How to start node.js app on machine boot by creating a boot service
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
My machine is Ubuntu 16.04. I want to start my node.js application when the machine boots up everytime. According to this post about autostarting services. I tried to make a service by doing the following:
1) I created a script to start node app with node's forever
module.
#!/bin/bash
echo "Starting App"
forever -a start /opt/app/app.js
echo "App started"
2) I named this script startApp.sh
and put this script inside /etc/init.d/ folder.
3) I ran the command update-rc.d startApp defaults
But I got the error update-rc.d: error: initscript does not exist: /etc/init.d/startApp
What did I do wrong?
ubuntu boot startup services node.js
add a comment |Â
up vote
0
down vote
favorite
My machine is Ubuntu 16.04. I want to start my node.js application when the machine boots up everytime. According to this post about autostarting services. I tried to make a service by doing the following:
1) I created a script to start node app with node's forever
module.
#!/bin/bash
echo "Starting App"
forever -a start /opt/app/app.js
echo "App started"
2) I named this script startApp.sh
and put this script inside /etc/init.d/ folder.
3) I ran the command update-rc.d startApp defaults
But I got the error update-rc.d: error: initscript does not exist: /etc/init.d/startApp
What did I do wrong?
ubuntu boot startup services node.js
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My machine is Ubuntu 16.04. I want to start my node.js application when the machine boots up everytime. According to this post about autostarting services. I tried to make a service by doing the following:
1) I created a script to start node app with node's forever
module.
#!/bin/bash
echo "Starting App"
forever -a start /opt/app/app.js
echo "App started"
2) I named this script startApp.sh
and put this script inside /etc/init.d/ folder.
3) I ran the command update-rc.d startApp defaults
But I got the error update-rc.d: error: initscript does not exist: /etc/init.d/startApp
What did I do wrong?
ubuntu boot startup services node.js
My machine is Ubuntu 16.04. I want to start my node.js application when the machine boots up everytime. According to this post about autostarting services. I tried to make a service by doing the following:
1) I created a script to start node app with node's forever
module.
#!/bin/bash
echo "Starting App"
forever -a start /opt/app/app.js
echo "App started"
2) I named this script startApp.sh
and put this script inside /etc/init.d/ folder.
3) I ran the command update-rc.d startApp defaults
But I got the error update-rc.d: error: initscript does not exist: /etc/init.d/startApp
What did I do wrong?
ubuntu boot startup services node.js
asked May 3 at 18:00
b11
11
11
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
There are multiple ways to achieve this
PM2
You can use PM2 which provides you to create a startup script to start up for expected or unexpected machine restarts.
http://pm2.keymetrics.io/docs/usage/startup/
Docker I prefer to create Dockerfile and run it with --restart=always tag
If you want to continue with your shell script
Then use unix's crontab It's very easy to use & you can configure in minutes
Edit crontab run the following replacing the "USER" with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u USER -e
Once in the editor add the following line:
@reboot /usr/local/bin/forever start /your/path/to/your/index.js
else@reboot sh /your/path/to/your/startApp.sh
Save & confirm file is saved by check command of #1 again
Note: In my opinion, you should use the full path in crontab file to prevent issues
You can refer this URL reference
Ubuntu Cron HowTo
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
There are multiple ways to achieve this
PM2
You can use PM2 which provides you to create a startup script to start up for expected or unexpected machine restarts.
http://pm2.keymetrics.io/docs/usage/startup/
Docker I prefer to create Dockerfile and run it with --restart=always tag
If you want to continue with your shell script
Then use unix's crontab It's very easy to use & you can configure in minutes
Edit crontab run the following replacing the "USER" with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u USER -e
Once in the editor add the following line:
@reboot /usr/local/bin/forever start /your/path/to/your/index.js
else@reboot sh /your/path/to/your/startApp.sh
Save & confirm file is saved by check command of #1 again
Note: In my opinion, you should use the full path in crontab file to prevent issues
You can refer this URL reference
Ubuntu Cron HowTo
add a comment |Â
up vote
1
down vote
There are multiple ways to achieve this
PM2
You can use PM2 which provides you to create a startup script to start up for expected or unexpected machine restarts.
http://pm2.keymetrics.io/docs/usage/startup/
Docker I prefer to create Dockerfile and run it with --restart=always tag
If you want to continue with your shell script
Then use unix's crontab It's very easy to use & you can configure in minutes
Edit crontab run the following replacing the "USER" with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u USER -e
Once in the editor add the following line:
@reboot /usr/local/bin/forever start /your/path/to/your/index.js
else@reboot sh /your/path/to/your/startApp.sh
Save & confirm file is saved by check command of #1 again
Note: In my opinion, you should use the full path in crontab file to prevent issues
You can refer this URL reference
Ubuntu Cron HowTo
add a comment |Â
up vote
1
down vote
up vote
1
down vote
There are multiple ways to achieve this
PM2
You can use PM2 which provides you to create a startup script to start up for expected or unexpected machine restarts.
http://pm2.keymetrics.io/docs/usage/startup/
Docker I prefer to create Dockerfile and run it with --restart=always tag
If you want to continue with your shell script
Then use unix's crontab It's very easy to use & you can configure in minutes
Edit crontab run the following replacing the "USER" with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u USER -e
Once in the editor add the following line:
@reboot /usr/local/bin/forever start /your/path/to/your/index.js
else@reboot sh /your/path/to/your/startApp.sh
Save & confirm file is saved by check command of #1 again
Note: In my opinion, you should use the full path in crontab file to prevent issues
You can refer this URL reference
Ubuntu Cron HowTo
There are multiple ways to achieve this
PM2
You can use PM2 which provides you to create a startup script to start up for expected or unexpected machine restarts.
http://pm2.keymetrics.io/docs/usage/startup/
Docker I prefer to create Dockerfile and run it with --restart=always tag
If you want to continue with your shell script
Then use unix's crontab It's very easy to use & you can configure in minutes
Edit crontab run the following replacing the "USER" with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u USER -e
Once in the editor add the following line:
@reboot /usr/local/bin/forever start /your/path/to/your/index.js
else@reboot sh /your/path/to/your/startApp.sh
Save & confirm file is saved by check command of #1 again
Note: In my opinion, you should use the full path in crontab file to prevent issues
You can refer this URL reference
Ubuntu Cron HowTo
answered May 18 at 10:46
Chandani Patel
537
537
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f441624%2fhow-to-start-node-js-app-on-machine-boot-by-creating-a-boot-service%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password