Run own bash script at system boot by specific user












0















I have a huge problem with some script which runs sidekiq at system boot. The script is:



#!/bin/bash
cd /home/passenger/application
source /usr/local/rvm/environments/ruby-2.5.1@gemset
bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid


It's attached inside /etc/rc.local and works but it runs with root privileges. Path to script:



/home/passenger/run_sidekiq


I need to run it with user passenger privileges. I tried:



sudo -u passenger bash -c "bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid"


and many combination of above but nothing worked.










share|improve this question



























    0















    I have a huge problem with some script which runs sidekiq at system boot. The script is:



    #!/bin/bash
    cd /home/passenger/application
    source /usr/local/rvm/environments/ruby-2.5.1@gemset
    bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid


    It's attached inside /etc/rc.local and works but it runs with root privileges. Path to script:



    /home/passenger/run_sidekiq


    I need to run it with user passenger privileges. I tried:



    sudo -u passenger bash -c "bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid"


    and many combination of above but nothing worked.










    share|improve this question

























      0












      0








      0








      I have a huge problem with some script which runs sidekiq at system boot. The script is:



      #!/bin/bash
      cd /home/passenger/application
      source /usr/local/rvm/environments/ruby-2.5.1@gemset
      bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid


      It's attached inside /etc/rc.local and works but it runs with root privileges. Path to script:



      /home/passenger/run_sidekiq


      I need to run it with user passenger privileges. I tried:



      sudo -u passenger bash -c "bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid"


      and many combination of above but nothing worked.










      share|improve this question














      I have a huge problem with some script which runs sidekiq at system boot. The script is:



      #!/bin/bash
      cd /home/passenger/application
      source /usr/local/rvm/environments/ruby-2.5.1@gemset
      bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid


      It's attached inside /etc/rc.local and works but it runs with root privileges. Path to script:



      /home/passenger/run_sidekiq


      I need to run it with user passenger privileges. I tried:



      sudo -u passenger bash -c "bundle exec sidekiq -d -L log/sidekiq.log -e testing -P tmp/sidekiq.pid"


      and many combination of above but nothing worked.







      shell-script






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 27 at 9:28









      PolakPolak

      1




      1






















          2 Answers
          2






          active

          oldest

          votes


















          0














          It's not super elegant, but you could add it to the user's crontab.



          So as the user passenger you'll run crontab -e
          then add



          @reboot /PATH/TO/SCRIPT


          to the bottom






          share|improve this answer































            0














            Try running the whole script as passenger.



            sudo -u passenger -H bash -c /home/passenger/run_sidekiq


            If your previous trials created any files, delete them, because non-superuser will not be able to overwrite them.



            P.S. you can, of course, run all commands like you were trying to do, just separating them with ;



            sudo -u passenger -H bash -c "cd /home/passenger/application; source ...; bundle ...;"


            but it does not look nice.






            share|improve this answer


























            • Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

              – Polak
              Feb 27 at 11:36













            • @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

              – John Smith
              Feb 27 at 12:39













            • It not appears on my screen but upvote is done. Thanks for advice.

              – Polak
              Feb 28 at 14:20













            • @Polak something does not work with your upvoting unfortunately

              – John Smith
              Mar 1 at 9:12











            • But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

              – Polak
              Mar 1 at 15:01











            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f503286%2frun-own-bash-script-at-system-boot-by-specific-user%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It's not super elegant, but you could add it to the user's crontab.



            So as the user passenger you'll run crontab -e
            then add



            @reboot /PATH/TO/SCRIPT


            to the bottom






            share|improve this answer




























              0














              It's not super elegant, but you could add it to the user's crontab.



              So as the user passenger you'll run crontab -e
              then add



              @reboot /PATH/TO/SCRIPT


              to the bottom






              share|improve this answer


























                0












                0








                0







                It's not super elegant, but you could add it to the user's crontab.



                So as the user passenger you'll run crontab -e
                then add



                @reboot /PATH/TO/SCRIPT


                to the bottom






                share|improve this answer













                It's not super elegant, but you could add it to the user's crontab.



                So as the user passenger you'll run crontab -e
                then add



                @reboot /PATH/TO/SCRIPT


                to the bottom







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 27 at 10:13









                WayneWayne

                443




                443

























                    0














                    Try running the whole script as passenger.



                    sudo -u passenger -H bash -c /home/passenger/run_sidekiq


                    If your previous trials created any files, delete them, because non-superuser will not be able to overwrite them.



                    P.S. you can, of course, run all commands like you were trying to do, just separating them with ;



                    sudo -u passenger -H bash -c "cd /home/passenger/application; source ...; bundle ...;"


                    but it does not look nice.






                    share|improve this answer


























                    • Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

                      – Polak
                      Feb 27 at 11:36













                    • @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

                      – John Smith
                      Feb 27 at 12:39













                    • It not appears on my screen but upvote is done. Thanks for advice.

                      – Polak
                      Feb 28 at 14:20













                    • @Polak something does not work with your upvoting unfortunately

                      – John Smith
                      Mar 1 at 9:12











                    • But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

                      – Polak
                      Mar 1 at 15:01
















                    0














                    Try running the whole script as passenger.



                    sudo -u passenger -H bash -c /home/passenger/run_sidekiq


                    If your previous trials created any files, delete them, because non-superuser will not be able to overwrite them.



                    P.S. you can, of course, run all commands like you were trying to do, just separating them with ;



                    sudo -u passenger -H bash -c "cd /home/passenger/application; source ...; bundle ...;"


                    but it does not look nice.






                    share|improve this answer


























                    • Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

                      – Polak
                      Feb 27 at 11:36













                    • @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

                      – John Smith
                      Feb 27 at 12:39













                    • It not appears on my screen but upvote is done. Thanks for advice.

                      – Polak
                      Feb 28 at 14:20













                    • @Polak something does not work with your upvoting unfortunately

                      – John Smith
                      Mar 1 at 9:12











                    • But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

                      – Polak
                      Mar 1 at 15:01














                    0












                    0








                    0







                    Try running the whole script as passenger.



                    sudo -u passenger -H bash -c /home/passenger/run_sidekiq


                    If your previous trials created any files, delete them, because non-superuser will not be able to overwrite them.



                    P.S. you can, of course, run all commands like you were trying to do, just separating them with ;



                    sudo -u passenger -H bash -c "cd /home/passenger/application; source ...; bundle ...;"


                    but it does not look nice.






                    share|improve this answer















                    Try running the whole script as passenger.



                    sudo -u passenger -H bash -c /home/passenger/run_sidekiq


                    If your previous trials created any files, delete them, because non-superuser will not be able to overwrite them.



                    P.S. you can, of course, run all commands like you were trying to do, just separating them with ;



                    sudo -u passenger -H bash -c "cd /home/passenger/application; source ...; bundle ...;"


                    but it does not look nice.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 27 at 10:13

























                    answered Feb 27 at 10:08









                    John SmithJohn Smith

                    1,19869




                    1,19869













                    • Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

                      – Polak
                      Feb 27 at 11:36













                    • @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

                      – John Smith
                      Feb 27 at 12:39













                    • It not appears on my screen but upvote is done. Thanks for advice.

                      – Polak
                      Feb 28 at 14:20













                    • @Polak something does not work with your upvoting unfortunately

                      – John Smith
                      Mar 1 at 9:12











                    • But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

                      – Polak
                      Mar 1 at 15:01



















                    • Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

                      – Polak
                      Feb 27 at 11:36













                    • @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

                      – John Smith
                      Feb 27 at 12:39













                    • It not appears on my screen but upvote is done. Thanks for advice.

                      – Polak
                      Feb 28 at 14:20













                    • @Polak something does not work with your upvoting unfortunately

                      – John Smith
                      Mar 1 at 9:12











                    • But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

                      – Polak
                      Mar 1 at 15:01

















                    Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

                    – Polak
                    Feb 27 at 11:36







                    Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have added su - passenger -c so whole line in file looks su - passenger -c '/home/passenger/run_sidekiq_on_startup || exit 1'.

                    – Polak
                    Feb 27 at 11:36















                    @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

                    – John Smith
                    Feb 27 at 12:39







                    @Polak you are welcome. but 'thanks' here are realized by upvoting the answer, not by writing it in words.

                    – John Smith
                    Feb 27 at 12:39















                    It not appears on my screen but upvote is done. Thanks for advice.

                    – Polak
                    Feb 28 at 14:20







                    It not appears on my screen but upvote is done. Thanks for advice.

                    – Polak
                    Feb 28 at 14:20















                    @Polak something does not work with your upvoting unfortunately

                    – John Smith
                    Mar 1 at 9:12





                    @Polak something does not work with your upvoting unfortunately

                    – John Smith
                    Mar 1 at 9:12













                    But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

                    – Polak
                    Mar 1 at 15:01





                    But I hope you got upvote to answer, yes? ;) Btw do you know how often/what time is run APT::Periodic::Unattended-Upgrade "1";? I can't find any information about when cron runs it.

                    – Polak
                    Mar 1 at 15:01


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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%2funix.stackexchange.com%2fquestions%2f503286%2frun-own-bash-script-at-system-boot-by-specific-user%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

                    How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                    is 'sed' thread safe

                    How to make a Squid Proxy server?