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?


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

  • It's a great answer, but your assertion that @Madhaven is "doing things very wrongly" is a bit strong. I found this question because i was trying to debug an init.d script, and I hadn't found the status function in the other script - it's possible that he moved a working script from CentOS to Ubuntu, but didn't realise he also had to move the functions script. – andrew lorien Mar 7 '17 at 7:11

The status on CentOS 6.5 is version 0.6.5 from package upstart.
The status on Ubuntu 14.04 is version 1.12.1, also from package upstart.

Neither of these accept the -p option.

The Upstart status doesn't allow you to specify PIDFILE in any way. You can specify a job and provide key=value parameters to be passed to the scripts. The other commandline options can be viewed with status --help.

On CentOS 7 there is no status (at least not on my installation), as CentOS 7 no longer uses Upstart (having switched to systemd). You can try to find out which package provides the status on your CentOS ( yum whatprovides $(which status)) and see if you can install that package on Ubuntu and so get an alternative status (which hopefully has a different, non-clashing, name as well).

  • @MadhavanKumar The job is typically the name of what at other times would have been called a service e.g. status ssh to see if the ssh-daemon is running. – Anthon Jun 6 '15 at 18:01

Your Answer

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