sfa-config-tty can do r(estart) and R(eload) again
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Sun, 27 May 2018 11:43:06 +0000 (13:43 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Sun, 27 May 2018 11:43:06 +0000 (13:43 +0200)
Makefile
config/sfa-config-tty
setup.py
sfa.spec
systemd/sfa-db.service
systemd/sfa-setup.sh [moved from systemd/sfa-db-init.sh with 88% similarity]

index 0bedea4..bcf1edc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -187,7 +187,7 @@ RSYNC                       := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
 
 CLIENTS = $(shell ls clientbin/*.py)
 
-BINS = ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
+BINS = ./config/sfa-config-tty ./config/gen-sfa-cm-config.py ./systemd/sfa-setup.sh \
        ./sfa/server/sfa-start.py \
        ./clientbin/sfaadmin.py \
        $(CLIENTS)
@@ -204,7 +204,7 @@ syncbin: synccheck
        +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
 syncservices: synccheck
        +$(RSYNC) ./systemd/*.service  $(SSHURL)/usr/lib/systemd/system
-       +$(RSYNC) ./systemd/sfa-db-init.sh  $(SSHURL)/usr/bin
+       +$(RSYNC) ./systemd/sfa-setup.sh  $(SSHURL)/usr/bin
 syncconfig:
        +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
 synctest: synccheck
index 5377d46..252c77d 100755 (executable)
@@ -223,18 +223,19 @@ def consolidate(default_config, site_config, consolidated_config):
 
 
 def reload_service():
-    global service
-    os.system("set -x ; service %s reload" % service)
+    reload = "sfa-setup.sh reload"
+    print("Running: {}".format(reload))
+    os.system(reload)
 
 ####################
 
 
 def restart_service():
-    global service
-    print("==================== Stopping %s" % service)
-    os.system("service %s stop" % service)
-    print("==================== Starting %s" % service)
-    os.system("service %s start" % service)
+    services = ('sfa-db', 'sfa-aggregate', 'sfa-registry')
+    for service in services:
+        restart = ("systemctl -q is-active {s} && {{ echo restarting {s} ; systemctl restart {s}; }}"
+                   .format(s=service))
+        os.system(restart)
 
 ####################
 
index b168ec7..f14941a 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,7 @@ scripts = glob("clientbin/*.py") + [
     'config/sfa-config-tty',
     'config/sfa-config',
     'sfa/server/sfa-start.py',
-    'systemd/sfa-db-init.sh',
+    'systemd/sfa-setup.sh',
     'sfatables/sfatables',
     'keyconvert/keyconvert.py',
     'flashpolicy/sfa_flashpolicy.py',
index b778da7..723e9a1 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -157,7 +157,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_bindir}/keyconvert.py*
 %{_bindir}/sfa-config-tty
 %{_bindir}/sfa-config
-%{_bindir}/sfa-db-init.sh
+%{_bindir}/sfa-setup.sh
 %config /etc/sfa/default_config.xml
 %config (noreplace) /etc/sfa/aggregates.xml
 %config (noreplace) /etc/sfa/registries.xml
index d76e122..6381bbc 100644 (file)
@@ -5,7 +5,7 @@ After=postgresql.service
 
 [Service]
 Type=oneshot
-ExecStart=/bin/bash -c "/usr/bin/sfa-db-init.sh"
+ExecStart=/bin/bash -c "/usr/bin/sfa-setup.sh start-db"
 RemainAfterExit=true
 # systemd insists that we define this one
 # that does not seem useful in our case
similarity index 88%
rename from systemd/sfa-db-init.sh
rename to systemd/sfa-setup.sh
index f28d7bd..d708abc 100755 (executable)
@@ -19,7 +19,7 @@ sfa_local_config_xml=/etc/sfa/configs/site_config.xml
 sfa_local_config_sh=/etc/sfa/sfa_config.sh
 
 # Regenerate configuration files - almost verbatim from plc.init
-function reconfigure () {
+function reload () {
 
     # Regenerate the main configuration file from default values
     # overlaid with site-specific and current values.
@@ -61,7 +61,16 @@ function postgresql_setting() {
       $postgresql_conf
 }
 
-function start () {
+function start-db () {
+
+    # source shell config if present
+    # but it might not be present the very first time
+    [ ! -f $sfa_local_config_sh ] && reload
+
+    source $sfa_local_config_sh
+
+    # Export so that we do not have to specify -p to psql invocations
+    export PGPORT=$SFA_DB_PORT
 
     # only if enabled
     [ "$SFA_DB_ENABLED" == 1 -o "$SFA_DB_ENABLED" == True ] || return
@@ -116,7 +125,7 @@ function start () {
     if [ -z "$SFA_DB_PASSWORD" ] ; then
         SFA_DB_PASSWORD=$(uuidgen)
         sfa-config --category=sfa_db --variable=password --value="$SFA_DB_PASSWORD" --save=$sfa_local_config $sfa_local_config >& /dev/null
-        reconfigure
+        reload
     fi
 
     systemctl restart postgresql
@@ -139,13 +148,14 @@ function start () {
 
 }
 
-# source shell config if present
-# but it might not be present the very first time
-[ ! -f $sfa_local_config_sh ] && reconfigure
-
-source $sfa_local_config_sh
+usage="$0 start-db|reload
+  start-db: configure postgresql database and restart postgresql
+  reload: recompute miscell configuration files after changes are made in master config
+"
 
-# Export so that we do not have to specify -p to psql invocations
-export PGPORT=$SFA_DB_PORT
+func="$1"; shift
 
-start
+case "$func" in
+    start-db|reload) $func;;
+    *) echo "$usage"; exit 1;;
+esac