How to make systemd call my "status" command?
We are replacing an Ubuntu 8.04 server with a Ubuntu 16.04. The server runs a single (non-OS) service that we need. (I'm the dev of that service, and not the sysadmin, which is on holiday this week) The service script looks about like this:
#!/bin/sh
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# ...
case "$1" in
start)
umask 002
#...
exit $?
;;
stop)
# ...
exit $?
;;
restart)
stop || exit $?
start
exit $?
;;
status)
# ...
exit $?
;;
*)
echo "Usage my_service (start|stop|restart|status)"
exit 1;;
esac
After updating the path to Java ... I got the service to work. But calling:
sudo service my_service status
returns some "standard" systemd output, instead of the code in the "status)" part of the script. Same result if I do this instead:
sudo /etc/init.d/my_service status
I'm not interested in what systemd thinks I want to know/see; I just want it to execute my code instead of it's own.
The output of "status" is parsed by some web-management console, and I don't want to have to change that application to take into account which version of Linux is installed on a specific server. "status" for the same service should output using the same format (IMO), independent of the specific OS version.
How do I tell systemd to "respect" my status command, instead of ignoring it?
Searching for "systemd status" did not get me anywhere, beyond the fact that I learned that systemd seems rather complicated.
Solution 1:
systemd
does not support custom status
commands. You have a couple alternatives:
- You can keep a custom status command and call it directly instead through
systemd
. -
systemd
provides machine-parsable status output viasystemctl show your-service-name
. As seen inman systemctl
, you can also usesystemctl set-property
to set custom properties which can be reported back in the the status. You could teach your web-management console to parse this output instead.