startup scripts : assume initscripts is not installed, only use systemctl
authorparmentelat <thierry.parmentelat@inria.fr>
Fri, 7 Dec 2018 15:57:56 +0000 (16:57 +0100)
committerparmentelat <thierry.parmentelat@inria.fr>
Fri, 7 Dec 2018 15:57:56 +0000 (16:57 +0100)
plc.d/functions
plc.d/mail
plc.d/network
plc_config.py

index 58508a3..161da9e 100644 (file)
@@ -7,8 +7,22 @@
 
 export PATH=/sbin:/bin:/usr/bin:/usr/sbin
 
-# Source function library
-. /etc/init.d/functions
+# covering for former /etc/init.d/functions
+function success() {
+    echo success "$@"
+    true
+}
+
+function failure() {
+    echo failure "$@"
+    false
+}
+
+function action() {
+    local message="$1"; shift
+    echo $message
+    "$@"
+}
 
 # Total number of errors
 ERRORS=0
@@ -18,7 +32,6 @@ function check () {
     ERRORS=$(($ERRORS+$?))
 }
 
-# Print status header
 function dialog () {
     echo -n "PLC: $*: " >&3
 }
@@ -26,9 +39,9 @@ function dialog () {
 # Print result
 function result () {
     if [ $ERRORS -eq 0 ] ; then
-       success "$*" >&3
+        success "$@" >&3
     else
-       failure "$*" >&3
+        failure "$@" >&3
     fi
     echo >&3
 }
@@ -39,11 +52,11 @@ function plc_daemon () {
 
     # See if it's already running. Look *only* at the pid file.
     if [ -f /var/run/plc_${base}.pid ]; then
-       local line p
-       read line < /var/run/plc_${base}.pid
-       for p in $line ; do
-               [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
-       done
+        local line p
+        read line < /var/run/plc_${base}.pid
+        for p in $line ; do
+                [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
+        done
     fi
 
     [ -n "${pid:-}" -a -z "${force:-}" ] && return
@@ -62,7 +75,7 @@ function plc_daemon () {
     ret=$?
 
     if [ -f /var/run/${base}.pid ] ; then
-       mv /var/run/${base}.pid /var/run/plc_${base}.pid
+        mv /var/run/${base}.pid /var/run/plc_${base}.pid
     fi
 
     return $ret
@@ -83,18 +96,18 @@ function symlink () {
 # Argument(s) or stdin to lowercase stdout
 function lower () {
     if [ ${#*} -ge 1 ] ; then
-       tr A-Z a-z <<<$*
+        tr A-Z a-z <<<$*
     else
-       tr A-Z a-z
+        tr A-Z a-z
     fi
 }
 
 # Argument(s) or stdin to uppercase stdout
 function upper () {
     if [ ${#*} -ge 1 ] ; then
-       tr a-z A-Z <<<$*
+        tr a-z A-Z <<<$*
     else
-       tr a-z A-Z
+        tr a-z A-Z
     fi
 }
 
@@ -145,7 +158,7 @@ function plc_reload () {
 # apachectl -V
 # Server version: Apache/2.2.22 (Unix)
 # <Directory "/usr/share/plc_api/apache">
-# Options      +ExecCGI
+# Options       +ExecCGI
 # Order allow,deny
 # Allow from all
 # </Directory>
@@ -153,8 +166,8 @@ function plc_reload () {
 # apachectl -V
 # Server version: Apache/2.4.3 (Fedora)
 # <Directory "/usr/share/plc_api/apache">
-# Options      +ExecCGI
-# Require      all granted
+# Options       +ExecCGI
+# Require       all granted
 # </Directory>
 
 function apache_newauth () {
@@ -165,16 +178,16 @@ function apache_newauth () {
 }
 function apache_allow () {
     if apache_newauth; then
-       echo -e "Require all granted"
+        echo -e "Require all granted"
     else
-       echo -e "Order allow,deny\n   Allow from all"
+        echo -e "Order allow,deny\n   Allow from all"
     fi
 }
 function apache_forbid () {
     if apache_newauth; then
-       echo -e "Require all denied"
+        echo -e "Require all denied"
     else
-       echo -e "Order deny,allow\n   Deny from all"
+        echo -e "Order deny,allow\n   Deny from all"
     fi
 }
 
index 1585622..2471d65 100755 (executable)
@@ -9,43 +9,45 @@
 #
 
 # Source function library and configuration
-. /etc/plc.d/functions
-. /etc/planetlab/plc_config
+source /etc/plc.d/functions
+source /etc/planetlab/plc_config
 
 # Be verbose
 set -x
 
+echo '$1' = $1
+
 case "$1" in
     start)
-       if [ "$PLC_MAIL_ENABLED" != "1" ] ; then
-           exit 0
-       fi
+        if [ "$PLC_MAIL_ENABLED" != "1" ] ; then
+            exit 0
+        fi
 
-       MESSAGE=$"Starting mail server"
-       dialog "$MESSAGE"
+        MESSAGE=$"Starting mail server"
+        dialog "$MESSAGE"
 
-       # Add apache to list of users that can send mail as others
-       # without a warning, so that the API can send out mail.
-       count=$(grep ^apache /etc/mail/trusted-users|wc -l)
-       if [ $count -eq 0 ] ; then
-               echo "apache" >>/etc/mail/trusted-users
-       fi
+        # Add apache to list of users that can send mail as others
+        # without a warning, so that the API can send out mail.
+        count=$(grep ^apache /etc/mail/trusted-users|wc -l)
+        if [ $count -eq 0 ] ; then
+                echo "apache" >>/etc/mail/trusted-users
+        fi
 
-       (exec 3>&- 4>&- ; service sendmail start)
-       check
+        (exec 3>&- 4>&- ; systemctl start sendmail)
+        check
 
-       result "$MESSAGE"
-       ;;
+        result "$MESSAGE"
+        ;;
 
     stop)
-       MESSAGE=$"Stopping mail server"
-       dialog "$MESSAGE"
+        MESSAGE=$"Stopping mail server"
+        dialog "$MESSAGE"
 
-       service sendmail stop
-       check
+        systemctl stop sendmail
+        check
 
-       result "$MESSAGE"
-       ;;
+        result "$MESSAGE"
+        ;;
 esac
 
 exit $ERRORS
index 363a0f6..73ac470 100755 (executable)
@@ -9,8 +9,8 @@
 #
 
 # Source function library and configuration
-. /etc/plc.d/functions
-. /etc/planetlab/plc_config
+source /etc/plc.d/functions
+source /etc/planetlab/plc_config
 
 # Be verbose
 set -x
index 4203862..5d6ef40 100644 (file)
@@ -40,7 +40,7 @@ class PLCConfiguration:
     You may also save() the configuration. If a file path or object is
     not specified, the configuration will be written to the file path
     or object that was first loaded.
-    
+
     plc.save()
     plc.save("/etc/planetlab/plc_config.xml")
     """
@@ -249,7 +249,7 @@ class PLCConfiguration:
             It looks for filled-in values in the order of, local object (self),
             followed by cread (read values), and finally default values.
 
-        Arguments: 
+        Arguments:
 
             default configuration
             site configuration
@@ -358,7 +358,7 @@ class PLCConfiguration:
 
         if not category.has_key('id') or type(category['id']) not in types.StringTypes:
             return
-        
+
         category_id = category['id'].lower()
 
         if self._variables.has_key(category_id):
@@ -420,7 +420,7 @@ class PLCConfiguration:
             for tag in ['name', 'value', 'description']:
                 if variable.has_key(tag):
                     self._set_text_of_child(variable_element, tag, variable[tag])
-                
+
             if category_element.getElementsByTagName('variablelist'):
                 variablelist_element = category_element.getElementsByTagName('variablelist')[0]
             else:
@@ -441,7 +441,7 @@ class PLCConfiguration:
         (variable, category) when found
         (None, None) otherwise
         """
-        
+
         for (category_id, (category, variables)) in self._variables.iteritems():
             for variable in variables.values():
                 (id, name, value, comments) = self._sanitize_variable(category_id, variable)
@@ -575,7 +575,7 @@ class PLCConfiguration:
             for attribute in ['type']:
                 if package.has_key(attribute):
                     packagereq_element.setAttribute(attribute, package[attribute])
-                
+
             if group_element.getElementsByTagName('packagelist'):
                 packagelist_element = group_element.getElementsByTagName('packagelist')[0]
             else:
@@ -952,7 +952,7 @@ def get_current_value (cread, cwrite, category_id, variable_id):
         result=get_value (cread,category_id,variable_id)
     return result
 
-# refrain from using plc_config's _sanitize 
+# refrain from using plc_config's _sanitize
 def get_varname (config,  category_id, variable_id):
     (category, variable) = config.get (category_id, variable_id)
     return (category_id+"_"+variable['id']).upper()
@@ -996,7 +996,7 @@ def list_category (config, cid):
             for variable in variables.values():
                 result += ["%s_%s" %(cid,variable['id'])]
     return result
-    
+
 def print_category (config, cid, show_comments=True):
     cid=cid.lower()
     CID=cid.upper()
@@ -1023,15 +1023,15 @@ def consolidate (default_config, site_config, consolidated_config):
 
 def reload_service ():
     global service
-    os.system("set -x ; service %s reload" % service)
-        
+    os.system("set -x ; systemctl reload %s" % service)
+
 ####################
 def restart_service ():
     global service
     print ("==================== Stopping %s" % service)
-    os.system("service %s stop" % service)
+    os.system("systemctl stop %s" % service)
     print ("==================== Starting %s" % service)
-    os.system("service %s start" % service)
+    os.system("systemctl start %s" % service)
 
 ####################
 def prompt_variable (cdef, cread, cwrite, category, variable,
@@ -1048,7 +1048,7 @@ def prompt_variable (cdef, cread, cwrite, category, variable,
         variable_type = get_type(cdef,category_id,variable_id)
         current_value = get_current_value(cread,cwrite,category_id, variable_id)
         varname = get_varname (cread,category_id, variable_id)
-        
+
         if show_comments :
             print_name_comments (cdef, category_id, variable_id)
         prompt = "== %s : [%s] " % (varname,current_value)
@@ -1100,7 +1100,7 @@ def prompt_variables_all (cdef, cread, cwrite, show_comments):
                 except Exception, inst:
                     if (str(inst) == 'NextCategory'): break
                     else: raise
-                    
+
     except Exception, inst:
         if (str(inst) == 'BailOut'): return
         else: raise
@@ -1229,7 +1229,7 @@ def mainloop (cdef, cread, cwrite, default_config, site_config, consolidated_con
             print ("Wrote %s" % site_config)
             consolidate(default_config, site_config, consolidated_config)
             print ("You might want to type 'r' (restart %s), 'R' (reload %s) or 'q' (quit)" % \
-                   (service,service))
+                   (service, service))
         elif command in "uU":
             global usual_variables
             try:
@@ -1282,13 +1282,13 @@ def check_dir (config_file):
         except OSError, e:
             print "Cannot create dir %s due to %s - exiting" % (dirname,e)
             sys.exit(1)
-            
+
         if (not os.path.exists (dirname)):
             print "Cannot create dir %s - exiting" % dirname
             sys.exit(1)
         else:
             print "Created directory %s" % dirname
-                
+
 ####################
 def optParserSetup(configuration):
     parser = OptionParser(usage=usage())
@@ -1349,7 +1349,7 @@ def main(command,argv,configuration):
 
     # local settings only, will be modified & saved
     cwrite=PLCConfiguration()
-    
+
     try:
         cread.load(site_config)
         cwrite.load(site_config)