2

I'm using the following script in /etc/init/my-project.conf on my AWS instance.

description "start and stop the go program 'my-project'"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

env USER='ec2-user'
env APP_DIR='/home/ec2-user/go/src/bitbucket.com/xxx/my-project/'
env APP_EXEC='my-project'

exec start-stop-daemon —start —chuid ${USER} —chdir ${APP_DIR} —exec ${APP_DIR}${APP_EXEC}

service my-project start command gives unrecognized service error. sudo start my-project starts a process which is not my project. When I run sudo status my-project command I get my-project stop/waiting. I couldn't find what I'm doing wrong.

In the path /home/ec2-user/go/src/bitbucket.com/xxx/my-project/ there is an executable file named my-project. So basically /home/ec2-user/go/src/bitbucket.com/xxx/my-project/my-project runs the executable.

Thellimist
  • 121
  • 3

1 Answers1

1

First off the "service" command is for the "System V init scripts" found in /etc/init.d not the Upstart configs found in /etc/init. For Upstart you want to use "initctl". The equivalent of

$ service --status-all

for Upstart is

$ initctl list

Using the example upstart config found at https://gist.github.com/c4milo/940909 as a guide, I was able to get an Upstart configuration to run using the following:

    #description "start and stop the go program 'my-project'"

    start on filesystem or runlevel [2345]
    stop on runlevel [!2345]

    script

    USER='ec2-user'
    APP_DIR='/home/ec2-user/go/src/bitbucket.com/xxx/my-project/'
    APP_EXEC='my-project'

    su - ${USER} -c "exec ${APP_DIR}${APP_EXEC}"

    end script

If your changes to /etc/init/my-project.conf do not take effect you can try to force a reload with:

$ initctl reload-configuration

I was also able to remove the use of "env" as it was unnecessary.

Morgan
  • 371
  • 1
  • 3