From 247e44625cdd3b4bf251dabfeca0ca241d9109a8 Mon Sep 17 00:00:00 2001 From: Kashyap Chamarthy Date: Fri, 20 May 2016 13:34:41 +0200 Subject: [PATCH] functions-common: Use `systemctl` when applicable We live in a new systemd world, use the native commands to talk to it if available. Change-Id: Iccdc35f0c9da2997f9e672bc1d24ca15d3403d98 --- functions-common | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/functions-common b/functions-common index d473077c3e..9973d8ff03 100644 --- a/functions-common +++ b/functions-common @@ -2264,11 +2264,12 @@ function python_version { # Service wrapper to restart services # restart_service service-name function restart_service { - if is_ubuntu; then - sudo /usr/sbin/service $1 restart + if [ -x /bin/systemctl ]; then + sudo /bin/systemctl restart $1 else - sudo /sbin/service $1 restart + sudo service $1 restart fi + } # Only change permissions of a file or directory if it is not on an @@ -2286,20 +2287,20 @@ function safe_chown { # Service wrapper to start services # start_service service-name function start_service { - if is_ubuntu; then - sudo /usr/sbin/service $1 start + if [ -x /bin/systemctl ]; then + sudo /bin/systemctl start $1 else - sudo /sbin/service $1 start + sudo service $1 start fi } # Service wrapper to stop services # stop_service service-name function stop_service { - if is_ubuntu; then - sudo /usr/sbin/service $1 stop + if [ -x /bin/systemctl ]; then + sudo /bin/systemctl stop $1 else - sudo /sbin/service $1 stop + sudo service $1 stop fi }