How to run a script after startup on Ubuntu 14.04?











up vote
2
down vote

favorite
1












I have scoured the web and tried numerous solutions. Nothing has worked for me so far, hence this question.



I have a rails application that I run with mongrel_rails start -e production -p 80. That command has to be run from the directory of the application, in this case "/var/myapp".



This is the setup:



/etc/mongrel.sh



#!/bin/bash
sleep 15;
cd /var/myapp/
mongrel_rails start -e production -p 80


I added this (sh /etc/mongrel.sh) before exit 0 in /etc/rc.local



The above does NOT work, but it does work when run manually sh /etc/mongrel.sh. I have also tried running this in a screen session using: screen -d -m *command*.



Any suggestions to get this working as desired? I need this application running after boot.










share|improve this question


























    up vote
    2
    down vote

    favorite
    1












    I have scoured the web and tried numerous solutions. Nothing has worked for me so far, hence this question.



    I have a rails application that I run with mongrel_rails start -e production -p 80. That command has to be run from the directory of the application, in this case "/var/myapp".



    This is the setup:



    /etc/mongrel.sh



    #!/bin/bash
    sleep 15;
    cd /var/myapp/
    mongrel_rails start -e production -p 80


    I added this (sh /etc/mongrel.sh) before exit 0 in /etc/rc.local



    The above does NOT work, but it does work when run manually sh /etc/mongrel.sh. I have also tried running this in a screen session using: screen -d -m *command*.



    Any suggestions to get this working as desired? I need this application running after boot.










    share|improve this question
























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I have scoured the web and tried numerous solutions. Nothing has worked for me so far, hence this question.



      I have a rails application that I run with mongrel_rails start -e production -p 80. That command has to be run from the directory of the application, in this case "/var/myapp".



      This is the setup:



      /etc/mongrel.sh



      #!/bin/bash
      sleep 15;
      cd /var/myapp/
      mongrel_rails start -e production -p 80


      I added this (sh /etc/mongrel.sh) before exit 0 in /etc/rc.local



      The above does NOT work, but it does work when run manually sh /etc/mongrel.sh. I have also tried running this in a screen session using: screen -d -m *command*.



      Any suggestions to get this working as desired? I need this application running after boot.










      share|improve this question













      I have scoured the web and tried numerous solutions. Nothing has worked for me so far, hence this question.



      I have a rails application that I run with mongrel_rails start -e production -p 80. That command has to be run from the directory of the application, in this case "/var/myapp".



      This is the setup:



      /etc/mongrel.sh



      #!/bin/bash
      sleep 15;
      cd /var/myapp/
      mongrel_rails start -e production -p 80


      I added this (sh /etc/mongrel.sh) before exit 0 in /etc/rc.local



      The above does NOT work, but it does work when run manually sh /etc/mongrel.sh. I have also tried running this in a screen session using: screen -d -m *command*.



      Any suggestions to get this working as desired? I need this application running after boot.







      linux ubuntu bash shell-script






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 23 '15 at 19:39









      Ralph

      1451111




      1451111






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote













          You can add your script in cron job.



          To add the script in cron job follow below steps




          1. Open terminal with root access.

          2. Run crontab -e this command will allow you to edit your cron.

          3. Add the line @reboot sh /etc/mongrel.sh


          The above process will execute that script once your computer boots up.






          share|improve this answer





















          • I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
            – Ralph
            Feb 23 '15 at 20:30










          • Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
            – vembutech
            Feb 23 '15 at 21:20










          • This is the output of cat /var/log/syslog.
            – Ralph
            Feb 24 '15 at 9:01










          • Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
            – Ralph
            Feb 24 '15 at 9:02












          • Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
            – Ralph
            Feb 24 '15 at 9:03


















          up vote
          0
          down vote













          Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,






          share|improve this answer





















          • Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
            – Ralph
            Feb 25 '15 at 16:49




















          up vote
          0
          down vote













          In rc.conf you have have to tell the system where sh is. So use:



          /bin/bash/sh /etc/mongrel.sh



          That will allow the system to run the script.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f881575%2fhow-to-run-a-script-after-startup-on-ubuntu-14-04%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            You can add your script in cron job.



            To add the script in cron job follow below steps




            1. Open terminal with root access.

            2. Run crontab -e this command will allow you to edit your cron.

            3. Add the line @reboot sh /etc/mongrel.sh


            The above process will execute that script once your computer boots up.






            share|improve this answer





















            • I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
              – Ralph
              Feb 23 '15 at 20:30










            • Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
              – vembutech
              Feb 23 '15 at 21:20










            • This is the output of cat /var/log/syslog.
              – Ralph
              Feb 24 '15 at 9:01










            • Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
              – Ralph
              Feb 24 '15 at 9:02












            • Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
              – Ralph
              Feb 24 '15 at 9:03















            up vote
            1
            down vote













            You can add your script in cron job.



            To add the script in cron job follow below steps




            1. Open terminal with root access.

            2. Run crontab -e this command will allow you to edit your cron.

            3. Add the line @reboot sh /etc/mongrel.sh


            The above process will execute that script once your computer boots up.






            share|improve this answer





















            • I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
              – Ralph
              Feb 23 '15 at 20:30










            • Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
              – vembutech
              Feb 23 '15 at 21:20










            • This is the output of cat /var/log/syslog.
              – Ralph
              Feb 24 '15 at 9:01










            • Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
              – Ralph
              Feb 24 '15 at 9:02












            • Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
              – Ralph
              Feb 24 '15 at 9:03













            up vote
            1
            down vote










            up vote
            1
            down vote









            You can add your script in cron job.



            To add the script in cron job follow below steps




            1. Open terminal with root access.

            2. Run crontab -e this command will allow you to edit your cron.

            3. Add the line @reboot sh /etc/mongrel.sh


            The above process will execute that script once your computer boots up.






            share|improve this answer












            You can add your script in cron job.



            To add the script in cron job follow below steps




            1. Open terminal with root access.

            2. Run crontab -e this command will allow you to edit your cron.

            3. Add the line @reboot sh /etc/mongrel.sh


            The above process will execute that script once your computer boots up.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 23 '15 at 19:52









            vembutech

            5,35811317




            5,35811317












            • I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
              – Ralph
              Feb 23 '15 at 20:30










            • Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
              – vembutech
              Feb 23 '15 at 21:20










            • This is the output of cat /var/log/syslog.
              – Ralph
              Feb 24 '15 at 9:01










            • Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
              – Ralph
              Feb 24 '15 at 9:02












            • Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
              – Ralph
              Feb 24 '15 at 9:03


















            • I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
              – Ralph
              Feb 23 '15 at 20:30










            • Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
              – vembutech
              Feb 23 '15 at 21:20










            • This is the output of cat /var/log/syslog.
              – Ralph
              Feb 24 '15 at 9:01










            • Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
              – Ralph
              Feb 24 '15 at 9:02












            • Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
              – Ralph
              Feb 24 '15 at 9:03
















            I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
            – Ralph
            Feb 23 '15 at 20:30




            I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
            – Ralph
            Feb 23 '15 at 20:30












            Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
            – vembutech
            Feb 23 '15 at 21:20




            Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
            – vembutech
            Feb 23 '15 at 21:20












            This is the output of cat /var/log/syslog.
            – Ralph
            Feb 24 '15 at 9:01




            This is the output of cat /var/log/syslog.
            – Ralph
            Feb 24 '15 at 9:01












            Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
            – Ralph
            Feb 24 '15 at 9:02






            Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
            – Ralph
            Feb 24 '15 at 9:02














            Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
            – Ralph
            Feb 24 '15 at 9:03




            Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
            – Ralph
            Feb 24 '15 at 9:03












            up vote
            0
            down vote













            Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,






            share|improve this answer





















            • Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
              – Ralph
              Feb 25 '15 at 16:49

















            up vote
            0
            down vote













            Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,






            share|improve this answer





















            • Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
              – Ralph
              Feb 25 '15 at 16:49















            up vote
            0
            down vote










            up vote
            0
            down vote









            Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,






            share|improve this answer












            Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 25 '15 at 13:08









            jcbermu

            15.5k24354




            15.5k24354












            • Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
              – Ralph
              Feb 25 '15 at 16:49




















            • Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
              – Ralph
              Feb 25 '15 at 16:49


















            Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
            – Ralph
            Feb 25 '15 at 16:49






            Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
            – Ralph
            Feb 25 '15 at 16:49












            up vote
            0
            down vote













            In rc.conf you have have to tell the system where sh is. So use:



            /bin/bash/sh /etc/mongrel.sh



            That will allow the system to run the script.






            share|improve this answer

























              up vote
              0
              down vote













              In rc.conf you have have to tell the system where sh is. So use:



              /bin/bash/sh /etc/mongrel.sh



              That will allow the system to run the script.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                In rc.conf you have have to tell the system where sh is. So use:



                /bin/bash/sh /etc/mongrel.sh



                That will allow the system to run the script.






                share|improve this answer












                In rc.conf you have have to tell the system where sh is. So use:



                /bin/bash/sh /etc/mongrel.sh



                That will allow the system to run the script.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 4 at 4:37









                LifeBoy

                10016




                10016






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f881575%2fhow-to-run-a-script-after-startup-on-ubuntu-14-04%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                    Eduardo VII do Reino Unido