Skip to content

Commit 247e446

Browse files
kashyapcsdague
authored andcommitted
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
1 parent 730703a commit 247e446

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

functions-common

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,11 +2264,12 @@ function python_version {
22642264
# Service wrapper to restart services
22652265
# restart_service service-name
22662266
function restart_service {
2267-
if is_ubuntu; then
2268-
sudo /usr/sbin/service $1 restart
2267+
if [ -x /bin/systemctl ]; then
2268+
sudo /bin/systemctl restart $1
22692269
else
2270-
sudo /sbin/service $1 restart
2270+
sudo service $1 restart
22712271
fi
2272+
22722273
}
22732274

22742275
# Only change permissions of a file or directory if it is not on an
@@ -2286,20 +2287,20 @@ function safe_chown {
22862287
# Service wrapper to start services
22872288
# start_service service-name
22882289
function start_service {
2289-
if is_ubuntu; then
2290-
sudo /usr/sbin/service $1 start
2290+
if [ -x /bin/systemctl ]; then
2291+
sudo /bin/systemctl start $1
22912292
else
2292-
sudo /sbin/service $1 start
2293+
sudo service $1 start
22932294
fi
22942295
}
22952296

22962297
# Service wrapper to stop services
22972298
# stop_service service-name
22982299
function stop_service {
2299-
if is_ubuntu; then
2300-
sudo /usr/sbin/service $1 stop
2300+
if [ -x /bin/systemctl ]; then
2301+
sudo /bin/systemctl stop $1
23012302
else
2302-
sudo /sbin/service $1 stop
2303+
sudo service $1 stop
23032304
fi
23042305
}
23052306

0 commit comments

Comments
 (0)