How to start node.js app on machine boot by creating a boot service

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question























    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?







    share|improve this question





















      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?







      share|improve this question











      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?









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 3 at 18:00









      b11

      11




      11




















          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




          1. 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




          2. 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




          3. 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






          share|improve this answer





















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            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






























            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




            1. 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




            2. 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




            3. 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






            share|improve this answer

























              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




              1. 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




              2. 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




              3. 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






              share|improve this answer























                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




                1. 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




                2. 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




                3. 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






                share|improve this answer













                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




                1. 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




                2. 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




                3. 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







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered May 18 at 10:46









                Chandani Patel

                537




                537






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?