start/stop/restart all in swat

Roylance, Stephen D. SROYLANCE at PARTNERS.ORG
Tue Apr 22 19:06:32 GMT 2003


I've spent a lot of time starting and stopping all the samba services through
swat today, so I did this:
*** statuspage.c.orig	Tue Apr 22 13:17:37 2003
--- statuspage.c	Tue Apr 22 13:54:23 2003
***************
*** 220,264 ****
  	int autorefresh=0;
  	int refresh_interval=30;
  	TDB_CONTEXT *tdb;
  
  	smbd_pid = pidfile_pid("smbd");
  
! 	if (cgi_variable("smbd_restart")) {
  		stop_smbd();
  		start_smbd();
  	}
  
! 	if (cgi_variable("smbd_start")) {
  		start_smbd();
  	}
  
! 	if (cgi_variable("smbd_stop")) {
  		stop_smbd();
  	}
  
! 	if (cgi_variable("nmbd_restart")) {
  		stop_nmbd();
  		start_nmbd();
  	}
! 	if (cgi_variable("nmbd_start")) {
  		start_nmbd();
  	}
  
! 	if (cgi_variable("nmbd_stop")) {
  		stop_nmbd();
  	}
  
  #ifdef WITH_WINBIND
! 	if (cgi_variable("winbindd_restart")) {
  		stop_winbindd();
  		start_winbindd();
  	}
  
! 	if (cgi_variable("winbindd_start")) {
  		start_winbindd();
  	}
  
! 	if (cgi_variable("winbindd_stop")) {
  		stop_winbindd();
  	}
  #endif
--- 220,265 ----
  	int autorefresh=0;
  	int refresh_interval=30;
  	TDB_CONTEXT *tdb;
+ 	int nr_running=0;
  
  	smbd_pid = pidfile_pid("smbd");
  
! 	if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
  		stop_smbd();
  		start_smbd();
  	}
  
! 	if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
  		start_smbd();
  	}
  
! 	if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
  		stop_smbd();
  	}
  
! 	if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
  		stop_nmbd();
  		start_nmbd();
  	}
! 	if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
  		start_nmbd();
  	}
  
! 	if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
  		stop_nmbd();
  	}
  
  #ifdef WITH_WINBIND
! 	if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
  		stop_winbindd();
  		start_winbindd();
  	}
  
! 	if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
  		start_winbindd();
  	}
  
! 	if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
  		stop_winbindd();
  	}
  #endif
***************
*** 314,319 ****
--- 315,321 ----
  	d_printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"),
smbd_running()?_("running"):_("not running"));
  	if (geteuid() == 0) {
  	    if (smbd_running()) {
+ 		nr_running++;
  		d_printf("<td><input type=submit name=\"smbd_stop\"
value=\"%s\"></td>\n", _("Stop smbd"));
  	    } else {
  		d_printf("<td><input type=submit name=\"smbd_start\"
value=\"%s\"></td>\n", _("Start smbd"));
***************
*** 326,336 ****
--- 328,352 ----
  	d_printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"),
nmbd_running()?_("running"):_("not running"));
  	if (geteuid() == 0) {
  	    if (nmbd_running()) {
+ 		nr_running++;
  		d_printf("<td><input type=submit name=\"nmbd_stop\"
value=\"%s\"></td>\n", _("Stop nmbd"));
  	    } else {
  		d_printf("<td><input type=submit name=\"nmbd_start\"
value=\"%s\"></td>\n", _("Start nmbd"));
  	    }
  	    d_printf("<td><input type=submit name=\"nmbd_restart\"
value=\"%s\"></td>\n", _("Restart nmbd"));
+ #ifndef WITH_WINBIND
+ 	    if (nr_running == 2) {
+ 	        /* stop, restart all */
+ 		d_printf("</tr><tr><td></td><td></td>\n");
+ 		d_printf("<td><input type=submit name=\"all_stop\"
value=\"%s\"></td>\n", _("Stop All"));
+ 		d_printf("<td><input type=submit name=\"all_restart\"
value=\"%s\"></td>\n", _("Restart All"));
+ 	    }
+ 	    else if (nr_running == 0) {
+ 	    	/* start all */
+ 		d_printf("</tr><tr><td></td><td></td>\n");
+ 		d_printf("<td><input type=submit name=\"all_start\"
value=\"%s\"></td>\n", _("Start All"));
+ 	    }    
+ #endif	    
  	}
  	d_printf("</tr>\n");
  
***************
*** 339,349 ****
--- 355,378 ----
  	d_printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"),
winbindd_running()?_("running"):_("not running"));
  	if (geteuid() == 0) {
  	    if (winbindd_running()) {
+ 		nr_running++;
  		d_printf("<td><input type=submit name=\"winbindd_stop\"
value=\"%s\"></td>\n", _("Stop winbindd"));
  	    } else {
  		d_printf("<td><input type=submit name=\"winbindd_start\"
value=\"%s\"></td>\n", _("Start winbindd"));
  	    }
  	    d_printf("<td><input type=submit name=\"winbindd_restart\"
value=\"%s\"></td>\n", _("Restart winbindd"));
+ 	    if (nr_running == 3) {
+ 	        /* stop, restart all */
+ 		d_printf("</tr><tr><td></td><td></td>\n");
+ 		d_printf("<td><input type=submit name=\"all_stop\"
value=\"%s\"></td>\n", _("Stop All"));
+ 		d_printf("<td><input type=submit name=\"all_restart\"
value=\"%s\"></td>\n", _("Restart All"));
+ 	    }
+ 	    else if (nr_running == 0) {
+ 	    	/* start all */
+ 		d_printf("</tr><tr><td></td><td></td>\n");
+ 		d_printf("<td><input type=submit name=\"all_start\"
value=\"%s\"></td>\n", _("Start All"));
+ 	    }
+ 		
  	}
  	d_printf("</tr>\n");
  #endif

This makes a'stop all' and 'restart all'  button to the status page if all the
services are running, and a 'start all' if none are running.  I don't know if
the start stop order is optimum, but it could be re-arranged.

-Steve


More information about the samba-technical mailing list