[Initng-svn] r3014 - in initng: plugins/service src
svn at initng.thinktux.net
svn at initng.thinktux.net
Fri Feb 17 12:14:36 CET 2006
Author: jimmy
Date: Fri Feb 17 12:14:35 2006
New Revision: 3014
Modified:
initng/plugins/service/initng_service.c
initng/src/initng.h
initng/src/initng_active_db.c
initng/src/initng_active_db.h
initng/src/initng_static_data_id.c
initng/src/initng_static_data_id.h
initng/src/main.c
Log:
Now initng removes down services default after 60 seconds of downtime to save memory.
also started work on START_TIMEOUT and STOP_TIMEOUT in initng_service.c
Modified: initng/plugins/service/initng_service.c
==============================================================================
--- initng/plugins/service/initng_service.c (original)
+++ initng/plugins/service/initng_service.c Fri Feb 17 12:14:35 2006
@@ -59,6 +59,8 @@
static void handle_SERVICE_WAITING_FOR_STOP_DEP(active_db_h * service);
static void handle_SERVICE_START_DEPS_MET(active_db_h * service);
static void handle_SERVICE_STOP_DEPS_MET(active_db_h * service);
+static void handle_SERVICE_START_RUN(active_db_h * service);
+static void handle_SERVICE_STOP_RUN(active_db_h * service);
/*
* ############################################################################
@@ -86,6 +88,17 @@
ptype_h T_START = { "start", &handle_killed_start };
ptype_h T_STOP = { "stop", &handle_killed_stop };
+/*
+ * ############################################################################
+ * # SERVICE VARIABLES #
+ * ############################################################################
+ */
+
+#define DEFAULT_START_TIMEOUT 240
+#define DEFAULT_STOP_TIMEOUT 60
+s_entry START_TIMEOUT = { "start_timeout", INT, &TYPE_SERVICE, "Let the start process run maximum this time." };
+s_entry STOP_TIMEOUT = { "start_timeout", INT, &TYPE_SERVICE, "Let the start process run maximum this time." };
+
/*
* ############################################################################
@@ -138,12 +151,12 @@
/*
* This is the state, when the Start code is actually running.
*/
-a_state_h SERVICE_START_RUN = { "SERVICE_START_RUN", IS_STARTING, NULL };
+a_state_h SERVICE_START_RUN = { "SERVICE_START_RUN", IS_STARTING, &handle_SERVICE_START_RUN };
/*
* This is the state, when the Stop code is actually running.
*/
-a_state_h SERVICE_STOP_RUN = { "SERVICE_STOP_RUN", IS_STOPPING, NULL };
+a_state_h SERVICE_STOP_RUN = { "SERVICE_STOP_RUN", IS_STOPPING, &handle_SERVICE_STOP_RUN };
/*
* Generally FAILING states, if something goes wrong, some of these are set.
@@ -235,6 +248,8 @@
initng_active_state_add(&SERVICE_FAIL_STARTING);
initng_active_state_add(&SERVICE_FAIL_STOPPING);
+ initng_service_data_types_add(&START_TIMEOUT);
+ initng_service_data_types_add(&STOP_TIMEOUT);
return (TRUE);
}
@@ -264,6 +279,9 @@
initng_active_state_del(&SERVICE_FAIL_STARTING);
initng_active_state_del(&SERVICE_FAIL_STOPPING);
+ initng_service_data_types_del(&START_TIMEOUT);
+ initng_service_data_types_del(&STOP_TIMEOUT);
+
}
/*
@@ -339,6 +357,16 @@
initng_common_mark_service(service, &SERVICE_FAIL_STARTING);
return;
default:
+ if (initng_active_db_is(&START_TIMEOUT, service))
+ {
+ initng_global_set_sleep(initng_active_db_get_int
+ (&START_TIMEOUT, service) + 1);
+ }
+ else
+ {
+ /* This will make sure all handlers a run in x seconds from now */
+ initng_global_set_sleep(DEFAULT_START_TIMEOUT + 1);
+ }
return;
}
@@ -347,8 +375,9 @@
static void handle_SERVICE_STOP_DEPS_MET(active_db_h * service)
{
/* mark this service as STOPPING */
- initng_common_mark_service(service, &SERVICE_STOP_RUN);
-
+ if(!initng_common_mark_service(service, &SERVICE_STOP_RUN))
+ return;
+
/* launch stop service */
switch (initng_execute_launch(service, &T_STOP))
{
@@ -370,65 +399,76 @@
}
else
{
+
/* This will make sure all handlers a run in x seconds from now */
- initng_global_set_sleep(SECONDS_BEFORE_KILL + 1);
+ initng_global_set_sleep(DEFAULT_STOP_TIMEOUT + 1);
}
return;
}
}
-
-
-
-#ifdef THIS_IS_DISABLED
-static void handle_STOPPED(active_db_h * service_stopped)
+/*
+ * This handler will execute on START_TIMEOUT.
+ * This will stop that start process if its taking to long.
+ */
+static void handle_SERVICE_START_RUN(active_db_h * service)
{
- active_db_h *current, *safe = NULL;
-
- /*
- * Make sure there is no services that needs this
- * that still think its running.
- */
- while_active_db_safe(current, safe)
- {
- /* no idea to stop myself */
- if (current == service_stopped)
- continue;
+ int elap;
+ int timeout;
+
+ /* get the timeout */
+ timeout = initng_active_db_get_int(&START_TIMEOUT, service);
+
+ /* if not set, use the default one */
+ if(!timeout)
+ timeout = DEFAULT_START_TIMEOUT;
- /* DON'T stop runlevels OR virtuals */
- if (current->type == &TYPE_VIRTUAL)
- continue;
+ /* calculate the elapsed time */
+ elap = g.now.tv_sec - service->time_current_state.tv_sec;
- /* check that current needs service_stopped */
- if (initng_depend(current, service_stopped) == FALSE)
- continue;
+ /* if the time elaped is bigger then the timeout */
+ if(elap >= timeout)
+ {
+ W_("Timeout ( %i Seconds ) for start process, service %s.\n", timeout, service->name);
+ return;
+ }
+
+ /* set the alarm again */
+ initng_global_set_sleep(timeout - elap + 1);
+}
- /* don't stop a stopped service */
- if (IS_DOWN(current))
- continue;
+/*
+ * This handler will execute on STOP_TIMEOUT.
+ * This will stop that stop process if its taking to long.
+ */
+static void handle_SERVICE_STOP_RUN(active_db_h * service)
+{
+ int elap;
+ int timeout;
+
+ /* get the timeout */
+ timeout = initng_active_db_get_int(&STOP_TIMEOUT, service);
+
+ /* if not set, use the default timeout */
+ if(!timeout)
+ timeout = DEFAULT_STOP_TIMEOUT;
- /* if stop this */
- D_("%s have to stop %s.\n", service_stopped->name, current->name);
- initng_handler_stop_service(current);
- }
+ /* calculate the elapsed time */
+ elap = g.now.tv_sec - service->time_current_state.tv_sec;
- /* check if this service is restarting */
- if (initng_active_db_is(&RESTARTING, service_stopped))
+ /* if the time elaped is bigger then the timeout */
+ if(elap >= timeout)
{
- initng_active_db_remove(&RESTARTING, service_stopped);
- initng_handler_start_service(service_stopped);
- D_("Service is restarting now!\n");
- return;
+ W_("Timeout ( %i Seconds ) for stop process, service %s.\n", timeout, service->name);
+ return;
}
-
- /* free service, and forget */
- initng_active_db_del(service_stopped);
- initng_active_db_free(service_stopped);
- D_("Service removed.\n");
+ /* set the alarm again */
+ initng_global_set_sleep(timeout - elap + 1);
}
-#endif
+
+
/*
Modified: initng/src/initng.h
==============================================================================
--- initng/src/initng.h (original)
+++ initng/src/initng.h Fri Feb 17 12:14:35 2006
@@ -53,14 +53,17 @@
#define MAX_VERBOSES 50
#define MAX_BLACKLIST 20
-/* after term is sent, wait these seconds before killing */
-#define SECONDS_BEFORE_KILL 2
-
/* makes all services sleep this many microseconds before launching,
* this will get initng time to register service */
#define ALL_USLEEP 1000
/*
+ * Clean delay, wait this no of seconds after a service is down, before removing
+ * the trace of it in memory.
+ */
+#define CLEAN_DELAY 60
+
+/*
* Temporary printf-replacement macros until a real logging system can be added.
*/
Modified: initng/src/initng_active_db.c
==============================================================================
--- initng/src/initng_active_db.c (original)
+++ initng/src/initng_active_db.c Fri Feb 17 12:14:35 2006
@@ -636,3 +636,27 @@
(type, from_active->from_service));
return (0);
}
+
+/*
+ * Walk the active db, searching for services that are down, and been so for a minute.
+ * It will remove this entry to save memory.
+ * CLEAN_DELAY are defined in initng.h
+ */
+void initng_active_db_clean_down(void)
+{
+ active_db_h *current = NULL;
+ active_db_h *safe = NULL;
+
+ while_active_db_safe(current,safe)
+ {
+ assert(current->name);
+ assert(current->current_state);
+
+ /* count stopped services */
+ if (!IS_DOWN(current))
+ continue;
+
+ if(g.now.tv_sec > current->time_current_state.tv_sec + CLEAN_DELAY)
+ initng_active_db_free(current);
+ }
+}
Modified: initng/src/initng_active_db.h
==============================================================================
--- initng/src/initng_active_db.h (original)
+++ initng/src/initng_active_db.h Fri Feb 17 12:14:35 2006
@@ -128,6 +128,7 @@
/* count the total number of this type */
int initng_active_db_count_type(s_entry * type, active_db_h * from_active);
+void initng_active_db_clean_down(void);
#define initng_active_db_set_string(type, act, string) d_set_string(type, &act->data.list, string)
#define initng_active_db_set_another_string(type, act, string) d_set_another_string(type, &act->data.list, string)
Modified: initng/src/initng_static_data_id.c
==============================================================================
--- initng/src/initng_static_data_id.c (original)
+++ initng/src/initng_static_data_id.c Fri Feb 17 12:14:35 2006
@@ -44,9 +44,6 @@
s_entry UP_ON_FAILURE = { "up_on_failure", SET, NULL,
"Mark this service as up, even if it fails to start."
};
-s_entry STOP_TIMEOUT = { "stop_timeout", INT, NULL,
- "Wait this seconds, before hard-terminate a stopping daemon."
-};
/*
* add some default options, that is needed by core, and should
@@ -63,5 +60,4 @@
initng_service_data_types_add(&RESTARTING);
- initng_service_data_types_add(&STOP_TIMEOUT);
}
Modified: initng/src/initng_static_data_id.h
==============================================================================
--- initng/src/initng_static_data_id.h (original)
+++ initng/src/initng_static_data_id.h Fri Feb 17 12:14:35 2006
@@ -30,7 +30,6 @@
extern s_entry ENV;
extern s_entry RESTARTING;
extern s_entry UP_ON_FAILURE;
-extern s_entry STOP_TIMEOUT;
void initng_static_data_id_add_defaults(void);
Modified: initng/src/main.c
==============================================================================
--- initng/src/main.c (original)
+++ initng/src/main.c Fri Feb 17 12:14:35 2006
@@ -582,6 +582,11 @@
continue;
}
+ /*
+ * Run this to clean the active_db out from down services.
+ */
+ initng_active_db_clean_down();
+
/* if interrupt is set, don't waits CPU on a poll */
if (g.interrupt == TRUE)
continue;
More information about the Initng-svn
mailing list