When working with Upstart on Ubuntu 12.04, you might notice that while your custom services work perfectly with start
, stop
, and status
commands, they mysteriously disappear when you run:
service --status-all
This isn't a bug in your configuration - it's actually by design in how Upstart and the service
command interact.
The service
command in Ubuntu 12.04 has special handling for different init systems. For --status-all
, it primarily shows services that:
- Have traditional SysV init scripts in
/etc/init.d
- Include a special status function in their init script
- Are marked as "LSB compliant" in their init script headers
Upstart services defined in /etc/init/*.conf
files work differently. While they integrate with the service
command for basic operations, they don't automatically appear in --status-all
because:
# Upstart handles status checks through its own mechanisms
status my_service
Works perfectly fine, while:
service --status-all | grep my_service
Returns nothing.
If you absolutely need your service to appear in service --status-all
, you have two options:
Option 1: Create a Compatible Init Script
Add a minimal init script in /etc/init.d
:
#!/bin/sh
### BEGIN INIT INFO
# Provides: my_service
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: My custom service
### END INIT INFO
case "$1" in
status)
status my_service
;;
*)
echo "Usage: $0 status" >&2
exit 1
;;
esac
exit 0
Then make it executable:
sudo chmod +x /etc/init.d/my_service
sudo update-rc.d my_service defaults
Option 2: Use Upstart's Native Tools
Instead of fighting the system, consider using Upstart's native tools:
# List all jobs
initctl list
# Filter for your service
initctl list | grep my_service
# Get detailed status
status my_service
For Ubuntu 12.04 systems using Upstart, I recommend:
- Use
initctl
andstatus
commands for service management - Document this behavior in your project's README
- Only create init scripts if you specifically need compatibility with legacy tools
The modern approach would be to embrace Upstart's native tools rather than trying to make them behave like SysV init.
When working with Upstart on Ubuntu 12.04, you'll notice that while service start/stop/status
commands work perfectly for your custom services, they mysteriously disappear from service --status-all
output. This isn't a bug - it's actually by design in Upstart's architecture.
The service --status-all
command primarily lists services that:
- Have traditional SysV init scripts in
/etc/init.d
- Include explicit status handling in their Upstart job definitions
Here's a typical working Upstart config that wouldn't appear in status-all:
# /etc/init/my_service.conf
description "My Custom Service"
author "Your Name"
start on filesystem
stop on shutdown
script
exec /usr/bin/my_service --daemon
end script
To make your service appear in service --status-all
, you need to implement the status command in your job definition. Here's the modified version:
# /etc/init/my_service.conf
description "My Custom Service"
author "Your Name"
start on filesystem
stop on shutdown
script
exec /usr/bin/my_service --daemon
end script
# Add this section for status support
pre-start script
if [ ! -x /usr/bin/my_service ]; then
echo "Binary not found" >&2
exit 1
fi
end script
post-stop script
# Cleanup if needed
end script
For full compatibility, create a traditional init script that interfaces with Upstart:
# /etc/init.d/my_service
#!/bin/sh
case "$1" in
status)
status_of_proc -p /var/run/my_service.pid /usr/bin/my_service my_service && exit 0 || exit $?
;;
*)
exec /sbin/initctl "$@"
;;
esac
Make it executable:
sudo chmod +x /etc/init.d/my_service
If you prefer keeping it pure Upstart without SysV compatibility, use this pattern:
# /etc/init/my_service.conf
description "My Custom Service"
author "Your Name"
start on filesystem
stop on shutdown
respawn
script
exec /usr/bin/my_service --daemon > /var/log/my_service.log 2>&1
echo $! > /var/run/my_service.pid
end script
pre-start script
# Status check logic
if pidof my_service > /dev/null; then
exit 0
else
exit 1
fi
end script
After implementing either solution, test with:
sudo service my_service status
sudo service --status-all | grep my_service