How can I automatically start a node.js application in Amazon Linux AMI on aws?

前端 未结 8 988
轻奢々
轻奢々 2020-12-07 16:44

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 th

8条回答
  •  我在风中等你
    2020-12-07 17:13

    You can create a script that can start and stop your app and place it in /etc/init.d; make the script adhere to chkconfig's conventions (below), and then use chkconfig to set it to start when other services are started.

    You can pick an existing script from /etc/init.d to use as an example; this article describes the requirements, which are basically:

    • An executable script that identifies the shell needed (i.e., #!/bin/bash)
    • A comment of the form # chkconfig: where is often 345, startprio indicates where in the order of services to start, and stopprio is where in the order of services to stop. I generally pick a similar service that already exists and use that as a guide for these values (i.e., if you have a web-related service, start at the same levels as httpd, with similar start and stop priorities).

    Once your script is set up, you can use

     chkconfig --add yourscript 
     chkconfig yourscript on 
    

    and you should be good to go. (Some distros may require you to manually symlink to the script to /etc/init.d/rc.d, but I believe your AWS distro will do that for you when you enable the script.

提交回复
热议问题