mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 06:25:19 +00:00
Add the script hook support to the libvirt daemon
It supports 3 kind of probing times, at daemon startup, when the daemon reloads its drivers on SIGHUP and when the daemon exits * daemon/libvirtd.c: daemon hooks for startup, reload and exit
This commit is contained in:
parent
2b4e353168
commit
53456e62ed
@ -62,6 +62,7 @@
|
|||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
#include "hooks.h"
|
||||||
#ifdef HAVE_AVAHI
|
#ifdef HAVE_AVAHI
|
||||||
# include "mdns.h"
|
# include "mdns.h"
|
||||||
#endif
|
#endif
|
||||||
@ -199,6 +200,7 @@ enum {
|
|||||||
VIR_DAEMON_ERR_PRIVS,
|
VIR_DAEMON_ERR_PRIVS,
|
||||||
VIR_DAEMON_ERR_NETWORK,
|
VIR_DAEMON_ERR_NETWORK,
|
||||||
VIR_DAEMON_ERR_CONFIG,
|
VIR_DAEMON_ERR_CONFIG,
|
||||||
|
VIR_DAEMON_ERR_HOOKS,
|
||||||
|
|
||||||
VIR_DAEMON_ERR_LAST
|
VIR_DAEMON_ERR_LAST
|
||||||
};
|
};
|
||||||
@ -212,7 +214,8 @@ VIR_ENUM_IMPL(virDaemonErr, VIR_DAEMON_ERR_LAST,
|
|||||||
"Unable to setup signal handlers",
|
"Unable to setup signal handlers",
|
||||||
"Unable to drop privileges",
|
"Unable to drop privileges",
|
||||||
"Unable to initialize network sockets",
|
"Unable to initialize network sockets",
|
||||||
"Unable to load configuration file")
|
"Unable to load configuration file",
|
||||||
|
"Unable to look for hook scripts")
|
||||||
|
|
||||||
static void sig_handler(int sig, siginfo_t * siginfo,
|
static void sig_handler(int sig, siginfo_t * siginfo,
|
||||||
void* context ATTRIBUTE_UNUSED) {
|
void* context ATTRIBUTE_UNUSED) {
|
||||||
@ -378,8 +381,11 @@ qemudDispatchSignalEvent(int watch ATTRIBUTE_UNUSED,
|
|||||||
switch (siginfo.si_signo) {
|
switch (siginfo.si_signo) {
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
VIR_INFO0(_("Reloading configuration on SIGHUP"));
|
VIR_INFO0(_("Reloading configuration on SIGHUP"));
|
||||||
|
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-",
|
||||||
|
VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL);
|
||||||
if (virStateReload() < 0)
|
if (virStateReload() < 0)
|
||||||
VIR_WARN0(_("Error while reloading drivers"));
|
VIR_WARN0(_("Error while reloading drivers"));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
@ -3143,9 +3149,23 @@ int main(int argc, char **argv) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* setup the hooks if any */
|
||||||
|
if (virHookInitialize()) {
|
||||||
|
ret = VIR_DAEMON_ERR_HOOKS;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
/* Disable error func, now logging is setup */
|
/* Disable error func, now logging is setup */
|
||||||
virSetErrorFunc(NULL, virshErrorHandler);
|
virSetErrorFunc(NULL, virshErrorHandler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Call the daemon startup hook
|
||||||
|
* TODO: should we abort the daemon startup if the script returned
|
||||||
|
* an error ?
|
||||||
|
*/
|
||||||
|
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_START,
|
||||||
|
0, "start", NULL);
|
||||||
|
|
||||||
if (qemudNetworkInit(server) < 0) {
|
if (qemudNetworkInit(server) < 0) {
|
||||||
ret = VIR_DAEMON_ERR_NETWORK;
|
ret = VIR_DAEMON_ERR_NETWORK;
|
||||||
goto error;
|
goto error;
|
||||||
@ -3206,6 +3226,9 @@ shutdown:
|
|||||||
}
|
}
|
||||||
pthread_join(server->eventThread, NULL);
|
pthread_join(server->eventThread, NULL);
|
||||||
|
|
||||||
|
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_SHUTDOWN,
|
||||||
|
0, "shutdown", NULL);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (statuswrite != -1) {
|
if (statuswrite != -1) {
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user