From e52b30cff858c51bcb519de6e509328a0631eb16 Mon Sep 17 00:00:00 2001 From: keoma Date: Sun, 10 Feb 2019 16:42:40 +0100 Subject: [PATCH] #42 using systemctl to get service status --- conf/ynh-hotspot | 2 +- scripts/install | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 13c53c5..f6c6283 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -285,7 +285,7 @@ if [ "$1" != restart ]; then echo -n "Retrieving Yunohost settings... " - ynh_service_enabled=$(ynh_setting_get hotspot service_enabled) + ynh_service_enabled=$(systemctl is-enabled ynh-hotspot) ynh_wifi_device=$(ynh_setting_get hotspot wifi_device) ynh_wifi_channel=$(ynh_setting_get hotspot wifi_channel) ynh_multissid=$(ynh_setting_get hotspot multissid) diff --git a/scripts/install b/scripts/install index a49a44b..b06ca24 100644 --- a/scripts/install +++ b/scripts/install @@ -46,6 +46,9 @@ firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE app=$YNH_APP_INSTANCE_NAME +# the service name must match the service template files +service_name='ynh-hotspot' + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -165,9 +168,11 @@ wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }') # Save arguments if [[ -z $wifi_device ]]; then + ynh_systemctl disable $service_name ynh_app_setting_set $app service_enabled 0 wifi_device=none else + ynh_systemctl enable $service_name ynh_app_setting_set $app service_enabled 1 fi @@ -190,6 +195,7 @@ ynh_app_setting_set $app ip4_dns0 80.67.188.188 ynh_app_setting_set $app ip4_dns1 80.67.169.12 ynh_app_setting_set $app ip4_nat_prefix 10.0.242 ynh_app_setting_set $app vpnclient no +ynh_app_setting_set $app service_name $service_name #================================================= @@ -249,8 +255,8 @@ sed 's||/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/wifia sed "s||${path_url}|g" -i /var/www/wifiadmin/config.php # Copy init script -install -o root -g root -m 0755 ../conf/ynh-hotspot /usr/local/bin/ -install -o root -g root -m 0644 ../conf/ynh-hotspot.service /etc/systemd/system/ +install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +install -o root -g root -m 0644 ../conf/$service_name.service /etc/systemd/system/ # Update firewall for DHCP yunohost firewall allow --no-upnp --ipv6 UDP 547 @@ -273,15 +279,15 @@ if [[ $ip6_addr != none ]]; then fi fi -systemctl enable ynh-hotspot -yunohost service add ynh-hotspot --description "creates a Wi-Fi access point" +# register the service +yunohost service add $service_name --description "creates a Wi-Fi access point" +# start the service if device is present if [[ $wifi_device == none ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 +else + ynh_systemctl start $service_name fi -# start the app -ynh_systemctl start ynh-hotspot - # Reload SSOwat config yunohost app ssowatconf