0 votes
1 view
in AWS by (5.8k points)

Is there a brief guide to explain how to start up a application when the instance starts up and running? If it were one of the services installed through yum then I guess I can use /sbin/chkconfig to add it to the service. (To make it sure, is it correct?)

However, I just want to run the program which was not installed through yum. To run node.js program, I will have to run script sudo node app.js at home directory whenever the system boots up.

I am not used to Amazon Linux AMI so I am having little trouble finding a 'right' way to run some script automatically on every boot.

Is there an elegant way to do this?

1 Answer

0 votes
by (18.5k points)

Don't know about elegant, but one of the most convenient ways is to create an upstart job. This way your application will start as soon as the Linux loads.

Here's what you need to do:

1. Install upstart, which might be pre-installed if you are using standard Amazon Linux AMI

sudo yum install upstart

For ubuntu:

sudo apt-get install upstart

2. Add the conf file of your application in /etc/init and create an upstart script for your application using the following code block:

#!upstart

description "Name of your application"

start on started mountall

stop on shutdown

# Automatically Respawn:

respawn

respawn limit 99 5

env NODE_ENV=development

# Warning: this runs node as root user, which is a security risk

# in many scenarios, but upstart-ing a process as a non-root user

# is outside the scope of this question

exec node /path_to_your_app/app.js >> /var/log/nameofyourapplication.log 2>&1

3. start your application using the following command:

sudo start nameofyourapplication

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...