Search code examples
linuxamazon-web-servicesupstartamazon-ami

Amazon Linux 2 AMI cannot start program with upstart


I wanted to run my server when connection to terminal is closed but i cannot do it.

Whenever i try to sudo start myconf_file it returns with start: command not found or even sudo initctl start myconf_file with initctl: command not found.

I am trying to use upstart for Golang .exe based on this file:

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

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

env USER='ubuntu'
env APP_DIR='/home/ubuntu/go/src/github.com/your-username/your-project-name/'
env APP_EXEC='your-project-name'

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

File is placed in /etc/init.d/folder.


Solution

  • There was no need for a script/startup. Did it using setsid. So sudo setsid ./NameOfTheExe.

    Then if the process has to be killed pidof and kill can be used.

    pidof NameOfTheExe
    

    and then as id of the process shows, for example "1871"

    sudo kill 1871