98 lines
2.5 KiB
Bash
98 lines
2.5 KiB
Bash
|
#!/bin/bash
|
||
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||
|
source /etc/ulibauto || exit 1
|
||
|
urequire debian service conf
|
||
|
|
||
|
function display_help() {
|
||
|
uecho "$scriptname: installer le service
|
||
|
|
||
|
USAGE
|
||
|
$scriptname [options]
|
||
|
|
||
|
OPTIONS
|
||
|
-n, --name NAME
|
||
|
Spécifier le nom du service
|
||
|
-p, --port PORT
|
||
|
Spécifier le port sur lequel doit écouter le serveur
|
||
|
-d, --destdir DESTDIR
|
||
|
Spécifier le répertoire d'installation. Par défaut, l'installation se
|
||
|
fait dans le répertoire $DEFAULT_DESTDIR
|
||
|
-s, --start
|
||
|
Activer et démarrer le service après installation"
|
||
|
}
|
||
|
|
||
|
DEFAULT_DESTDIR=/opt/webpyapps
|
||
|
|
||
|
name=
|
||
|
port=
|
||
|
destdir=
|
||
|
owner=root:
|
||
|
mode=u=rwX,go=rX
|
||
|
overwrite_config=
|
||
|
enable=
|
||
|
start=
|
||
|
args=(
|
||
|
--help '$exit_with display_help'
|
||
|
-n:,--name: name=
|
||
|
-p:,--port: port=
|
||
|
-d:,--destdir: destdir=
|
||
|
--overwrite-config overwrite_config=1
|
||
|
-s,--start '$enable=1; start=1'
|
||
|
)
|
||
|
parse_args "$@"; set -- "${args[@]}"
|
||
|
|
||
|
[ -n "$name" ] || setx name=basename "$scriptdir"
|
||
|
[ -n "$destdir" ] || destdir="$DEFAULT_DESTDIR"
|
||
|
run_as_root -n "$name" ${port:+-p "$port"} \
|
||
|
-d "$destdir" ${overwrite_config:+--overwrite-config} \
|
||
|
${start:+-s}
|
||
|
"$@"
|
||
|
|
||
|
if service "$name" check; then
|
||
|
estep "Arrêt du service"
|
||
|
service "$name" stop
|
||
|
start=1
|
||
|
fi
|
||
|
|
||
|
etitle "Copie des fichiers"
|
||
|
destdir="$destdir/$name"
|
||
|
mkdir -p "$destdir" || die
|
||
|
rsync -a --exclude /server.conf --exclude /install-or-update.sh "$scriptdir/" "$destdir"
|
||
|
eend
|
||
|
|
||
|
etitle "Vérification de la configuration"
|
||
|
if [ -n "$overwrite_config" -o ! -f "$destdir/server.conf" ]; then
|
||
|
estep "Copie de la configuration initiale"
|
||
|
cp "$scriptdir/server.conf" "$destdir"
|
||
|
if [ -n "$port" ]; then
|
||
|
estep "Configuration du port d'écoute $port"
|
||
|
conf_enable "$destdir/server.conf" PORT="$port"
|
||
|
fi
|
||
|
else
|
||
|
enote "Refus d'écraser la configuration existante $destdir/server.conf"
|
||
|
fi
|
||
|
eend
|
||
|
|
||
|
etitle "Correction des permissions"
|
||
|
chown -R "$owner" "$destdir"
|
||
|
chmod -R "$mode" "$destdir"
|
||
|
eend
|
||
|
|
||
|
etitle "Configuration du service"
|
||
|
estep "Copie des fichiers init..."
|
||
|
if [ -d /etc/systemd/system ]; then
|
||
|
estep "... /etc/systemd/system/$name.service"
|
||
|
sed "\
|
||
|
s|@@destdir@@|$destdir|g
|
||
|
s|@@name@@|$name|g" "$destdir/lib/server.service" >"/etc/systemd/system/$name.service"
|
||
|
fi
|
||
|
if [ -n "$enable" ]; then
|
||
|
estep "Activation du service"
|
||
|
service_enable "$name"
|
||
|
fi
|
||
|
if [ -n "$start" ]; then
|
||
|
estep "Démarrage du service"
|
||
|
service "$name" start
|
||
|
fi
|
||
|
eend
|