[Initng-svn] r2987 - in initng: plugins/daemon plugins/ngc2 plugins/stcmd src

svn at initng.thinktux.net svn at initng.thinktux.net
Mon Feb 13 17:39:07 CET 2006


Author: jimmy
Date: Mon Feb 13 17:39:06 2006
New Revision: 2987

Modified:
   initng/plugins/daemon/initng_daemon.c
   initng/plugins/ngc2/initng_ngc2.c
   initng/plugins/stcmd/print_service.c
   initng/src/initng_handler.c
   initng/src/initng_service_data_types.h
   initng/src/initng_static_process_types.c
Log:
Some more work, mutch more to do.


Modified: initng/plugins/daemon/initng_daemon.c
==============================================================================
--- initng/plugins/daemon/initng_daemon.c	(original)
+++ initng/plugins/daemon/initng_daemon.c	Mon Feb 13 17:39:06 2006
@@ -84,6 +84,15 @@
  */
 #define RESPAWN_SLEEP 1
 
+/*
+ * Seconds a process have to exit after kill signal sent, before term is sent.
+ */
+#define DEFAULT_KILL_TIMEOUT 6
+
+/*
+ * Seconds a process have to exit after term signal sent.
+ */
+#define DEFAULT_TERM_TIMEOUT 2
 
 /*
  * ############################################################################
@@ -120,7 +129,8 @@
 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);
+static void handle_DAEMON_KILL(active_db_h * daemon);
+static void handle_DAEMON_TERM(active_db_h * daemon);
 
 /*
  * ############################################################################
@@ -206,8 +216,7 @@
 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                           #
@@ -254,7 +263,8 @@
 /*
  * 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 };
+a_state_h DAEMON_KILL = { "DAEMON_KILL", IS_STOPPING, &handle_DAEMON_KILL };
+a_state_h DAEMON_TERM = { "DAEMON_TERM", IS_STOPPING, &handle_DAEMON_TERM };
 
 /*
  * This marks the daemons, as DOWN.
@@ -296,6 +306,7 @@
 /* This are run, when initng wants to start a daemon */
 static int start_DAEMON(active_db_h * daemon_to_start)
 {
+    W_("Starting daemon %s.\n", daemon_to_start->name);
     /* mark it WAITING_FOR_START_DEP and wait */
     if (!initng_common_mark_service(daemon_to_start, &DAEMON_START_MARKED))
     {
@@ -359,7 +370,8 @@
     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_KILL);
+    initng_active_state_add(&DAEMON_TERM);
     initng_active_state_add(&DAEMON_STOPPED);
     initng_active_state_add(&DAEMON_LAUNCH);
     initng_active_state_add(&DAEMON_WAIT_FOR_PID_FILE);
@@ -387,7 +399,8 @@
     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_KILL);
+    initng_active_state_del(&DAEMON_TERM);
     initng_active_state_del(&DAEMON_STOPPED);
     initng_active_state_del(&DAEMON_LAUNCH);
     initng_active_state_del(&DAEMON_WAIT_FOR_PID_FILE);
@@ -585,7 +598,7 @@
 static void handle_DAEMON_STOP_DEPS_MET(active_db_h * service)
 {
     process_h *process = NULL;
-    int timeout = SECONDS_BEFORE_KILL;
+    int timeout = DEFAULT_KILL_TIMEOUT;
 
     /* get the KILL_TIMEOUT */
     if (initng_active_db_is(&KILL_TIMEOUT, service))
@@ -615,9 +628,6 @@
         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))
@@ -632,13 +642,23 @@
              * we do it ourself.
              */
 	    if(timeout == 0)
+	    {
         	kill_daemon(service, SIGTERM);
+	    	if(!initng_common_mark_service(service, &DAEMON_TERM))
+		    return;
+	    }
 	    else
+	    {
         	kill_daemon(service, SIGKILL);
-		
+	    	if(!initng_common_mark_service(service, &DAEMON_KILL))
+		    return;
+	    }	
             break;
 	}
         default:
+	/* Set its state to GOING_KILLED, to mark that we put some effort on killing it. */
+	    if(!initng_common_mark_service(service, &DAEMON_KILL))
+		return;
             break;
     }
 
@@ -755,15 +775,38 @@
 }
 
 
-static void handle_DAEMON_GOING_KILLED(active_db_h * daemon)
+static void handle_DAEMON_KILL(active_db_h * daemon)
 {
+    time_t n = time(0);
 
-    int timeout = initng_active_db_is(&KILL_TIMEOUT, daemon);
-    
-    
+    if(n-daemon->time_current_state.tv_sec>DEFAULT_KILL_TIMEOUT)
+    {
+	F_("Service %s DEFAULT_KILL_TIMEOUT reached!\n");
+	return;
+    }
+
+    /* else */
     
-    initng_global_set_sleep(timeout + 1);
+    initng_global_set_sleep(n-daemon->time_current_state.tv_sec);
+
+/* Here is when timeout of kill checked */
 
+}
+
+
+static void handle_DAEMON_TERM(active_db_h * daemon)
+{
+    time_t n = time(0);
+
+    if(n-daemon->time_current_state.tv_sec>DEFAULT_TERM_TIMEOUT)
+    {
+	F_("Service %s DEFAULT_KILL_TIMEOUT reached!\n");
+	return;
+    }
+
+    initng_global_set_sleep(n-daemon->time_current_state.tv_sec);
+
+/* Here is timeout of term checked */
 
 }
 
@@ -806,12 +849,6 @@
     if (check_for_pidfile(daemon))
 	return;
     
-    /* All other states here can only be DAMEON_RUNNING becouse DAEMON_LAUNCH is stuck in chec_for_pidfile */
-    if (daemon->current_state != &DAEMON_RUNNING)
-    {
-	F_("This is strange, an daemon exited, and is not in state DAEMON_LAUNCH or DAEMON_RUNNING, check this out.\n");
-    }
-    
     /* This service are gonna respawn, no need to set it stopped */
     if(check_respawn(daemon))
     {
@@ -1185,6 +1222,10 @@
     time_t last = 0;
 
     assert(service);
+    
+    /* Check so service status is DAEMON_RUNNING, or it wont have stopped by it self */
+    if(!IS_MARK(service, &DAEMON_RUNNING))
+	return(FALSE);
 
     /* check if the service have respawn enabled */
     if (!initng_active_db_is(&RESPAWN, service))

Modified: initng/plugins/ngc2/initng_ngc2.c
==============================================================================
--- initng/plugins/ngc2/initng_ngc2.c	(original)
+++ initng/plugins/ngc2/initng_ngc2.c	Mon Feb 13 17:39:06 2006
@@ -712,13 +712,21 @@
         strncpy(row.n, serv->name, 100);
         if (IS_UP(serv))
         {
+	    /* set status == ALREDY_RUNNING */
             strcpy(row.s, "ALREADY_RUNNING");
         }
         else
         {
+	    /* Try start this service */
+	    initng_handler_start_service(serv);
+	    /* set current status instead */
             strncpy(row.s, serv->current_state->state_name, 100);
         }
+	
+	/* the routh state */
         row.i = serv->current_state->is;
+	
+	/* Send */
         if (fwrite(&row, sizeof(active_row), 1, fd) != 1)
             F_("failed to send all data\n");
         return;

Modified: initng/plugins/stcmd/print_service.c
==============================================================================
--- initng/plugins/stcmd/print_service.c	(original)
+++ initng/plugins/stcmd/print_service.c	Mon Feb 13 17:39:06 2006
@@ -138,7 +138,7 @@
             case ALIAS:
                 fprintf(fd, " @@ ALIAS %s\n", tmp->type->opt_name);
                 continue;
-            case U_D_T:
+            default:
                 continue;
         }
     }

Modified: initng/src/initng_handler.c
==============================================================================
--- initng/src/initng_handler.c	(original)
+++ initng/src/initng_handler.c	Mon Feb 13 17:39:06 2006
@@ -49,7 +49,6 @@
 #include "initng_static_data_id.h"
 #include "initng_static_states.h"
 
-
 /*
  * This function is run from main when g.interrupt is set.
  * Will do special actions, for some status mode.

Modified: initng/src/initng_service_data_types.h
==============================================================================
--- initng/src/initng_service_data_types.h	(original)
+++ initng/src/initng_service_data_types.h	Mon Feb 13 17:39:06 2006
@@ -33,10 +33,12 @@
     SET = 3,
     INT = 6,
     ALIAS = 7,
+    TIME_T = 8,
     VARIABLE_STRING = 51,
     VARIABLE_STRINGS = 52,
     VARIABLE_SET = 53,
-    VARIABLE_INT = 56
+    VARIABLE_INT = 56,
+    VARIABLE_TIME_T = 58,
 } e_dt;
 
 typedef struct ss_entry s_entry;

Modified: initng/src/initng_static_process_types.c
==============================================================================
--- initng/src/initng_static_process_types.c	(original)
+++ initng/src/initng_static_process_types.c	Mon Feb 13 17:39:06 2006
@@ -43,6 +43,4 @@
 
 void initng_static_process_types_add_default(void)
 {
-/*    initng_process_db_ptype_add(&T_DAEMON);
-    initng_process_db_ptype_add(&T_KILL);*/
 }


More information about the Initng-svn mailing list