Ubuntu Shell Script – Status Command Doesn’t Recognize -p Option

init.dshell-script

status -p $pidfile -l $lockfile $prog

This command works on CentOS – /bin/sh shell.

But when I try to run the same command on Ubuntu 14.04 with /bin/bash shell (or zsh as well), it throws error,

status: invalid option: -p
Try `status --help' for more information.

How can we pass pidfile location argument to status command on Ubuntu?

Best Answer

status -p $pidfile -l $lockfile $prog

That's the status() shell function from /etc/rc.d/init.d/functions on RHEL/CentOS 6. It's also known as statusproc() in the Linux From Scratch world.

This tells us that you are doing things very wrongly. You're conflating the special shell helper functions available for use in System 5 rc scripts with ordinary interactive shell external commands. You're writing System 5 rc scripts on Ubuntu. And you're using PID files and lock files.

  • Don't use PID files as poor man's service tracking. Don't use lock files as poor man's service interlocking, either. They are totally unnecessary on Ubuntu Linux versions 14 and 15, which have upstart and systemd, respectively. They have no need for rickety PID files and lock files. Both systemd and upstart ensure that one does not start a single service twice, and the both properly track the process IDs of service processes, because they forked those processes in the first place. Which brings me to:
  • Don't write System 5 rc scripts on Ubuntu Linux. On version 14 one already had upstart; and on version 15 one now has systemd, just like on CentOS 7, RHEL 7, and Debian 8. There hasn't been a good reason for writing System 5 rc scripts on Ubuntu Linux for a long while. And one certainly should not start from there if one is coming to Ubuntu Linux anew. Even if you starting there because you are (mistakenly) trying to bring System 5 rc scripts across from CentOS:
  • Don't rely upon the status() shell function across operating systems or even across versions of the same operating system. As noted, it's differently named in LFS. It is not in the "new" LSB support functions from Fedora from 2009. There's not even a mandatory status System 5 rc script action in the Debian Policy Manual in the first place, although the LSB helper shell function library does have a (subtly different) status_of_proc() helper function.

Write an upstart "job file" for Ubuntu version 14, or a systemd "service unit" for CentOS 7, RHEL 7, Debian 8, or Ubuntu 15. Both upstart and systemd provide service status commands: initctl status (with a simple shim named just status) and systemctl status, respectively. To support them in a job file or a service unit you do not need to do a thing.

Further reading

Related Question