From 46537f13c45d5e40967ab6cf6a9912da405d08a5 Mon Sep 17 00:00:00 2001 From: viennet Date: Sat, 5 Dec 2020 17:29:26 +0100 Subject: [PATCH] 7.19a: configuration with systemd --- VERSION.py | 2 +- config/configure_systemd.sh | 17 +++++++++++++++++ config/delete_dept.sh | 5 +++-- config/distrib.sh | 2 +- config/install_debian10.sh | 7 ++++--- config/restore_scodoc_data.sh | 5 ++--- config/save_scodoc_data.sh | 3 ++- config/upgrade.sh | 6 ++---- config/utils.sh | 21 ++++++++++++++++++++- misc/Restore-database.txt | 4 ++-- misc/backup_db2 | 4 ++-- 11 files changed, 56 insertions(+), 20 deletions(-) create mode 100755 config/configure_systemd.sh diff --git a/VERSION.py b/VERSION.py index 853ccfbb8..337786e6b 100644 --- a/VERSION.py +++ b/VERSION.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "7.18" +SCOVERSION = "7.19a" SCONAME = "ScoDoc" diff --git a/config/configure_systemd.sh b/config/configure_systemd.sh new file mode 100755 index 000000000..235694188 --- /dev/null +++ b/config/configure_systemd.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Modify ScoDoc install tu use systemd +# E. Viennet, 2020-12-04 +source config.sh +source utils.sh + +check_uid_root $0 + +echo 'Installation du demarrage automatique de ScoDoc (systemd)' +cp $SCODOC_DIR/config/etc/scodoc.service /etc/systemd/system +systemctl enable scodoc.service + +echo "A partir de maintenant, utiliser" +echo " pour demarrer: systemctl start scodoc" +echo " pour arreter : systemctl stop scodoc" + diff --git a/config/delete_dept.sh b/config/delete_dept.sh index 9a88a70ce..b0e9919a4 100755 --- a/config/delete_dept.sh +++ b/config/delete_dept.sh @@ -41,7 +41,8 @@ cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg if [ -e $cfg_pathname ] then # arret de ScoDoc - /etc/init.d/scodoc stop + scodocctl stop + # suppression de la base postgres db_name=$(cat $cfg_pathname | sed '/^dbname=*/!d; s///;q') echo "suppression de la base postgres $db_name" @@ -53,7 +54,7 @@ then read ans if [ "$(norm_ans "$ans")" = 'Y' ] then - /etc/init.d/scodoc start + scodocctl start fi exit 0 else diff --git a/config/distrib.sh b/config/distrib.sh index 0958fb107..9ffead11c 100644 --- a/config/distrib.sh +++ b/config/distrib.sh @@ -19,7 +19,7 @@ echo "Changing to directory " $SCODOC_DIR/config cd $SCODOC_DIR/config echo "Stopping ScoDoc..." -/etc/init.d/scodoc stop +scodocctl stop # DROITS echo -n "Verification des droits: proprietaire www-data ? (y/n) [y] " diff --git a/config/install_debian10.sh b/config/install_debian10.sh index 090dae4c9..8e28134df 100755 --- a/config/install_debian10.sh +++ b/config/install_debian10.sh @@ -219,9 +219,10 @@ echo -n "Voulez vous installer le service scodoc ? (y/n) [y] " read ans if [ "$(norm_ans "$ans")" != 'N' ] then - echo 'Installation du demarrage automatique de ScoDoc' - cp $SCODOC_DIR/config/etc/scodoc /etc/init.d/ - update-rc.d scodoc defaults + # ScoDoc 7.19+ uses systemd + echo 'Installation du demarrage automatique de ScoDoc (systemd)' + cp $SCODOC_DIR/config/etc/scodoc.service /etc/systemd/system + systemctl enable scodoc.service fi diff --git a/config/restore_scodoc_data.sh b/config/restore_scodoc_data.sh index aed3a1ea6..f2bd87858 100755 --- a/config/restore_scodoc_data.sh +++ b/config/restore_scodoc_data.sh @@ -71,7 +71,7 @@ fi echo "Source is $SRC" echo "Stopping ScoDoc..." -/etc/init.d/scodoc stop +scodocctl stop # Erase all postgres databases and load data chmod a+rx "$SRC" @@ -141,5 +141,4 @@ cd $SCODOC_DIR/config # echo -echo "Ok. Run \"/etc/init.d/scodoc start\" to start ScoDoc." - +scodocctl start \ No newline at end of file diff --git a/config/save_scodoc_data.sh b/config/save_scodoc_data.sh index 09cc0644d..a53c76403 100755 --- a/config/save_scodoc_data.sh +++ b/config/save_scodoc_data.sh @@ -8,6 +8,7 @@ # # E. Viennet, Sept 2011, Aug 2020 # +source utils.sh # Destination directory if [ ! $# -eq 1 ] @@ -37,7 +38,7 @@ source utils.sh check_uid_root $0 echo "Stopping ScoDoc..." -/etc/init.d/scodoc stop +scodocctl stop # Dump all postgres databases echo "Dumping SQL database..." diff --git a/config/upgrade.sh b/config/upgrade.sh index 32e34f654..894fc0785 100755 --- a/config/upgrade.sh +++ b/config/upgrade.sh @@ -28,8 +28,7 @@ then (cd "$SCODOC_DIR"; find . -name .svn -type d -exec dirname {} \; | xargs svn upgrade) fi -echo "Stopping ScoDoc..." -/etc/init.d/scodoc stop +scodocctl stop echo echo "Using SVN to update $SCODOC_DIR..." @@ -133,7 +132,6 @@ su -c "$SCODOC_DIR/config/postupgrade-db.py" $POSTGRES_USER # echo -echo "Starting ScoDoc..." -/etc/init.d/scodoc start +scodocctl start diff --git a/config/utils.sh b/config/utils.sh index 8637b7363..4508303b6 100644 --- a/config/utils.sh +++ b/config/utils.sh @@ -29,6 +29,25 @@ terminate() { exit 1 } +# Start/stop scodoc, using sysv or systemd +scodocctl() { + if [ "$1" = "start" ]; then + echo "Starting ScoDoc..." + elif [ "$1" = "stop" ]; then + echo "Stopping ScoDoc" + else + echo "Error: invalid argument for scodocctl" + exit 1 + fi + if [ -e /etc/systemd/system/scodoc.service ] + then + systemctl $1 scodoc + else + echo "(using legacy SystemV)" + /etc/init.d/scodoc $1 + fi +} + # --- Ensure postgres user www-data exists init_postgres_user() { # run as root if [ -z $(echo "select usename from pg_user;" | su -c "$PSQL -d template1 -p $POSTGRES_PORT" $POSTGRES_SUPERUSER | grep $POSTGRES_USER) ] @@ -43,7 +62,7 @@ init_postgres_user() { # run as root # XXX inutilise gen_passwd() { PASSWORD_LENGTH="8" - ALLOWABLE_ASCII="~@#$%^&*()_+=-?><0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + ALLOWABLE_ASCII="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#$%^&*()_+=-?><" SEED=$(head -c4 /dev/urandom | od -t u4 | awk '{ print $2 }') RANDOM=$SEED n=1 diff --git a/misc/Restore-database.txt b/misc/Restore-database.txt index 89fcfcc7f..b912e90cd 100644 --- a/misc/Restore-database.txt +++ b/misc/Restore-database.txt @@ -15,7 +15,7 @@ Le copier sur la machine destination. 2) Sur la machine destination: Avant toute chose, stopper scodoc: - /etc/init.d/scodoc stop + /etc/init.d/scodoc stop (ou systemctl stop scodoc)) 1.1) Supprimer toutes les bases ScoDoc existantes s'il y en a: su postgres @@ -42,7 +42,7 @@ done Puis redemarrer ScoDoc: - en tant que root: /etc/init.d/scodoc start + en tant que root: /etc/init.d/scodoc start (ou systemctl start scodoc) NB: si la version des sources a changée, lancer imperativement le script de mise a jour avant de redemarrer scodoc, afin qu'il change si besoin la base de donnees: diff --git a/misc/backup_db2 b/misc/backup_db2 index f34c19f5e..779287702 100755 --- a/misc/backup_db2 +++ b/misc/backup_db2 @@ -12,7 +12,7 @@ # # Note: pour restaurer un backup (en supprimant la base existante !): # -# 0- Arreter scodoc: /etc/init.d/scodoc stop +# 0- Arreter scodoc: /etc/init.d/scodoc stop (ou systemctl stop scodoc) # # Puis en tant qu'utilisateur postgres: su postgres # 1- supprimer la base existante si elle existe: dropdb SCOXXX @@ -23,7 +23,7 @@ # 3- pg_restore -d SCOXXX SCOXXX_pgdump # # Revenir a l'utilisateur root: exit -# 4- Relancer scodoc: /etc/init.d/scodoc start +# 4- Relancer scodoc: /etc/init.d/scodoc start (ou systemctl start scodoc) DBNAME=$1 DUMPBASE="$DBNAME"-BACKUPS