8

I am trying to get systemd to do what init.d scripts would do, showing the status of a service automatically after being manually given a command to start or stop. Is this somehow possible?

systemd unfortunately pops right back since it runs in the background and then you have to do a second command to show the status, the start or stop may or may not have worked, systemd will not tell you unless you ask and leave you blissfully ignorant.

ie. I am trying to get

service nginx status

to run automatically after I do a

service nginx start

or

service nginx restart

(or in brain damaged systemd, systemctl start nginx.service )

  • 1
    I use the "brain damaged" commands (I like them!). They actually says nothing when everything is fine but will let you know when something fails. At least that's how it is on openSUSE 13.1. Are you sure they are "silent" when they fail? Did you try systemctl start nginx.service && echo SUCCESS || echo failure? – Huygens Jul 29 '14 at 20:29
  • 2
    @Huygens do not count on systemd being able to detect all fails, there can most definitely be silent fails or warnings. Processes are started in the background and systemd exits control, it is not at all like init.d I can see that happen consistently with PID file creation fails. Getting a status after a manual start or restart is an absolute must with systemd (and point of my question). – ck_ Jul 30 '14 at 0:14
  • thanks for the clarification, I learned something here! I'm looking forward for an answer to this question then! – Huygens Jul 30 '14 at 7:23
  • The braindead syntax is service one because unlike much better systemd syntax it does not allow you to operate on multiple services at once: systemctl stop service1 service2 service3 – god Jun 19 '16 at 23:56
  • 1
    If you still see the same inconsistency when checking the exit status of systemctl as @Huygens had suggested, then the problem may be that nginx.service starts successfully but crashes afterwards. Try checking the journal or in Nginx logs. – Amir Jan 17 '19 at 8:38
1

There's no built-in command for your use-case so you'll have to make an alias for your favorite shell or a trivial script wrapper.

| improve this answer | |
0

To make systemd more "verbose", add/uncomment the following lines in your /etc/systemd/journald.conf and then reboot:

ForwardToConsole=yes
MaxLevelConsole=debug
| improve this answer | |

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.