And now for the Ubuntu answers.
This is an Ubuntu Linux question, and version 15 is now released. The Ubuntu world now has systemd. But even before version 15 the Ubuntu world had upstart. There really isn't a reason to write System 5 rc
scripts; and there is certainly no good reason for starting from there.
Both upstart and systemd do all of the "service controls". All that you need to do is describe the service.
systemd
A systemd service unit, to be placed in /etc/systemd/system/mailcatcher.service
, is
[Unit]
Description=Ruby MailCatcher
Documentation=http://mailcatcher.me/
[Service]
# Ubuntu/Debian convention:
EnvironmentFile=-/etc/default/mailcatcher
Type=simple
ExecStart=/usr/bin/mailcatcher --foreground --http-ip 192.168.50.10
[Install]
WantedBy=multi-user.target
This automatically gets one all of the systemd controls, such as:
systemctl enable mailcatcher.service
to set the service to be auto-started at boot.
systemctl preset mailcatcher.service
to set the service to be auto-started at boot, if the local policy permits it.
systemctl start mailcatcher.service
to start the service manually.
systemctl status mailcatcher.service
to see the service status.
upstart
Upstart is similar, and modifying Fideloper LLC's upstart job file to this question gives this for /etc/init/mailcatcher.conf
:
description "Mailcatcher"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/bin/mailcatcher --foreground --http-ip=192.168.50.10
This automatically gets one all of the upstart controls, such as:
initctl start mailcatcher
to start the service manually.
initctl status mailcatcher
to see the service status.
Bonus daemontools section
For kicks, for the entertainment of any daemontools-family-using people who reach this via a WWW search, and to demonstrate another reason why not to begin at System 5 rc
scripts, I ran that systemd service unit through the nosh toolset's convert-systemd-units
command to produce the following daemontools-family run script:
#!/bin/nosh
#Run file generated from ./mailcatcher.service
#Ruby MailCatcher
chdir /
read-conf --oknofile /etc/default/mailcatcher
/usr/bin/mailcatcher --foreground --http-ip 192.168.50.10
Actually, the convert-systemd-units
command generates a whole nosh service bundle directory. With that directory, which specifies dependency and ordering information, installed as /var/sv/mailcatcher
in a system with the nosh service-manager
one gets all of the nosh controls, such as:
system-control enable mailcatcher.service
to set the service to be auto-started at boot.
system-control start mailcatcher.service
to start the service manually.
system-control status mailcatcher.service
to see the service status.
system-control preset mailcatcher.service
to set the service to be auto-started at boot, if the local configuration (systemd-style presets or /etc/rc.conf{,.local}
) permits it.
Don't even begin with System 5 rc
files.
Look at this template used by SaltStack for System 5 rc
scripts. Even with the SaltStack parameterization eliminated that is 59 lines of shell script code, most of which is generic boilerplate that you'd be having to re-invent and re-write. Again. And Celada has already pointed out where you've re-invented it badly.
The systemd unit file is 11 lines long. The upstart job file is 8 lines. The nosh run
script is 6. And they do all of the start/stop/status mechanics for you. Don't start with System V rc
, especially not on Ubuntu Linux.
Further reading
start
,stop
,status
,reload
. It just runs the command. It will start the service even if it is asked to stop the service, reload the service, check its status, etc... You should fix that. Nevertheless, that's not what the problem is.mailcatcher
and in theupdate-rc.d
command you've called itmailcatcher.sh
. Which is it? You should not name ismailcatcher.sh
actually, because the suffix.sh
has a special meaning forinit.d
scripts which it would not be desirable to invoke here.