How to stop a service before executing an ExecStart entry?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I would like to set up a Timer which will stop a service, execute a script and restart the service.
One of the possibilities is to use
Type=oneshot
ExecStartPre=/bin/systemctl stop myservice
ExecStart=/usr/local/bin/myscript.sh
ExecStartPost=/bin/systemctl start myservice
Another one is to have myscript.sh handling the whole thing, including systemctl.
I find it awkward, though, to use systemctl within a service declaration, when there may be systemd built-in mechanisms to interact with services. Is there a cleaner way to perform these operations?
systemd systemd-timer
add a comment |
up vote
1
down vote
favorite
I would like to set up a Timer which will stop a service, execute a script and restart the service.
One of the possibilities is to use
Type=oneshot
ExecStartPre=/bin/systemctl stop myservice
ExecStart=/usr/local/bin/myscript.sh
ExecStartPost=/bin/systemctl start myservice
Another one is to have myscript.sh handling the whole thing, including systemctl.
I find it awkward, though, to use systemctl within a service declaration, when there may be systemd built-in mechanisms to interact with services. Is there a cleaner way to perform these operations?
systemd systemd-timer
Can you give more context here? Why do you needmyserviceto be stopped during the run ofmyscript.sh? There's nothing essentially wrong with usingsystemctlinside a service (and you probably won't find a solution that doesn't involve using it), but perhaps, depending on whatmyscript.shis doing, you could just hook it intomyservice.servicedirectly (in anExecStartPre=, perhaps checking if it needs to run) and then just having the timer launch asystemctl restart myserviceinstead... Just an idea. Having more context on what you're trying to do would help here.
– Filipe Brandenburger
Nov 23 at 19:17
@FilipeBrandenburger: this is a Timer which will perform a backup. The service backed up needs first to be stopped, then restarted afterwards.
– WoJ
Nov 23 at 19:22
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to set up a Timer which will stop a service, execute a script and restart the service.
One of the possibilities is to use
Type=oneshot
ExecStartPre=/bin/systemctl stop myservice
ExecStart=/usr/local/bin/myscript.sh
ExecStartPost=/bin/systemctl start myservice
Another one is to have myscript.sh handling the whole thing, including systemctl.
I find it awkward, though, to use systemctl within a service declaration, when there may be systemd built-in mechanisms to interact with services. Is there a cleaner way to perform these operations?
systemd systemd-timer
I would like to set up a Timer which will stop a service, execute a script and restart the service.
One of the possibilities is to use
Type=oneshot
ExecStartPre=/bin/systemctl stop myservice
ExecStart=/usr/local/bin/myscript.sh
ExecStartPost=/bin/systemctl start myservice
Another one is to have myscript.sh handling the whole thing, including systemctl.
I find it awkward, though, to use systemctl within a service declaration, when there may be systemd built-in mechanisms to interact with services. Is there a cleaner way to perform these operations?
systemd systemd-timer
systemd systemd-timer
asked Nov 21 at 10:14
WoJ
396113
396113
Can you give more context here? Why do you needmyserviceto be stopped during the run ofmyscript.sh? There's nothing essentially wrong with usingsystemctlinside a service (and you probably won't find a solution that doesn't involve using it), but perhaps, depending on whatmyscript.shis doing, you could just hook it intomyservice.servicedirectly (in anExecStartPre=, perhaps checking if it needs to run) and then just having the timer launch asystemctl restart myserviceinstead... Just an idea. Having more context on what you're trying to do would help here.
– Filipe Brandenburger
Nov 23 at 19:17
@FilipeBrandenburger: this is a Timer which will perform a backup. The service backed up needs first to be stopped, then restarted afterwards.
– WoJ
Nov 23 at 19:22
add a comment |
Can you give more context here? Why do you needmyserviceto be stopped during the run ofmyscript.sh? There's nothing essentially wrong with usingsystemctlinside a service (and you probably won't find a solution that doesn't involve using it), but perhaps, depending on whatmyscript.shis doing, you could just hook it intomyservice.servicedirectly (in anExecStartPre=, perhaps checking if it needs to run) and then just having the timer launch asystemctl restart myserviceinstead... Just an idea. Having more context on what you're trying to do would help here.
– Filipe Brandenburger
Nov 23 at 19:17
@FilipeBrandenburger: this is a Timer which will perform a backup. The service backed up needs first to be stopped, then restarted afterwards.
– WoJ
Nov 23 at 19:22
Can you give more context here? Why do you need
myservice to be stopped during the run of myscript.sh? There's nothing essentially wrong with using systemctl inside a service (and you probably won't find a solution that doesn't involve using it), but perhaps, depending on what myscript.sh is doing, you could just hook it into myservice.service directly (in an ExecStartPre=, perhaps checking if it needs to run) and then just having the timer launch a systemctl restart myservice instead... Just an idea. Having more context on what you're trying to do would help here.– Filipe Brandenburger
Nov 23 at 19:17
Can you give more context here? Why do you need
myservice to be stopped during the run of myscript.sh? There's nothing essentially wrong with using systemctl inside a service (and you probably won't find a solution that doesn't involve using it), but perhaps, depending on what myscript.sh is doing, you could just hook it into myservice.service directly (in an ExecStartPre=, perhaps checking if it needs to run) and then just having the timer launch a systemctl restart myservice instead... Just an idea. Having more context on what you're trying to do would help here.– Filipe Brandenburger
Nov 23 at 19:17
@FilipeBrandenburger: this is a Timer which will perform a backup. The service backed up needs first to be stopped, then restarted afterwards.
– WoJ
Nov 23 at 19:22
@FilipeBrandenburger: this is a Timer which will perform a backup. The service backed up needs first to be stopped, then restarted afterwards.
– WoJ
Nov 23 at 19:22
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
By (ab?)using the WatchdogSec the service will terminate when it fails to acknowledge within the time. It will then restart, but execute the script first.
WatchdogSec=interval
Restart=on-watchdog
ExecStopPost=/script.sh
ref: WatchdogSec
Having the service being able to be backed up while running would be a much nicer service.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
By (ab?)using the WatchdogSec the service will terminate when it fails to acknowledge within the time. It will then restart, but execute the script first.
WatchdogSec=interval
Restart=on-watchdog
ExecStopPost=/script.sh
ref: WatchdogSec
Having the service being able to be backed up while running would be a much nicer service.
add a comment |
up vote
0
down vote
By (ab?)using the WatchdogSec the service will terminate when it fails to acknowledge within the time. It will then restart, but execute the script first.
WatchdogSec=interval
Restart=on-watchdog
ExecStopPost=/script.sh
ref: WatchdogSec
Having the service being able to be backed up while running would be a much nicer service.
add a comment |
up vote
0
down vote
up vote
0
down vote
By (ab?)using the WatchdogSec the service will terminate when it fails to acknowledge within the time. It will then restart, but execute the script first.
WatchdogSec=interval
Restart=on-watchdog
ExecStopPost=/script.sh
ref: WatchdogSec
Having the service being able to be backed up while running would be a much nicer service.
By (ab?)using the WatchdogSec the service will terminate when it fails to acknowledge within the time. It will then restart, but execute the script first.
WatchdogSec=interval
Restart=on-watchdog
ExecStopPost=/script.sh
ref: WatchdogSec
Having the service being able to be backed up while running would be a much nicer service.
answered 14 hours ago
danblack
3166
3166
add a comment |
add a comment |
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%2f483169%2fhow-to-stop-a-service-before-executing-an-execstart-entry%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
Can you give more context here? Why do you need
myserviceto be stopped during the run ofmyscript.sh? There's nothing essentially wrong with usingsystemctlinside a service (and you probably won't find a solution that doesn't involve using it), but perhaps, depending on whatmyscript.shis doing, you could just hook it intomyservice.servicedirectly (in anExecStartPre=, perhaps checking if it needs to run) and then just having the timer launch asystemctl restart myserviceinstead... Just an idea. Having more context on what you're trying to do would help here.– Filipe Brandenburger
Nov 23 at 19:17
@FilipeBrandenburger: this is a Timer which will perform a backup. The service backed up needs first to be stopped, then restarted afterwards.
– WoJ
Nov 23 at 19:22