1

It used to be the case that

service service-name reload|restart|start|stop - would display a nice :

service-name start/running, process 17642

Now, while the new status output is really cool - I would really like to keep the old way - where it gives some kind of [OK] on stop|start|restart|reload - Is there any way to do this?

1
  • That's the output of initctl start, which is what service devolves to on upstart systems with upstart jobs. The "new" output is the behaviour of systemctl start which is what service is devolving to.
    – JdeBP
    May 3 '15 at 20:21
1

At the very least,something like a script and an alias would probably do the trick, here...

Maybe:

#!/bin/sh
# service-status
service "$1" "$2" 
if [[ $2 != "status ]]; then
    service "$1" status
fi 

Or better yet; since service is really systemctl anyway:

#!/bin/sh
# service-status 
systemctl "$2" "$1" 
if [[ $1 != "status" ]]; then 
    systemctl status "$1"
fi

and then add this to your .bashrc or your .bash_aliases:

alias service="service-status";
4
  • Better: use double quotes, "$1" and "$2"
    – A.B.
    May 1 '15 at 15:22
  • Where should this script be saved in 16.04? Apr 18 '17 at 21:00
  • You can put it anywhere your $PATH points to. /usr/local/bin is probably a good spot. You'll want to save it as just "service-status" and don't forget to make it executable via sudo chmod +x /usr/local/bin/service-status - or replace that path with whichever one you choose.
    – rm-vanda
    Apr 19 '17 at 12:49
  • also tweaked it a bit
    – rm-vanda
    Apr 19 '17 at 12:57
0

My version of script, that gives me the result to the output:

#!/bin/bash
service "$1" "$2"
if [[ $2 != "status" ]]; then
    service --status-all | grep "$1"
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.