Restarting a service from a script
Clash Royale CLAN TAG#URR8PPP
I have a init script - /etc/init.d/myservice
, which starts some processes, including a CLI process. And from this CLI process, I am adding a command which can be used to restart the service (restart ourselves - kind of).
What I tried - from a script (that is spawned from the CLI command), ran sudo service myservice restart
, where restart
is stop;start
.
But, this doesn't work! i.e, even though the stop
happens, by the time start
part is executing, the script terminates (not with any signals, but plain EXIT
).
I tried combinations of nohup
, disown
etc, but didn't seem to work! I am not sure how to complete the restart
without getting terminated - any pointers, or workarounds to debug further ?
To summarize:
myservice
-> spawns many processes, including CLI- CLI -> has a
restart
command, which invokes a script
script doessudo service myservice restart
--More info--
I'm on Ubuntu 12.04, i.e, upstart
bash init-script
add a comment |
I have a init script - /etc/init.d/myservice
, which starts some processes, including a CLI process. And from this CLI process, I am adding a command which can be used to restart the service (restart ourselves - kind of).
What I tried - from a script (that is spawned from the CLI command), ran sudo service myservice restart
, where restart
is stop;start
.
But, this doesn't work! i.e, even though the stop
happens, by the time start
part is executing, the script terminates (not with any signals, but plain EXIT
).
I tried combinations of nohup
, disown
etc, but didn't seem to work! I am not sure how to complete the restart
without getting terminated - any pointers, or workarounds to debug further ?
To summarize:
myservice
-> spawns many processes, including CLI- CLI -> has a
restart
command, which invokes a script
script doessudo service myservice restart
--More info--
I'm on Ubuntu 12.04, i.e, upstart
bash init-script
1
What's the OS, init system (upstart, systemd, sysvinit...)?
– Stéphane Chazelas
Aug 26 '14 at 13:01
How is the "stop" action done? Does it help if you add atrap '' TERM
in your restart script?
– Stéphane Chazelas
Aug 26 '14 at 13:02
@StéphaneChazelas added more info,stop
does a usualkill
by process name. If I addtrap..TERM
wouldn't it affect other ways of start/stop - like, from shell if one doessudo myservice stop
?
– vyom
Aug 26 '14 at 13:09
would your kill by process name (it's better to combine that with pid files to avoid problems or use cgroups as systemd) not possibly kill your script?
– Stéphane Chazelas
Aug 26 '14 at 13:16
I don't understand cgroups as systemd :(. The script name is not in the list of processes to be stopped.
– vyom
Aug 26 '14 at 13:24
add a comment |
I have a init script - /etc/init.d/myservice
, which starts some processes, including a CLI process. And from this CLI process, I am adding a command which can be used to restart the service (restart ourselves - kind of).
What I tried - from a script (that is spawned from the CLI command), ran sudo service myservice restart
, where restart
is stop;start
.
But, this doesn't work! i.e, even though the stop
happens, by the time start
part is executing, the script terminates (not with any signals, but plain EXIT
).
I tried combinations of nohup
, disown
etc, but didn't seem to work! I am not sure how to complete the restart
without getting terminated - any pointers, or workarounds to debug further ?
To summarize:
myservice
-> spawns many processes, including CLI- CLI -> has a
restart
command, which invokes a script
script doessudo service myservice restart
--More info--
I'm on Ubuntu 12.04, i.e, upstart
bash init-script
I have a init script - /etc/init.d/myservice
, which starts some processes, including a CLI process. And from this CLI process, I am adding a command which can be used to restart the service (restart ourselves - kind of).
What I tried - from a script (that is spawned from the CLI command), ran sudo service myservice restart
, where restart
is stop;start
.
But, this doesn't work! i.e, even though the stop
happens, by the time start
part is executing, the script terminates (not with any signals, but plain EXIT
).
I tried combinations of nohup
, disown
etc, but didn't seem to work! I am not sure how to complete the restart
without getting terminated - any pointers, or workarounds to debug further ?
To summarize:
myservice
-> spawns many processes, including CLI- CLI -> has a
restart
command, which invokes a script
script doessudo service myservice restart
--More info--
I'm on Ubuntu 12.04, i.e, upstart
bash init-script
bash init-script
edited Aug 26 '14 at 13:29
slm♦
250k66526683
250k66526683
asked Aug 26 '14 at 12:18
vyomvyom
133114
133114
1
What's the OS, init system (upstart, systemd, sysvinit...)?
– Stéphane Chazelas
Aug 26 '14 at 13:01
How is the "stop" action done? Does it help if you add atrap '' TERM
in your restart script?
– Stéphane Chazelas
Aug 26 '14 at 13:02
@StéphaneChazelas added more info,stop
does a usualkill
by process name. If I addtrap..TERM
wouldn't it affect other ways of start/stop - like, from shell if one doessudo myservice stop
?
– vyom
Aug 26 '14 at 13:09
would your kill by process name (it's better to combine that with pid files to avoid problems or use cgroups as systemd) not possibly kill your script?
– Stéphane Chazelas
Aug 26 '14 at 13:16
I don't understand cgroups as systemd :(. The script name is not in the list of processes to be stopped.
– vyom
Aug 26 '14 at 13:24
add a comment |
1
What's the OS, init system (upstart, systemd, sysvinit...)?
– Stéphane Chazelas
Aug 26 '14 at 13:01
How is the "stop" action done? Does it help if you add atrap '' TERM
in your restart script?
– Stéphane Chazelas
Aug 26 '14 at 13:02
@StéphaneChazelas added more info,stop
does a usualkill
by process name. If I addtrap..TERM
wouldn't it affect other ways of start/stop - like, from shell if one doessudo myservice stop
?
– vyom
Aug 26 '14 at 13:09
would your kill by process name (it's better to combine that with pid files to avoid problems or use cgroups as systemd) not possibly kill your script?
– Stéphane Chazelas
Aug 26 '14 at 13:16
I don't understand cgroups as systemd :(. The script name is not in the list of processes to be stopped.
– vyom
Aug 26 '14 at 13:24
1
1
What's the OS, init system (upstart, systemd, sysvinit...)?
– Stéphane Chazelas
Aug 26 '14 at 13:01
What's the OS, init system (upstart, systemd, sysvinit...)?
– Stéphane Chazelas
Aug 26 '14 at 13:01
How is the "stop" action done? Does it help if you add a
trap '' TERM
in your restart script?– Stéphane Chazelas
Aug 26 '14 at 13:02
How is the "stop" action done? Does it help if you add a
trap '' TERM
in your restart script?– Stéphane Chazelas
Aug 26 '14 at 13:02
@StéphaneChazelas added more info,
stop
does a usual kill
by process name. If I add trap..TERM
wouldn't it affect other ways of start/stop - like, from shell if one does sudo myservice stop
?– vyom
Aug 26 '14 at 13:09
@StéphaneChazelas added more info,
stop
does a usual kill
by process name. If I add trap..TERM
wouldn't it affect other ways of start/stop - like, from shell if one does sudo myservice stop
?– vyom
Aug 26 '14 at 13:09
would your kill by process name (it's better to combine that with pid files to avoid problems or use cgroups as systemd) not possibly kill your script?
– Stéphane Chazelas
Aug 26 '14 at 13:16
would your kill by process name (it's better to combine that with pid files to avoid problems or use cgroups as systemd) not possibly kill your script?
– Stéphane Chazelas
Aug 26 '14 at 13:16
I don't understand cgroups as systemd :(. The script name is not in the list of processes to be stopped.
– vyom
Aug 26 '14 at 13:24
I don't understand cgroups as systemd :(. The script name is not in the list of processes to be stopped.
– vyom
Aug 26 '14 at 13:24
add a comment |
2 Answers
2
active
oldest
votes
Before starting the service again you might want to wait for a few seconds so that it stops properly. You can delay your script with the following line
# waiting for 5 seconds
sleep 5
You can see more details here - http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/
thestop
is happening, but atstart
the script terminates.
– vyom
Aug 26 '14 at 13:07
add a comment |
I had searched for quite some time, but I found one solution here to this SuperUser Q&A titled: How do I detach a process from Terminal, entirely?, after posting my question here.
| at now
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%2f152246%2frestarting-a-service-from-a-script%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
Before starting the service again you might want to wait for a few seconds so that it stops properly. You can delay your script with the following line
# waiting for 5 seconds
sleep 5
You can see more details here - http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/
thestop
is happening, but atstart
the script terminates.
– vyom
Aug 26 '14 at 13:07
add a comment |
Before starting the service again you might want to wait for a few seconds so that it stops properly. You can delay your script with the following line
# waiting for 5 seconds
sleep 5
You can see more details here - http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/
thestop
is happening, but atstart
the script terminates.
– vyom
Aug 26 '14 at 13:07
add a comment |
Before starting the service again you might want to wait for a few seconds so that it stops properly. You can delay your script with the following line
# waiting for 5 seconds
sleep 5
You can see more details here - http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/
Before starting the service again you might want to wait for a few seconds so that it stops properly. You can delay your script with the following line
# waiting for 5 seconds
sleep 5
You can see more details here - http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/
answered Aug 26 '14 at 13:00
redmosesredmoses
1
1
thestop
is happening, but atstart
the script terminates.
– vyom
Aug 26 '14 at 13:07
add a comment |
thestop
is happening, but atstart
the script terminates.
– vyom
Aug 26 '14 at 13:07
the
stop
is happening, but at start
the script terminates.– vyom
Aug 26 '14 at 13:07
the
stop
is happening, but at start
the script terminates.– vyom
Aug 26 '14 at 13:07
add a comment |
I had searched for quite some time, but I found one solution here to this SuperUser Q&A titled: How do I detach a process from Terminal, entirely?, after posting my question here.
| at now
add a comment |
I had searched for quite some time, but I found one solution here to this SuperUser Q&A titled: How do I detach a process from Terminal, entirely?, after posting my question here.
| at now
add a comment |
I had searched for quite some time, but I found one solution here to this SuperUser Q&A titled: How do I detach a process from Terminal, entirely?, after posting my question here.
| at now
I had searched for quite some time, but I found one solution here to this SuperUser Q&A titled: How do I detach a process from Terminal, entirely?, after posting my question here.
| at now
edited Mar 20 '17 at 10:18
Community♦
1
1
answered Aug 26 '14 at 13:06
vyomvyom
133114
133114
add a comment |
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%2f152246%2frestarting-a-service-from-a-script%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
1
What's the OS, init system (upstart, systemd, sysvinit...)?
– Stéphane Chazelas
Aug 26 '14 at 13:01
How is the "stop" action done? Does it help if you add a
trap '' TERM
in your restart script?– Stéphane Chazelas
Aug 26 '14 at 13:02
@StéphaneChazelas added more info,
stop
does a usualkill
by process name. If I addtrap..TERM
wouldn't it affect other ways of start/stop - like, from shell if one doessudo myservice stop
?– vyom
Aug 26 '14 at 13:09
would your kill by process name (it's better to combine that with pid files to avoid problems or use cgroups as systemd) not possibly kill your script?
– Stéphane Chazelas
Aug 26 '14 at 13:16
I don't understand cgroups as systemd :(. The script name is not in the list of processes to be stopped.
– vyom
Aug 26 '14 at 13:24