How can I automatically start a node.js applicatio

2019-01-30 14:28发布

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?

8条回答
相关推荐>>
2楼-- · 2019-01-30 15:19

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 use chkconfig on your app, then install the rpm on your instance.

Maybe this or this help. (or just google for "creating rpm packages")

查看更多
爷、活的狠高调
3楼-- · 2019-01-30 15:21

You can use forever-service for provisioning node script as a service and automatically starting during boots. Following commands will do the needful,

npm install -g forever-service
forever-service install test

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.

查看更多
登录 后发表回答