Hi,

This patch fix system_service so it is more robust against bad service startup 
scripts.
I think that this fixes ticket #516 (not sure as this fix only correct start 
error message if daemon already running).

- 1st, it uses /sbin/service if possible so the script runs using a clean 
environment.
- 2nd, it if a service is started, it will restart it instead of trying to do a 
second start. This prevent bad startup scripts (systemimager-server-monitord 
for example) that are not LSB compliant and fails to start if service is 
already running. Restarting instead of doing nothing or trying a second start 
has also the advantage of starting the daemon even if there is a PID file and 
the daemon died unexpectedly.

SystemServicesDefs.pm.svn9147.patch (fix system_service() )
SystemServices.pm.svn9147.patch (adds STATUS definition and fix POSTGRESS 
definition (before I forget))


Before the patch, we had the following error when pressing "Monitor Cluster 
Deployment" setup if  systemimager-server-monitord was already running.

--> Executing: /etc/init.d/systemimager-server-monitord start
Starting SystemImager's installation monitoring: si_monitor... failed.
PID file /var/run/si_monitor.pid exists.  Must be already running.
ERROR: Impossible to execute /etc/init.d/systemimager-server-monitord start at 
/usr/bin/oscar_wizard line 984
ERROR: Impossible to start service monitord
 at /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/Tk.pm line 247

=> The monitor windows did not displays.

After the patch:
starting service systemimager-server-monitord... starting service 
systemimager-server-monitord... --> Executing: /sbin/service 
systemimager-server-monitord status
Status of SystemImager's installation monitoring: si_monitor... running.
=> return code: 0 --> Executing: /sbin/service systemimager-server-monitord 
restart
Stopping SystemImager's installation monitoring: si_monitor... stopped.
Starting SystemImager's installation monitoring: si_monitor... ok.
=> return code: 0 A thread exited while 2 threads were running.

=> The monitor windows did opens successfully.

Regards,

-- 
        Olivier LAHAYE
        CEA Saclay
        DRT-LIST-DETECS-SSTM
Index: SystemServices.pm
===================================================================
--- SystemServices.pm	(révision 9147)
+++ SystemServices.pm	(copie de travail)
@@ -139,31 +139,67 @@
     return 0;
 }
 
+################################################################################
+# is_system_service_running: tels if a service is running                      #
+#                                                                              #
+# input: service name                                                          #
+#        action                                                                #
+# output: 0 Success                                                            #
+#         non 0: Error                                                         #
+################################################################################
+
 sub system_service ($$) {
     my ($service, $action) = @_;
 
     # We get the daemon path
     my $path = OSCAR::OCA::OS_Settings::getitem ($service . "_daemon");
 
-    my $cmd = "$path ";
+    # /sbin/service is a RPM specific command, so we do not use it on Debian-like
+    # systems. It allows to start a service with a non polluted environment.
+    my $os = OSCAR::OCA::OS_Detect::open();
+    my $binary_format = $os->{'pkg'};
+    my $cmd;
+    if ($binary_format eq "rpm") { # RPM based distro
+        $cmd = File::Basename::basename ($path);
+        print ("starting service $cmd... ");
+        $cmd = "/sbin/service $cmd ";
+    } else { # Non RPM based distro.
+        my $cmd = "$path ";
+    }
+
     if ($action eq OSCAR::SystemServicesDefs::START()) {
-        $cmd .= "start";
+        if (system_service ($service, OSCAR::SystemServicesDefs::STATUS())) { # not running
+            $cmd .= "start";
+        } else { # already running, we restart to avoid errors (bad init stripts)
+            $cmd .= "restart"; # systemimager-server-monitord is not LSB.
+        }
     } elsif ($action eq OSCAR::SystemServicesDefs::STOP()) {
         $cmd .= "stop";
     } elsif ($action eq OSCAR::SystemServicesDefs::RESTART()) {
         $cmd .= "restart";
+    } elsif ($action eq OSCAR::SystemServicesDefs::STATUS()) {
+        $cmd .= "status";
     } else {
         carp "ERROR: Unknow system service action ($action)";
         return -1;
     }
-
     OSCAR::Logger::oscar_log_subsection "Executing: $cmd";
-    if (system ($cmd)) {
-        carp "ERROR: Impossible to execute $cmd";
-        return -1;
-    }
+#    if (system ($cmd)) {
+#        carp "ERROR: Impossible to execute $cmd";
+#        return -1;
+#    }
 
-    return 0;
+    # start returns 0 if start ok or already running
+    # stop returns 0 is deamon running and succesfully stopped (else error)
+    # retart: same as start
+    # status: 0 if running 3 or 1 if not.
+    # command not found: 127
+    # unknown service: 1
+
+    my $ret_code = system ($cmd);
+    print ("=> return code: $ret_code ");
+
+    return $ret_code;
 }
 
 # Give the list of system services OSCAR knows how to deal with.
Index: SystemServicesDefs.pm
===================================================================
--- SystemServicesDefs.pm	(révision 9147)
+++ SystemServicesDefs.pm	(copie de travail)
@@ -18,13 +18,14 @@
 use constant SSH            => 'ssh';
 use constant DHCP           => 'dhcp';
 use constant MYSQL          => 'mysql';
-use constant POSTGRESQL     => 'postgresql';
+use constant POSTGRESQL     => 'pgsql';
 use constant SI_MONITORD    => 'monitord';
 
 # List of actions related to system services
 use constant START      => 0;
 use constant STOP       => 1;
 use constant RESTART    => 2;
+use constant STATUS     => 3;
 
 # List of service status
 use constant STARTED    => 0;
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Oscar-devel mailing list
Oscar-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oscar-devel

Reply via email to