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?
Quick solution for you would be to start your app from
/etc/rc.local
; just add your command there.But if you want to go the elegant way, you'll have to package your application in a rpm file, have a startup script that goes in
/etc/rc.d
so that you can usechkconfig
on your app, then install the rpm on your instance.Maybe this or this help. (or just google for "creating rpm packages")
You can use forever-service for provisioning node script as a service and automatically starting during boots. Following commands will do the needful,
This will provision app.js in the current directory as a service via forever. The service will automatically restart every time system is restarted. Also when stopped it will attempt a graceful stop. This script provisions the logrotate script as well.
Github url: https://github.com/zapty/forever-service
As of now forever-service supports Amazon Linux, CentOS, Redhat support for other Linux distro, Mac and Windows are in works..
NOTE: I am the author of forever-service.