Fixing “Unrecognized Service” Error for Upstart Jobs on Amazon EC2 Linux (Migration from Ubuntu)


3 views

During migration of Upstart jobs from Ubuntu to Amazon Linux (Elastic Beanstalk environment), you encounter the frustrating "unrecognized service" error even with simple test scripts. The same configuration that works perfectly on Ubuntu fails on EC2 Linux with no meaningful error details.

Amazon Linux uses a modified version of Upstart that behaves differently from Ubuntu's implementation:

# Check your init system:
$ ps -p 1 -o comm=
# On Amazon Linux this typically returns 'init' (Upstart)
# While Ubuntu 14.04 would return 'upstart'

Here's a verified working test.conf for Amazon Linux:

# /etc/init/test.conf
description "Test service"
author "Your Name"

start on started network
stop on shutdown

script
    exec >> /var/log/testjob.log 2>&1
    echo "Service started at $(date)"
    ping -c 1 serverfault.com
end script

Three essential modifications for Amazon Linux:

1. Use 'started network' instead of 'startup' 
2. Add proper logging redirection
3. Ensure correct file permissions:
$ sudo chmod 644 /etc/init/test.conf
$ sudo chown root:root /etc/init/test.conf

After creating your job file:

# Reload Upstart configuration
$ sudo initctl reload-configuration

# Check job status
$ sudo initctl list | grep test

# Alternative start command
$ sudo start test

When things still don't work:

# Check Upstart logs
$ sudo tail -f /var/log/boot.log

# Verify Upstart sees your job
$ sudo initctl show-config test

# Test script execution manually
$ sudo bash -x /etc/init/test.conf
  • Convert all 'start on startup' triggers
  • Implement proper logging in every job
  • Test with 'start' instead of 'service' command
  • Verify file permissions and SELinux context
  • Check for typos in job names

When migrating Upstart jobs from Ubuntu to Amazon EC2 Linux (particularly in Elastic Beanstalk environments), many developers encounter the frustrating "unrecognized service" error. This typically occurs even with perfectly valid Upstart configuration files that work fine on Ubuntu systems.

Amazon Linux uses a modified version of Upstart that behaves differently from Ubuntu's implementation:

  • Different init system paths
  • Alternative service management approach
  • Modified logging behavior

Here's a functional Upstart configuration that works on EC2 Linux:

# /etc/init/test-service.conf
description "Test service for EC2 Linux"
author "Your Name"

start on started network
stop on shutdown

script
    exec 2>&1
    echo "Test service started at $(date)" >> /var/log/test-service.log
    ping -c 5 google.com >> /var/log/test-service.log 2>&1
end script

To make your Upstart jobs work on EC2 Linux:

  1. Place config files in /etc/init/ with .conf extension
  2. Use full paths for all commands
  3. Explicitly redirect output streams
  4. Include proper start/stop conditions

After creating your service file:

# Check if Upstart recognizes your service
initctl list | grep test-service

# View service status
status test-service

# Start the service
start test-service

# Check logs
tail -f /var/log/test-service.log
Issue Solution
Permission errors Ensure root ownership of config files (644 permissions)
Path issues Use absolute paths for all commands and files
Environment differences Explicitly set PATH in your script section

For AWS Elastic Beanstalk environments, consider using platform hooks instead of Upstart:

#!/bin/bash
# .platform/hooks/postdeploy/test-service.sh

LOGFILE="/var/log/eb-test-service.log"
echo "Starting service at $(date)" > $LOGFILE
ping -c 5 google.com >> $LOGFILE 2>&1 &