Migrating from inittab to Upstart in CentOS 6: Resolving Service Autostart Issues


2 views

When transitioning from traditional System V init to Upstart in CentOS 6, many administrators encounter difficulties with service autostart functionality. The key pain point lies in proper event-based triggering compared to the simpler runlevel-based approach of inittab.

The fundamental structure of an Upstart job file requires precise event definitions. Let's examine a proper working configuration:

# /etc/init/ssh-tunnel.conf
description "SSH tunnel service"
author "System Administrator"

start on (filesystem and net-device-up IFACE=eth0)
stop on runlevel [016]

respawn
respawn limit 5 60

exec /usr/bin/su - username -c "/usr/bin/ssh -2CNL 11111:127.0.0.1:11111 10.10.1.1"

Several factors commonly prevent successful autostart:

# Common pitfalls to avoid:
1. Missing network dependency (net-device-up)
2. Incorrect runlevel specification
3. Improper service dependencies
4. Permission issues with su/sudo
5. Missing respawn configuration

Use these commands to verify and troubleshoot:

# Check job status
initctl status ssh-tunnel

# View system events
initctl list

# Check configuration syntax
init-checkconf /etc/init/ssh-tunnel.conf

# View boot process events (in another terminal)
tail -f /var/log/messages | grep upstart

For complex services with multiple dependencies:

# /etc/init/multi-service.conf
start on (started network-manager and 
          started dbus and 
          filesystem and 
          net-device-up IFACE=eth0)

stop on (shutdown or stopping network-manager)

respawn
console output
env PIDFILE=/var/run/myservice.pid

pre-start script
    [ -f /etc/default/myservice ] && . /etc/default/myservice
end script

exec /usr/sbin/myservice --daemon --pidfile $PIDFILE

When converting from inittab:

  1. Map each inittab line to a separate .conf file
  2. Convert runlevels to Upstart events
  3. Preserve respawn behavior with proper limits
  4. Test each service individually before reboot
  5. Maintain original inittab as backup during transition

Verify your configuration works before relying on it:

# First test without respawn
initctl start --no-start ssh-tunnel
initctl status ssh-tunnel

# Then test full lifecycle
initctl stop ssh-tunnel
initctl start ssh-tunnel
initctl status ssh-tunnel

# Finally verify it survives SIGHUP
kill -HUP pidof ssh

When migrating from CentOS 5 to CentOS 6, one of the most significant changes is the replacement of traditional SysV init with Upstart. Many administrators find converting /etc/inittab entries to Upstart jobs particularly challenging, especially for services that need the respawn functionality.

The original poster's configuration attempts show several valid approaches, but none seem to work reliably after reboot. The fundamental issue lies in how Upstart handles service dependencies and startup sequencing.

Here's a tested configuration that works reliably in CentOS 6 for respawn-style services:

# /etc/init/my_ssh_tunnel.conf
description "SSH tunnel service"
author "System Administrator"

start on (runlevel [345] and started network)
stop on runlevel [016]

respawn
respawn limit 10 5

exec su - username -c "/usr/bin/ssh -2CNL 11111:127.0.0.1:11111 10.10.1.1"

1. Startup conditions: The start on clause combines runlevel checking with network availability:

  • runlevel [345] ensures service starts in multi-user runlevels
  • started network guarantees network interfaces are up

2. Respawn configuration:

  • respawn recreates the process if it dies
  • respawn limit 10 5 prevents respawn storms (max 10 restarts within 5 seconds)

When troubleshooting Upstart jobs that don't start automatically:

# Check job configuration
initctl check-config my_ssh_tunnel

# View system events (use another terminal)
tail -f /var/log/messages | grep upstart

# Verify job status
initctl status my_ssh_tunnel

# Force job start for testing
initctl start my_ssh_tunnel

For servers with numerous inittab entries, consider this bulk conversion approach:

# Convert inittab respawn entries to Upstart
grep ^[^#] /etc/inittab | grep respawn | while read id runl proc comment
do
  cat > /etc/init/${id}.conf <

When converting many services:

  • Group related services where possible
  • Use start on started other-service for dependencies
  • Consider converting some to traditional init scripts if they don't need respawn

Remember to reload the configuration after creating new jobs:

initctl reload-configuration