Run own bash script at system boot by specific user
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
add a comment |
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
add a comment |
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
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
shell-script
asked Feb 27 at 9:28
PolakPolak
1
1
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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.
Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have addedsu - passenger -c
so whole line in file lookssu - 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 runAPT::Periodic::Unattended-Upgrade "1";
? I can't find any information about when cron runs it.
– Polak
Mar 1 at 15:01
add a comment |
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
});
}
});
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
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Feb 27 at 10:13
WayneWayne
443
443
add a comment |
add a comment |
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.
Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have addedsu - passenger -c
so whole line in file lookssu - 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 runAPT::Periodic::Unattended-Upgrade "1";
? I can't find any information about when cron runs it.
– Polak
Mar 1 at 15:01
add a comment |
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.
Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have addedsu - passenger -c
so whole line in file lookssu - 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 runAPT::Periodic::Unattended-Upgrade "1";
? I can't find any information about when cron runs it.
– Polak
Mar 1 at 15:01
add a comment |
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.
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.
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 addedsu - passenger -c
so whole line in file lookssu - 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 runAPT::Periodic::Unattended-Upgrade "1";
? I can't find any information about when cron runs it.
– Polak
Mar 1 at 15:01
add a comment |
Thank you for answer. I have resolved it by changing line it /etc/rc.local. I have addedsu - passenger -c
so whole line in file lookssu - 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 runAPT::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
add a comment |
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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