[Initng-svn] r2984 - initng/plugins/daemon
svn at initng.thinktux.net
svn at initng.thinktux.net
Fri Feb 10 17:40:07 CET 2006
Author: jimmy
Date: Fri Feb 10 17:40:06 2006
New Revision: 2984
Modified:
initng/plugins/daemon/initng_daemon.c
Log:
introduce KILL_TIMEOUT
Modified: initng/plugins/daemon/initng_daemon.c
==============================================================================
--- initng/plugins/daemon/initng_daemon.c (original)
+++ initng/plugins/daemon/initng_daemon.c Fri Feb 10 17:40:06 2006
@@ -91,7 +91,7 @@
* ############################################################################
*/
-static void kill_daemon(active_db_h * service);
+static void kill_daemon(active_db_h * service, int sig);
static void clear_pidfile(active_db_h * s);
static pid_t get_pidof(active_db_h * s);
static pid_t get_pidfile(active_db_h * s, int warn);
@@ -120,6 +120,7 @@
static void handle_DAEMON_STOP_DEPS_MET(active_db_h * daemon);
static void handle_DAEMON_WAIT_FOR_PID_FILE(active_db_h *daemon);
static void handle_DAEMON_WAIT_RESP_TOUT(active_db_h * service);
+static void handle_DAEMON_GOING_KILLED(active_db_h * daemon);
/*
* ############################################################################
@@ -186,7 +187,12 @@
"Wait this number of seconds before respawning."
};
-
+/*
+ * Kill timeout, when killing the daemon, wait this many seconds, before
+ * Sending the TERM signal, if this is 0, the TERM signal will be sent directly.
+ */
+s_entry KILL_TIMEOUT = { "kill_timeout", INT, &TYPE_DAEMON,
+ "Wait this many seconds before TERM daemon, after a KILL." };
/*
* Down here, internal variables, that we use, but cant be set in the .i file.
@@ -200,7 +206,8 @@
s_entry INTERNAL_PID_WARN_TIME = { NULL, INT, &TYPE_DAEMON, NULL, NULL };
/* Last time respawning, so it wont respawn to mutch */
s_entry INTERNAL_LAST_RESPAWN = { NULL, INT, &TYPE_DAEMON, NULL };
-
+/* Time when kill signal was sent */
+s_entry INTERNAL_KILL_SENT = { NULL, INT, &TYPE_DAEMON, NULL };
/*
* ############################################################################
* # DAEMON STATES STRUCTS #
@@ -245,6 +252,11 @@
a_state_h DAEMON_STOP_DEPS_MET = { "DAEMON_STOP_DEPS_MET", IS_STARTING, &handle_DAEMON_STOP_DEPS_MET };
/*
+ * This is the state on the daemon, when it are being killed.
+ */
+a_state_h DAEMON_GOING_KILLED = { "DAEMON_GOING_KILLED", IS_STOPPING, &handle_DAEMON_GOING_KILLED };
+
+/*
* This marks the daemons, as DOWN.
*/
a_state_h DAEMON_STOPPED = { "DAEMON_STOPPED", IS_DOWN, NULL };
@@ -333,6 +345,7 @@
initng_service_data_types_add(&PIDOF);
initng_service_data_types_add(&FORKS);
initng_service_data_types_add(&RESPAWN);
+ initng_service_data_types_add(&KILL_TIMEOUT);
initng_service_data_types_add(&INTERNAL_GOT_PID);
initng_service_data_types_add(&INTERNAL_PIDFILE_TIMEOUT);
initng_service_data_types_add(&INTERNAL_PID_WARN_TIME);
@@ -346,6 +359,7 @@
initng_active_state_add(&DAEMON_WAITING_FOR_STOP_DEP);
initng_active_state_add(&DAEMON_START_DEPS_MET);
initng_active_state_add(&DAEMON_STOP_DEPS_MET);
+ initng_active_state_add(&DAEMON_GOING_KILLED);
initng_active_state_add(&DAEMON_STOPPED);
initng_active_state_add(&DAEMON_LAUNCH);
initng_active_state_add(&DAEMON_WAIT_FOR_PID_FILE);
@@ -373,6 +387,7 @@
initng_active_state_del(&DAEMON_WAITING_FOR_STOP_DEP);
initng_active_state_del(&DAEMON_START_DEPS_MET);
initng_active_state_del(&DAEMON_STOP_DEPS_MET);
+ initng_active_state_del(&DAEMON_GOING_KILLED);
initng_active_state_del(&DAEMON_STOPPED);
initng_active_state_del(&DAEMON_LAUNCH);
initng_active_state_del(&DAEMON_WAIT_FOR_PID_FILE);
@@ -387,6 +402,7 @@
initng_service_data_types_del(&PIDOF);
initng_service_data_types_del(&FORKS);
initng_service_data_types_del(&RESPAWN);
+ initng_service_data_types_del(&KILL_TIMEOUT);
initng_service_data_types_del(&INTERNAL_GOT_PID);
initng_service_data_types_del(&INTERNAL_PIDFILE_TIMEOUT);
initng_service_data_types_del(&INTERNAL_PID_WARN_TIME);
@@ -568,58 +584,66 @@
static void handle_DAEMON_STOP_DEPS_MET(active_db_h * service)
{
- process_h *process, *safe = NULL;
+ process_h *process = NULL;
+ int timeout = SECONDS_BEFORE_KILL;
- /* mark this service as STOPPING */
- /*initng_common_mark_service(service, &DAEMON_);*/
+ /* get the KILL_TIMEOUT */
+ if (initng_active_db_is(&KILL_TIMEOUT, service))
+ {
+ timeout=initng_active_db_get_int(&KILL_TIMEOUT, service);
+ }
/* find the daemon, and check so it still exits */
- while_processes_safe(process, safe, service)
+ if(!(process=initng_process_db_get(&T_DAEMON, service)))
{
- if (process->pt != &T_DAEMON)
- continue;
-
- if (process->pid <= 0)
- {
- initng_common_mark_service(service, &DAEMON_STOPPED);
- return;
- }
+ F_("Could not find process to kill!\n");
+ return;
+ }
+
+ /* Check so process have a valid pid */
+ if (process->pid <= 0)
+ {
+ D_("Pid is unvalid, marked as DAEMON_STOPPED\n");
+ initng_common_mark_service(service, &DAEMON_STOPPED);
+ return;
+ }
- if (kill(process->pid, 0) && errno == ESRCH)
- {
- initng_common_mark_service(service, &DAEMON_STOPPED);
- return;
- }
+ if (kill(process->pid, 0) && errno == ESRCH)
+ {
+ D_("Dont exist a process with pid %i, mark as DAEMON_STOPPED\n", process->pid);
+ initng_common_mark_service(service, &DAEMON_STOPPED);
+ return;
}
+ /* Set its state to GOING_KILLED, to mark that we put some effort on killing it. */
+ if(!initng_common_mark_service(service, &DAEMON_GOING_KILLED))
+ return;
+
/* launch stop service */
switch (initng_execute_launch(service, &T_KILL))
{
case FAIL:
F_(" -- (%s): fail launch stop!\n", service->name);
- initng_common_mark_service(service, &FAIL_STOPPING);
+ initng_common_mark_service(service, &DAEMON_FAIL_STOPPING);
return;
case FALSE:
+ {
/* if there is no plugin that wanna kill this daemon,
* we do it ourself.
*/
- kill_daemon(service);
+ if(timeout == 0)
+ kill_daemon(service, SIGTERM);
+ else
+ kill_daemon(service, SIGKILL);
+
break;
+ }
default:
break;
}
-
- /* TODO, STOP_TIMEOUT should be KILL_TIMEOUT */
- if (initng_active_db_is(&STOP_TIMEOUT, service))
- {
- initng_global_set_sleep(initng_active_db_get_int
- (&STOP_TIMEOUT, service) + 1);
- }
- else
- {
- initng_global_set_sleep(SECONDS_BEFORE_KILL + 1);
- }
+ if(timeout)
+ initng_global_set_sleep(timeout + 1);
}
/*
@@ -731,6 +755,18 @@
}
+static void handle_DAEMON_GOING_KILLED(active_db_h * daemon)
+{
+
+ int timeout = initng_active_db_is(&KILL_TIMEOUT, daemon);
+
+
+
+ initng_global_set_sleep(timeout + 1);
+
+
+}
+
/*
* ############################################################################
* # KILL HANDLER FUNCTIONS #
@@ -815,33 +851,19 @@
*/
-static void kill_daemon(active_db_h * service)
+static void kill_daemon(active_db_h * service, int sig)
{
process_h *process = NULL;
assert(service);
- /* look for a T_DAEMON process */
- while_processes(process, service)
- {
- if (process->pt == &T_DAEMON)
- break;
- }
-
/* make sure we got a process */
- if (!process)
+ if (!(process=initng_process_db_get(&T_DAEMON, service)))
{
F_("Service doesn't have any processes, don't know how to kill then.\n");
return;
}
- /* check so we got a T_DAEMON */
- if (process->pt != &T_DAEMON)
- {
- F_("This daemon does not have a daemon_process!\n");
- return;
- }
-
/* check so that pid is good */
if (process->pid <= 0)
{
@@ -867,20 +889,8 @@
process->pid, service->name);
}
- /* Uhm, this doesn't work : kill(-service->start_process->pid, SIGTERM); */
- kill(process->pid, SIGTERM);
-
- if (initng_active_db_is(&STOP_TIMEOUT, service))
- {
- initng_global_set_sleep(initng_active_db_get_int
- (&STOP_TIMEOUT, service) + 1);
- D_("Clock is set, killed process %i (%s), have %i seconds to quit before SIGKILL\n", process->pid, service->name, initng_active_db_get_int(&STOP_TIMEOUT, service));
- }
- else
- {
- initng_global_set_sleep(SECONDS_BEFORE_KILL + 1);
- D_("Clock is set, killed process %i (%s), have %i seconds to quit before SIGKILL\n", process->pid, service->name, SECONDS_BEFORE_KILL);
- }
+ /* Uhm, this doesn't work : kill(-service->start_process->pid, SIGKILL); */
+ kill(process->pid, sig);
}
/*
More information about the Initng-svn
mailing list