7

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.

monster
  • 608
  • 2
  • 10
  • 17
  • Maybe you should not source and use functions from the system. I don't see why `/etc/init.d/my_service status` is not doing exactly what you wrote. – rudimeier Oct 06 '16 at 14:51
  • Wait for sysadmin to come back from holiday would be the smartest solution imo. – Danila Ladner Oct 06 '16 at 15:01
  • @rudimeier I don't understand how systemd can override "/etc/init.d/my_service status" as well, which is when I gave up and asked here. – monster Oct 06 '16 at 15:14
  • 1
    @monster You are sourcing `/lib/lsb/init-functions` and other files. There they can do whatever they want. They could even call `exit` and ignore all your code below. – rudimeier Oct 06 '16 at 16:05
  • I think you need to spend some time with the documentation for sysemd. – user9517 Oct 06 '16 at 20:32
  • 1
    systemd doesn't support running a program to get status information. But you can provide custom status information to systemd via D-Bus. – Michael Hampton Oct 06 '16 at 20:58

1 Answers1

4

systemd does not support custom status commands. You have a couple alternatives:

  1. You can keep a custom status command and call it directly instead through systemd.
  2. systemd provides machine-parsable status output via systemctl show your-service-name. As seen in man systemctl, you can also use systemctl 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.
Mark Stosberg
  • 3,771
  • 23
  • 27
  • 1
    So, the short answer is "you cannot dictate the output of: sudo service my_service status". Not what I was hoping for. But if I need to update the web-management console anyway, then I can just teach it to understand the default systemd output, and I don't actually need a custom "status" anymore. Thanks. – monster Oct 07 '16 at 09:14
  • 1
    What bothered me mostly was that I can change the init.d script any time, but changing the web-management console must be approved, reviewed, tested, and deployed as a bugfix, so it adds at least a week of delay to getting that server "online". – monster Oct 07 '16 at 09:23
  • 1
    `service` is an old tool used to manage "System V init scripts". For compatibility on a systemd-based systems, some of it's functions are redirected through systemd, adding an extra layer of complexity (or compatibility, depending on how you want to look it!). `systemctl` is the systemd-native equivalent, although the syntax and sub-commands have some differences. – Mark Stosberg Oct 07 '16 at 14:44