Browse Source

systemd: Convert services (SySv init) to systemctl (systemd) commands

Sebastien Badia 10 years ago
parent
commit
428e5d789f
5 changed files with 21 additions and 19 deletions
  1. 2 2
      README.md
  2. 5 5
      conf/init_ynh-hotspot
  3. 6 5
      scripts/install
  4. 4 3
      scripts/remove
  5. 4 4
      sources/controller.php

+ 2 - 2
README.md

@@ -47,6 +47,6 @@ This app works with a non-stable version of YunoHost.
 
 Until this version is available (coming soon!) as an official stable release, you need to execute some commands before installing this app:
 
-    # service bind9 stop
-    # update-rc.d bind9 remove
+    # systemctl stop bind9
+    # systemctl disable bind9
     # apt-get install dnsmasq

+ 5 - 5
conf/init_ynh-hotspot

@@ -89,7 +89,7 @@ is_dhcpd4_running() {
 }
 
 is_hostapd_running() {
-  service hostapd status &> /dev/null
+  systemctl is-active hostapd --quiet &> /dev/null
 }
 
 is_running() {
@@ -218,7 +218,7 @@ start_hostapd() {
     rm /etc/hostapd/hostapd.conf.tmp
   done
 
-  service hostapd start
+  systemctl start hostapd --quiet
 }
 
 ## Unsetters
@@ -269,7 +269,7 @@ stop_dhcpd4() {
 }
 
 stop_hostapd() {
-  service hostapd stop
+  systemctl stop hostapd --quiet
 }
 
 ## Tools
@@ -317,7 +317,7 @@ if [ "$1" != restart ]; then
   # Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
   if [ ! -e /tmp/.ynh-hotspot-boot ]; then
     touch /tmp/.ynh-hotspot-boot
-    service php5-fpm restart
+    systemctl restart php5-fpm --quiet
   fi
   
   # Variables
@@ -499,7 +499,7 @@ case "$1" in
     fi
 
     if has_vpnclient_app; then
-      service ynh-vpnclient start
+      systemctl start ynh-vpnclient --quiet
     fi
   ;;
   restart)

+ 6 - 5
scripts/install

@@ -39,10 +39,10 @@ if [ "${ynh_version}" -lt 220 ]; then
   exit 1
 fi
 
-sudo service dnsmasq status &> /dev/null
+sudo systemctl status dnsmasq status --quiet &> /dev/null
 
 if [ $? -ne 0 ]; then
-  echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && service dnsmasq start)"
+  echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind && systemctl start dnsmasq)"
   exit 1
 fi
 
@@ -191,7 +191,7 @@ sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/
 sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
 
 # Copy init script
-sudo install -o root -g root -m 0755 ../conf/init_ynh-hotspot /etc/init.d/ynh-hotspot
+sudo install -o root -g root -m 0755 ../conf/ynh-hotspot.service /lib/systemd/system/ynh-hotspot.service
 
 # Update firewall for DHCP
 sudo yunohost firewall allow --no-upnp --ipv6 UDP 547
@@ -208,7 +208,7 @@ sudo yunohost service disable hostapd
 sudo yunohost service add php5-fpm
 sudo yunohost service enable php5-fpm
 
-sudo service nginx reload
+sudo systemcld reload nginx
 
 # Remove IPv6 address set if there is a VPN installed
 if [ "${ip6_addr}" != none ]; then
@@ -220,7 +220,8 @@ fi
 
 sudo yunohost service add ynh-hotspot
 sudo yunohost service enable ynh-hotspot
-sudo service ynh-hotspot start
+sudo systemctl reenable ynh-hotspot
+sudo systemcld start ynh-hotspot
 
 # Update SSO for wifiadmin
 sudo yunohost app ssowatconf

+ 4 - 3
scripts/remove

@@ -21,9 +21,10 @@
 domain=$(sudo yunohost app setting hotspot domain)
 
 # The End
-sudo service ynh-hotspot stop
+sudo systemctl stop ynh-hotspot
 sudo yunohost service remove ynh-hotspot
-sudo rm -f /etc/init.d/ynh-hotspot
+sudo systemctl disable ynh-hotspot
+sudo rm -f /lib/systemd/system/ynh-hotspot.service
 sudo rm -f /tmp/.ynh-hotspot-*
 
 # Update firewall for DHCP
@@ -43,7 +44,7 @@ sudo rm -f /lib/firmware/htc-9271.fw
 # Restart services
 sudo yunohost service stop php5-fpm
 sudo yunohost service start php5-fpm
-sudo service nginx reload
+sudo systemctl reload nginx
 
 # Remove sources
 sudo rm -rf /var/www/wifiadmin/

+ 4 - 4
sources/controller.php

@@ -27,23 +27,23 @@ function moulinette_set($var, $value) {
 }
 
 function stop_service() {
-  exec('sudo service ynh-hotspot stop');
+  exec('sudo systemctl stop ynh-hotspot');
 }
 
 function start_service() {
-  exec('sudo service ynh-hotspot start', $output, $retcode);
+  exec('sudo systemctl start ynh-hotspot', $output, $retcode);
 
   return $retcode;
 }
 
 function service_status() {
-  exec('sudo service ynh-hotspot status', $output);
+  exec('sudo systemctl is-active ynh-hotspot', $output);
 
   return $output;
 }
 
 function service_faststatus() {
-  exec('sudo service hostapd status', $output, $retcode);
+  exec('sudo systemctl is-active hostapd', $output, $retcode);
 
   return $retcode;
 }