[Initng-svn] r3987 - in initng/trunk/plugins: service

svn at initng.thinktux.net svn at initng.thinktux.net
Tue May 2 01:35:34 CEST 2006


Author: jimmy
Date: Tue May  2 01:35:33 2006
New Revision: 3987

Modified:
   initng/trunk/plugins/service/initng_service.c
   initng/trunk/plugins/stcmd/initng_stcmd.c

Log:
Add a new command, to manually launch some execs put in i-files.
For example how this may be used:

ngc --run daemon/apache:reload
ngc --run daemon/samba:cleanup

Only .i file change you need is to add another exec or script like
exec reload = /sbin/apache reload;



Modified: initng/trunk/plugins/service/initng_service.c
==============================================================================
--- initng/trunk/plugins/service/initng_service.c	(original)
+++ initng/trunk/plugins/service/initng_service.c	Tue May  2 01:35:33 2006
@@ -651,7 +651,7 @@
 	 */
 	if (!IS_MARK(service, &SERVICE_START_RUN))
 	{
-		F_("Start exited!, and service is not marked starting!\n");
+		F_("Start exited!, and service is not marked starting!\nWas this one launched manually by ngc --run ??");
 		return;
 	}
 

Modified: initng/trunk/plugins/stcmd/initng_stcmd.c
==============================================================================
--- initng/trunk/plugins/stcmd/initng_stcmd.c	(original)
+++ initng/trunk/plugins/stcmd/initng_stcmd.c	Tue May  2 01:35:33 2006
@@ -50,6 +50,7 @@
 #include <initng_static_states.h>
 #include <initng_depend.h>
 #include <initng_main.h>
+#include <initng_execute.h>
 
 static int cmd_get_pid_of(char *arg);
 static int cmd_start_on_new(char *arg);
@@ -70,6 +71,7 @@
 static char *cmd_get_depends_off(char *arg);
 static char *cmd_get_depends_off_deep(char *arg);
 static int cmd_new_init(char *arg);
+static int cmd_run(char *arg);
 
 s_command GET_PID_OF = { 'g', "get_pid_of", INT_COMMAND, ADVANCHED_COMMAND, REQUIRES_OPT,
 	{(void *) &cmd_get_pid_of}, "Get pid of service"
@@ -168,6 +170,11 @@
 	"Stops all services, and when its done, launching a new init."
 };
 
+s_command RUN = { 'U', "run", TRUE_OR_FALSE_COMMAND, ADVANCHED_COMMAND, REQUIRES_OPT,
+	{(void *) &cmd_run },
+	"Simply run an exec with specified name, example ngc --run service/test:start"
+};
+
 static int cmd_get_pid_of(char *arg)
 {
 	active_db_h *apt = NULL;
@@ -543,6 +550,62 @@
 }
 
 
+static int cmd_run(char *arg)
+{
+	char * runtype = NULL;
+	char * serv_name = NULL;
+	active_db_h * service = NULL;
+	ptype_h * ptype = NULL;
+	
+	/* search for a ':' char in arg */
+	runtype = strchr(arg, ':');
+	if(!runtype || runtype[0] != ':')
+	{
+		W_("Bad format: --run \"%s\"\n");
+		return(FALSE);
+	}
+	
+	/* if serv name is less then 2 chars */
+	if(runtype - arg - 1 < 2)
+	{
+		W_("Bad format: --run \"%s\"\n");
+		return(FALSE);
+	}
+
+	/* skip the ':' char */
+	runtype++;
+	
+	/* copy serv_name so we can put a '\0' to mark end */
+	serv_name=i_strndup(arg, runtype-arg- 1);
+	
+		/* get the process type by name */
+		ptype = initng_process_db_ptype_find(runtype);
+		if(!ptype)
+		{
+			F_("Process type \"%s\" was not found in service \"%s\"\n", runtype, serv_name);
+			free(serv_name);
+			return(FALSE);
+		}
+		
+		service=initng_active_db_find_by_name(serv_name);
+		if(!service)
+		{
+			F_("Service \"%s\" was not found, trying to run.\n", serv_name);
+			free(serv_name);
+			return(FALSE);
+		}
+		
+		/* wont need it anymore */
+		free(serv_name);
+	
+		printf("Found service %s\n", service->name);
+		
+		if(initng_execute_launch(service, ptype)!=TRUE)
+			return(FALSE);
+	
+	/* return happily */
+	return(TRUE);
+}
 
 int module_init(int api_version)
 {
@@ -575,6 +638,7 @@
 	initng_command_register(&DEPENDS_OFF);
 	initng_command_register(&DEPENDS_OFF_DEEP);
 	initng_command_register(&NEW_INIT);
+	initng_command_register(&RUN);
 
 	D_("libstcmd.so.0.0 loaded!\n");
 	return (TRUE);
@@ -607,7 +671,7 @@
 	initng_command_unregister(&DEPENDS_OFF);
 	initng_command_unregister(&DEPENDS_OFF_DEEP);
 	initng_command_unregister(&NEW_INIT);
-
+	initng_command_unregister(&RUN);
 
 	D_("libstcmd.so.0.0 unloaded!\n");
 


More information about the Initng-svn mailing list