Search code examples
linuxgoamazon-ec2upstart

How to start the upstart process for golang application?


I am using upstart to start my golang application. I have my application folder structure like this,

   web-app/
         /app
             main.go

I built the application as below,

$cd /home/ec2-user/go/src/github.com/dineshappavoo/web-app/app/
$go build ./...

It generated the binary app

And placed the web-app.conf in /etc/init/ folder. Here is the web-app.conf content,

#Web app upstart script
description "start and stop web app"

start on (net-device-up
and local-filesystems
and runlevel [2345])

stop on runlevel [016]

respawn
respawn limit 5 30

console output

script
    chdir /home/ec2-user/go/src/github.com/dineshappavoo/web-app/app
    exec ./app
end script

When I tried sudo initctl list, it lists the process as stop/waiting. And I tried to start the process

$sudo initctl start web-app

It shows the process as start/running. But it is not started.

I checked the /var/log/messages logs. It shows,

init: web-app main process (18740) terminated with status 127

I couldn't start the process. I think there is some issue with the chdir. I tried different options for past two days. And I am fairly new to upstart but no luck. Could someone help me with this?


Solution

  • OP eventually solved after fixing a few issues. See comments, notably:

    • upstart might not recognise environment variables
    • Amazon Linux Image currently uses an old version of init (upstart 0.6.5), lacking newer features such as console log & nested script tags

    • status 127 can occur if exec can't find the binary

    • status 1 can occur if binary runs but fails
    • substituting a simple program in an upstart script can help diagnose errors