Why `systemctl stop service` can't envoke the service?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
vim /home/mytest.sh
rm -f /home/mytest/*
I want to write a service to execute the remove action.
My expections:sudo systemctl stop mytest can delete files in /home/mytestsudo systemctl start mytest do nothing.
Edit my service file.
sudo vim /etc/systemd/system/mytest.service
[Unit]
Description=delete file
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
Enable it.
sudo systemctl enable mytest
Now i found a strange action for mytest service.
sudo systemctl start mytest can delete files in /home/mytestsudo systemctl stop mytest do nothing.
Why?
Pleas give a explanation in detail.
systemd startx start-stop-daemon
add a comment |Â
up vote
1
down vote
favorite
vim /home/mytest.sh
rm -f /home/mytest/*
I want to write a service to execute the remove action.
My expections:sudo systemctl stop mytest can delete files in /home/mytestsudo systemctl start mytest do nothing.
Edit my service file.
sudo vim /etc/systemd/system/mytest.service
[Unit]
Description=delete file
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
Enable it.
sudo systemctl enable mytest
Now i found a strange action for mytest service.
sudo systemctl start mytest can delete files in /home/mytestsudo systemctl stop mytest do nothing.
Why?
Pleas give a explanation in detail.
systemd startx start-stop-daemon
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
vim /home/mytest.sh
rm -f /home/mytest/*
I want to write a service to execute the remove action.
My expections:sudo systemctl stop mytest can delete files in /home/mytestsudo systemctl start mytest do nothing.
Edit my service file.
sudo vim /etc/systemd/system/mytest.service
[Unit]
Description=delete file
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
Enable it.
sudo systemctl enable mytest
Now i found a strange action for mytest service.
sudo systemctl start mytest can delete files in /home/mytestsudo systemctl stop mytest do nothing.
Why?
Pleas give a explanation in detail.
systemd startx start-stop-daemon
vim /home/mytest.sh
rm -f /home/mytest/*
I want to write a service to execute the remove action.
My expections:sudo systemctl stop mytest can delete files in /home/mytestsudo systemctl start mytest do nothing.
Edit my service file.
sudo vim /etc/systemd/system/mytest.service
[Unit]
Description=delete file
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
Enable it.
sudo systemctl enable mytest
Now i found a strange action for mytest service.
sudo systemctl start mytest can delete files in /home/mytestsudo systemctl stop mytest do nothing.
Why?
Pleas give a explanation in detail.
systemd startx start-stop-daemon
asked Apr 29 at 13:28
it_is_a_literature
20532249
20532249
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand whatâÂÂs going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as youâÂÂve declared it never becomes active, so its stop action will be run once its start action completes.
To achieve what youâÂÂre after, you need a oneshot service which nevertheless becomes active:
[Unit]
Description=delete file
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand whatâÂÂs going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as youâÂÂve declared it never becomes active, so its stop action will be run once its start action completes.
To achieve what youâÂÂre after, you need a oneshot service which nevertheless becomes active:
[Unit]
Description=delete file
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
add a comment |Â
up vote
2
down vote
accepted
This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand whatâÂÂs going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as youâÂÂve declared it never becomes active, so its stop action will be run once its start action completes.
To achieve what youâÂÂre after, you need a oneshot service which nevertheless becomes active:
[Unit]
Description=delete file
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand whatâÂÂs going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as youâÂÂve declared it never becomes active, so its stop action will be run once its start action completes.
To achieve what youâÂÂre after, you need a oneshot service which nevertheless becomes active:
[Unit]
Description=delete file
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand whatâÂÂs going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as youâÂÂve declared it never becomes active, so its stop action will be run once its start action completes.
To achieve what youâÂÂre after, you need a oneshot service which nevertheless becomes active:
[Unit]
Description=delete file
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/bin/bash /home/mytest.sh
[Install]
WantedBy=multi-user.target
answered Apr 29 at 13:58
Stephen Kitt
140k22302363
140k22302363
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440728%2fwhy-systemctl-stop-service-cant-envoke-the-service%23new-answer', 'question_page');
);
Post as a guest
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
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
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