From 4803879f5c7e356970f12414ef3e1ce382d9ad69 Mon Sep 17 00:00:00 2001 From: Moul Date: Thu, 29 Nov 2018 17:46:37 +0100 Subject: [PATCH] [enh] #21: set Duniter as a systemd service - use 'systemctl' instead of 'service' --- conf/duniter.service | 16 ++++++++++++++++ scripts/functions.sh | 7 ++++++- scripts/install | 3 ++- scripts/remove | 3 +++ scripts/upgrade | 5 +++-- 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 conf/duniter.service diff --git a/conf/duniter.service b/conf/duniter.service new file mode 100644 index 0000000..f40c546 --- /dev/null +++ b/conf/duniter.service @@ -0,0 +1,16 @@ +[Unit] +Description=Duniter node +After=network.target + +[Service] +Environment="DUNITER_WEB=web" +Group=root +User=root +Type=forking +ExecStart=/usr/bin/duniter ${DUNITER_WEB}start +ExecReload=/usr/bin/duniter ${DUNITER_WEB}restart +ExecStop=/usr/bin/duniter stop +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/scripts/functions.sh b/scripts/functions.sh index 1c30e35..b7dc085 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -19,6 +19,11 @@ INSTALL_DUNITER_DEBIAN_PACKAGE () { rm -f $deb_path } +INSTALL_SYSTEMD () { + cp ../conf/duniter.service /etc/systemd/system/duniter.service + systemctl enable duniter.service +} + CONFIGURE_DUNITER () { duniter config --ipv4 127.0.0.1 --port $port --remoteh $domain --remotep 80 --noupnp duniter config --addep "BMAS $domain 443" @@ -51,7 +56,7 @@ REMOVE_DUNITER () { # Stop duniter daemon if running duniter status if [ `echo "$?"` == 0 ]; then - duniter stop + systemctl stop duniter fi # Remove Duniter package diff --git a/scripts/install b/scripts/install index 9ccc47a..086f125 100755 --- a/scripts/install +++ b/scripts/install @@ -45,13 +45,14 @@ ynh_app_setting_set "$app" admin "$admin" yunohost firewall allow TCP $port > /dev/null 2>&1 INSTALL_DUNITER_DEBIAN_PACKAGE +INSTALL_SYSTEMD CONFIGURE_DUNITER # Reset Duniter node's existing data (blockchain, not conf) duniter reset data > /dev/null # Launch Duniter node -duniter webstart +systemctl start duniter # Add Duniter service to the YunoHost monitoring yunohost service add $app --log /root/.config/$app/"$app"_default/"$app".log diff --git a/scripts/remove b/scripts/remove index 2ce73ea..66329c4 100755 --- a/scripts/remove +++ b/scripts/remove @@ -13,6 +13,9 @@ port=$(ynh_app_setting_get $app port) REMOVE_DUNITER +# Disable systemd service +systemctl disable duniter.service + # Remove data and conf rm -rf /root/.conf/duniter diff --git a/scripts/upgrade b/scripts/upgrade index 648da0c..ceef533 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,10 +16,11 @@ admin=$(ynh_app_setting_get "$app" admin) REMOVE_DUNITER INSTALL_DUNITER_DEBIAN_PACKAGE +INSTALL_SYSTEMD CONFIGURE_DUNITER -# Start duniter daemon -duniter webstart +# Start duniter service +systemctl start duniter CONFIG_SSOWAT CONFIG_NGINX