[Initng-svn] r2716 - initng/plugins/ngc2

svn at initng.thinktux.net svn at initng.thinktux.net
Wed Jan 4 17:46:50 CET 2006


Author: jimmy
Date: Wed Jan  4 17:46:49 2006
New Revision: 2716

Modified:
   initng/plugins/ngc2/initng_ngc2.c
   initng/plugins/ngc2/ngc2.c
Log:
Facelift for ngc2.c, (Hopefully replaced soon).
Will tell user if service is started aldredy now.


Modified: initng/plugins/ngc2/initng_ngc2.c
==============================================================================
--- initng/plugins/ngc2/initng_ngc2.c	(original)
+++ initng/plugins/ngc2/initng_ngc2.c	Wed Jan  4 17:46:49 2006
@@ -665,13 +665,30 @@
     /* argument required */
     if (!arg || strlen(arg) < 2)
     {
-        strcpy(row.n, "UNSET");
+        strcpy(row.n, "");
         strcpy(row.s, "NOT_FOUND");
         row.i = IS_FAILED;
         if (fwrite(&row, sizeof(active_row), 1, fd) != 1)
             F_("failed to send all data\n");
         return;
     }
+    
+    serv = initng_active_db_find_in_name(arg);
+    if(serv)
+    {
+	memcpy(&row.t, &serv->time_current_state, sizeof(struct timeval));
+	strncpy(row.n, serv->name, 100);
+	if(IS_UP(serv))
+	{
+	    strcpy(row.s, "ALREDY_RUNNING");
+	} else {
+    	    strncpy(row.s, serv->current_state->state_name, 100);
+	}
+	row.i = serv->current_state->is;
+        if (fwrite(&row, sizeof(active_row), 1, fd) != 1)
+            F_("failed to send all data\n");
+	return;
+    }
 
     serv = initng_handler_start_new_service_named(arg);
     if (!serv)

Modified: initng/plugins/ngc2/ngc2.c
==============================================================================
--- initng/plugins/ngc2/ngc2.c	(original)
+++ initng/plugins/ngc2/ngc2.c	Wed Jan  4 17:46:49 2006
@@ -58,6 +58,9 @@
 
 #define print_out(...); { if(quiet==FALSE) printf(__VA_ARGS__ ); }
 
+#define TMP_QUIET if(quiet==FALSE) quiet=3;
+#define TMP_UNQUIET if(quiet==3) quiet=FALSE;
+
 /* Global comunication socket */
 static int sock = -1;
 
@@ -345,11 +348,22 @@
     }
     close_socket();
 
-    if (row.i == IS_UP || row.i == IS_WAITING)
+    if (row.i == IS_UP)
     {
-        print_out("\tService %s started sucessfully! (%s)\n", row.n, row.s);
+	if(strcmp(row.s, "ALREDY_RUNNING")==0)
+	{
+	    print_out("\tService %s alredy running!\n", row.n);        
+	} else {
+	    print_out("\tService %s started sucessfully! (%s)\n", row.n, row.s);
+	}
         return (TRUE);
     }
+    
+    if (row.i == IS_WAITING)
+    {
+	print_out("\tService %s is starting! (%s)\n", row.n, row.s);
+	return (TRUE);
+    }
 
     if (counter == 10)
     {
@@ -362,20 +376,34 @@
         try_count++;
         print_out("\n\n");
         print_out("Warning, service %s is in status: \"%s\"\n\n", row.n, row.s);
-        print_out
-            ("I will now try to reset the service, wait 1 second, and restart %s.\n",
-             row.n);
-
-        /* zap the service */
-        if (!send_and_handle('z', NULL, row.n))
-            return (FALSE);
-
-        sleep(1);
-        print_out("\n\nTrying to start %s again ...\n\n", row.n);
-
-        /* try start again */
-        if (send_and_handle('u', NULL, row.n))
-            return (TRUE);
+	
+	if(strcmp(row.s, "NOT_FOUND")==0)
+	{
+	    print_out("This meens that the service cound not start,\n");
+	    print_out("Please check initng console, syslogs or ngc -L\n");
+	    print_out("For more info.\n");
+	    
+	    return(FALSE);    
+	}
+	
+	/* If found but failed */
+    	    print_out("Service %s was failed, but found.\n", row.n);
+	    print_out("Will not make an attempt to reset service state and try again\n");
+	
+	    TMP_QUIET; /* dont print zap result */
+    	    /* zap the service */
+    	    if (!send_and_handle('z', NULL, row.n))
+        	return (FALSE);
+
+	    TMP_UNQUIET;
+	    
+	    
+    	    sleep(1);
+    	    print_out("\n\nTrying to start %s again ...\n\n", row.n);
+
+    	    /* try start again */
+    	    if (send_and_handle('u', NULL, row.n))
+        	return (TRUE);
     }
 
     print_out("\tFailed to start service, %s (%s)\n", row.n, row.s);
@@ -463,9 +491,13 @@
              row.n);
         sleep(1);
 
+	TMP_QUIET; /* Dont show anymore atempts */
+	
         /* zap the service */
         if (!send_and_handle('z', NULL, row.n))
             return (FALSE);
+	    
+	TMP_UNQUIET;
 
         print_out
             ("Done, WARNING, clearing service meens that its removed from initng,\n");
@@ -477,7 +509,7 @@
     /* Down is to */
     if (row.i == IS_DOWN)
     {
-        print_out("\tService stopped sucessfully!\n");
+        print_out("\tNo service %s exists anymore!\n", row.n);
         return (TRUE);
     }
 


More information about the Initng-svn mailing list