How to run a script with systemd right before shutdown?
Clash Royale CLAN TAG#URR8PPP
up vote
47
down vote
favorite
What do I need to put in the [install]
section, so that systemd runs /home/me/so.pl
right before shutdown and also before /proc/self/net/dev
gets destroyed?
[Unit]
Description=Log Traffic
[Service]
ExecStart=/home/me/so.pl
[Install]
?
linux shutdown systemd
add a comment |Â
up vote
47
down vote
favorite
What do I need to put in the [install]
section, so that systemd runs /home/me/so.pl
right before shutdown and also before /proc/self/net/dev
gets destroyed?
[Unit]
Description=Log Traffic
[Service]
ExecStart=/home/me/so.pl
[Install]
?
linux shutdown systemd
add a comment |Â
up vote
47
down vote
favorite
up vote
47
down vote
favorite
What do I need to put in the [install]
section, so that systemd runs /home/me/so.pl
right before shutdown and also before /proc/self/net/dev
gets destroyed?
[Unit]
Description=Log Traffic
[Service]
ExecStart=/home/me/so.pl
[Install]
?
linux shutdown systemd
What do I need to put in the [install]
section, so that systemd runs /home/me/so.pl
right before shutdown and also before /proc/self/net/dev
gets destroyed?
[Unit]
Description=Log Traffic
[Service]
ExecStart=/home/me/so.pl
[Install]
?
linux shutdown systemd
linux shutdown systemd
asked May 23 '12 at 16:39
sid_com
6163818
6163818
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
53
down vote
accepted
The suggested solution is to run the service unit as a normal service - have a look at the [Install]
section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop=
.
The following solution is working for me:
[Unit]
Description=...
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=<your script/program>
[Install]
WantedBy=multi-user.target
RemainAfterExit=true
is needed when you don't have an ExecStart
action.
After creating the file, make sure to systemctl daemon-reload
and systemctl enable yourservice --now
.
I just got it from systemd IRC, credits are going to mezcalero.
6
At ubuntu 16.04 you must have aExecStart=/bin/true
.
â niels
Dec 29 '16 at 20:50
2
My assumption to WHYRemainAfterExit=true
is required when there is noExecStart
is becausesystemd
will not attempt to runExecStop
if it thinks that the service is not running.RemainAfterExit=true
causessystemd
to believe that the service is running, thereby causing it to runExecStop
at shutdown.
â Felipe Alvarez
Jun 15 '17 at 0:30
1
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
@richmb Not at all. From the docs:Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
add a comment |Â
up vote
7
down vote
As far as I can see this does what I need (but I don't know exactly why).
[Unit]
Description=Log Traffic
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
ExecStart=/usr/local/bin/perl /home/me/log_traffic.pl --stop
Type=oneshot
3
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
You may want to addkexec.target
to the Before bit
â ntzrmtthihu777
Mar 26 '16 at 11:11
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
I don't see how this will work unless you also addWantedBy=shutdown.target reboot.target halt.target
to the[Unit]
section.Before=
&After=
don't change dependencies.
â rsaw
Sep 8 '16 at 15:57
1
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
 |Â
show 2 more comments
up vote
3
down vote
I am not totally sure but i don't think you need the install part though i added it explicitly. I also didn't test it but i think it should help you get started:
[Unit]
Description=Log Traffic
Requires=network.target
After=network.target
Before=shutdown.target
DefaultDependencies=no
[Service]
ExecStart=/home/me/so.pl
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
add a comment |Â
up vote
0
down vote
To run a service right before starting any of reboot/shutdown/halt/kexec services (i.e. in the last moment before root filesystem becomes remounted read-only) use this service config:
[Unit]
Description=Save system clock on shutdown
DefaultDependencies=no
After=final.target
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh save
[Install]
WantedBy=final.target
Enable it with:
systemctl enable my_service.service
To run a script right before actual reboot/shutdown/halt/kexec (when you cannot write to the root filesystem, because it was remounted read-only) add this script executable to the /usr/lib/systemd/system-shutdown
directory.
Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.
See:
https://www.freedesktop.org/software/systemd/man/bootup.html
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html
add a comment |Â
protected by Stephen Kitt Jul 28 '17 at 9:42
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
53
down vote
accepted
The suggested solution is to run the service unit as a normal service - have a look at the [Install]
section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop=
.
The following solution is working for me:
[Unit]
Description=...
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=<your script/program>
[Install]
WantedBy=multi-user.target
RemainAfterExit=true
is needed when you don't have an ExecStart
action.
After creating the file, make sure to systemctl daemon-reload
and systemctl enable yourservice --now
.
I just got it from systemd IRC, credits are going to mezcalero.
6
At ubuntu 16.04 you must have aExecStart=/bin/true
.
â niels
Dec 29 '16 at 20:50
2
My assumption to WHYRemainAfterExit=true
is required when there is noExecStart
is becausesystemd
will not attempt to runExecStop
if it thinks that the service is not running.RemainAfterExit=true
causessystemd
to believe that the service is running, thereby causing it to runExecStop
at shutdown.
â Felipe Alvarez
Jun 15 '17 at 0:30
1
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
@richmb Not at all. From the docs:Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
add a comment |Â
up vote
53
down vote
accepted
The suggested solution is to run the service unit as a normal service - have a look at the [Install]
section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop=
.
The following solution is working for me:
[Unit]
Description=...
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=<your script/program>
[Install]
WantedBy=multi-user.target
RemainAfterExit=true
is needed when you don't have an ExecStart
action.
After creating the file, make sure to systemctl daemon-reload
and systemctl enable yourservice --now
.
I just got it from systemd IRC, credits are going to mezcalero.
6
At ubuntu 16.04 you must have aExecStart=/bin/true
.
â niels
Dec 29 '16 at 20:50
2
My assumption to WHYRemainAfterExit=true
is required when there is noExecStart
is becausesystemd
will not attempt to runExecStop
if it thinks that the service is not running.RemainAfterExit=true
causessystemd
to believe that the service is running, thereby causing it to runExecStop
at shutdown.
â Felipe Alvarez
Jun 15 '17 at 0:30
1
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
@richmb Not at all. From the docs:Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
add a comment |Â
up vote
53
down vote
accepted
up vote
53
down vote
accepted
The suggested solution is to run the service unit as a normal service - have a look at the [Install]
section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop=
.
The following solution is working for me:
[Unit]
Description=...
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=<your script/program>
[Install]
WantedBy=multi-user.target
RemainAfterExit=true
is needed when you don't have an ExecStart
action.
After creating the file, make sure to systemctl daemon-reload
and systemctl enable yourservice --now
.
I just got it from systemd IRC, credits are going to mezcalero.
The suggested solution is to run the service unit as a normal service - have a look at the [Install]
section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop=
.
The following solution is working for me:
[Unit]
Description=...
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=<your script/program>
[Install]
WantedBy=multi-user.target
RemainAfterExit=true
is needed when you don't have an ExecStart
action.
After creating the file, make sure to systemctl daemon-reload
and systemctl enable yourservice --now
.
I just got it from systemd IRC, credits are going to mezcalero.
edited Sep 8 '16 at 16:15
rsaw
753413
753413
answered Jun 27 '12 at 14:56
Matthias
54643
54643
6
At ubuntu 16.04 you must have aExecStart=/bin/true
.
â niels
Dec 29 '16 at 20:50
2
My assumption to WHYRemainAfterExit=true
is required when there is noExecStart
is becausesystemd
will not attempt to runExecStop
if it thinks that the service is not running.RemainAfterExit=true
causessystemd
to believe that the service is running, thereby causing it to runExecStop
at shutdown.
â Felipe Alvarez
Jun 15 '17 at 0:30
1
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
@richmb Not at all. From the docs:Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
add a comment |Â
6
At ubuntu 16.04 you must have aExecStart=/bin/true
.
â niels
Dec 29 '16 at 20:50
2
My assumption to WHYRemainAfterExit=true
is required when there is noExecStart
is becausesystemd
will not attempt to runExecStop
if it thinks that the service is not running.RemainAfterExit=true
causessystemd
to believe that the service is running, thereby causing it to runExecStop
at shutdown.
â Felipe Alvarez
Jun 15 '17 at 0:30
1
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
@richmb Not at all. From the docs:Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
6
6
At ubuntu 16.04 you must have a
ExecStart=/bin/true
.â niels
Dec 29 '16 at 20:50
At ubuntu 16.04 you must have a
ExecStart=/bin/true
.â niels
Dec 29 '16 at 20:50
2
2
My assumption to WHY
RemainAfterExit=true
is required when there is no ExecStart
is because systemd
will not attempt to run ExecStop
if it thinks that the service is not running. RemainAfterExit=true
causes systemd
to believe that the service is running, thereby causing it to run ExecStop
at shutdown.â Felipe Alvarez
Jun 15 '17 at 0:30
My assumption to WHY
RemainAfterExit=true
is required when there is no ExecStart
is because systemd
will not attempt to run ExecStop
if it thinks that the service is not running. RemainAfterExit=true
causes systemd
to believe that the service is running, thereby causing it to run ExecStop
at shutdown.â Felipe Alvarez
Jun 15 '17 at 0:30
1
1
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
Is there anyway to ensure this script will run and complete before user sessions and user processes are terminated?
â richmb
Oct 19 '17 at 13:19
@richmb Not at all. From the docs:
Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
@richmb Not at all. From the docs:
Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so.
â svenwltr
Nov 30 '17 at 11:19
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
I've tried this and various iterations on it but it does not work on Debian Stretch.
â 2rs2ts
Sep 21 at 1:02
add a comment |Â
up vote
7
down vote
As far as I can see this does what I need (but I don't know exactly why).
[Unit]
Description=Log Traffic
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
ExecStart=/usr/local/bin/perl /home/me/log_traffic.pl --stop
Type=oneshot
3
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
You may want to addkexec.target
to the Before bit
â ntzrmtthihu777
Mar 26 '16 at 11:11
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
I don't see how this will work unless you also addWantedBy=shutdown.target reboot.target halt.target
to the[Unit]
section.Before=
&After=
don't change dependencies.
â rsaw
Sep 8 '16 at 15:57
1
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
 |Â
show 2 more comments
up vote
7
down vote
As far as I can see this does what I need (but I don't know exactly why).
[Unit]
Description=Log Traffic
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
ExecStart=/usr/local/bin/perl /home/me/log_traffic.pl --stop
Type=oneshot
3
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
You may want to addkexec.target
to the Before bit
â ntzrmtthihu777
Mar 26 '16 at 11:11
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
I don't see how this will work unless you also addWantedBy=shutdown.target reboot.target halt.target
to the[Unit]
section.Before=
&After=
don't change dependencies.
â rsaw
Sep 8 '16 at 15:57
1
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
 |Â
show 2 more comments
up vote
7
down vote
up vote
7
down vote
As far as I can see this does what I need (but I don't know exactly why).
[Unit]
Description=Log Traffic
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
ExecStart=/usr/local/bin/perl /home/me/log_traffic.pl --stop
Type=oneshot
As far as I can see this does what I need (but I don't know exactly why).
[Unit]
Description=Log Traffic
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
ExecStart=/usr/local/bin/perl /home/me/log_traffic.pl --stop
Type=oneshot
edited Jun 25 '15 at 13:35
Tshepang
25.2k71182262
25.2k71182262
answered May 29 '12 at 13:57
sid_com
6163818
6163818
3
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
You may want to addkexec.target
to the Before bit
â ntzrmtthihu777
Mar 26 '16 at 11:11
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
I don't see how this will work unless you also addWantedBy=shutdown.target reboot.target halt.target
to the[Unit]
section.Before=
&After=
don't change dependencies.
â rsaw
Sep 8 '16 at 15:57
1
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
 |Â
show 2 more comments
3
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
You may want to addkexec.target
to the Before bit
â ntzrmtthihu777
Mar 26 '16 at 11:11
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
I don't see how this will work unless you also addWantedBy=shutdown.target reboot.target halt.target
to the[Unit]
section.Before=
&After=
don't change dependencies.
â rsaw
Sep 8 '16 at 15:57
1
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
3
3
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
It happens to work because of 2 things: 1) DefaultDependencies=no makes it ignores all dependencies and run "at first" on start and "at last" on stop, always respecting "Before" and "After" clauses. 2) It happens to have a Before clause on shutdown/reboot/halt targets, so it will run just before shutdown/reboot/halt is reached on stop (because they only run on stop it happens to do what you want).
â RDP
Jan 29 '16 at 1:01
You may want to add
kexec.target
to the Before bitâ ntzrmtthihu777
Mar 26 '16 at 11:11
You may want to add
kexec.target
to the Before bitâ ntzrmtthihu777
Mar 26 '16 at 11:11
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
This doesn't work for me
â Bug Killer
Sep 7 '16 at 1:50
I don't see how this will work unless you also add
WantedBy=shutdown.target reboot.target halt.target
to the [Unit]
section. Before=
& After=
don't change dependencies.â rsaw
Sep 8 '16 at 15:57
I don't see how this will work unless you also add
WantedBy=shutdown.target reboot.target halt.target
to the [Unit]
section. Before=
& After=
don't change dependencies.â rsaw
Sep 8 '16 at 15:57
1
1
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
@FelipeAlvarez: I have removed my comment.
â sid_com
Jun 22 at 4:07
 |Â
show 2 more comments
up vote
3
down vote
I am not totally sure but i don't think you need the install part though i added it explicitly. I also didn't test it but i think it should help you get started:
[Unit]
Description=Log Traffic
Requires=network.target
After=network.target
Before=shutdown.target
DefaultDependencies=no
[Service]
ExecStart=/home/me/so.pl
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
add a comment |Â
up vote
3
down vote
I am not totally sure but i don't think you need the install part though i added it explicitly. I also didn't test it but i think it should help you get started:
[Unit]
Description=Log Traffic
Requires=network.target
After=network.target
Before=shutdown.target
DefaultDependencies=no
[Service]
ExecStart=/home/me/so.pl
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
add a comment |Â
up vote
3
down vote
up vote
3
down vote
I am not totally sure but i don't think you need the install part though i added it explicitly. I also didn't test it but i think it should help you get started:
[Unit]
Description=Log Traffic
Requires=network.target
After=network.target
Before=shutdown.target
DefaultDependencies=no
[Service]
ExecStart=/home/me/so.pl
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
I am not totally sure but i don't think you need the install part though i added it explicitly. I also didn't test it but i think it should help you get started:
[Unit]
Description=Log Traffic
Requires=network.target
After=network.target
Before=shutdown.target
DefaultDependencies=no
[Service]
ExecStart=/home/me/so.pl
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
edited May 24 '12 at 11:57
answered May 24 '12 at 4:42
Ulrich Dangel
20.1k25671
20.1k25671
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
add a comment |Â
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
When I try this the script gets executed soon after the start (boot).
â sid_com
May 24 '12 at 8:05
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
@sid_com After reading thread.gmane.org/gmane.comp.sysutils.systemd.devel/4515/⦠try to add DefaultDependencies=no and maybe remove the install section. Otherwise it may help to remote the after/requires lines.
â Ulrich Dangel
May 24 '12 at 11:56
add a comment |Â
up vote
0
down vote
To run a service right before starting any of reboot/shutdown/halt/kexec services (i.e. in the last moment before root filesystem becomes remounted read-only) use this service config:
[Unit]
Description=Save system clock on shutdown
DefaultDependencies=no
After=final.target
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh save
[Install]
WantedBy=final.target
Enable it with:
systemctl enable my_service.service
To run a script right before actual reboot/shutdown/halt/kexec (when you cannot write to the root filesystem, because it was remounted read-only) add this script executable to the /usr/lib/systemd/system-shutdown
directory.
Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.
See:
https://www.freedesktop.org/software/systemd/man/bootup.html
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html
add a comment |Â
up vote
0
down vote
To run a service right before starting any of reboot/shutdown/halt/kexec services (i.e. in the last moment before root filesystem becomes remounted read-only) use this service config:
[Unit]
Description=Save system clock on shutdown
DefaultDependencies=no
After=final.target
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh save
[Install]
WantedBy=final.target
Enable it with:
systemctl enable my_service.service
To run a script right before actual reboot/shutdown/halt/kexec (when you cannot write to the root filesystem, because it was remounted read-only) add this script executable to the /usr/lib/systemd/system-shutdown
directory.
Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.
See:
https://www.freedesktop.org/software/systemd/man/bootup.html
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To run a service right before starting any of reboot/shutdown/halt/kexec services (i.e. in the last moment before root filesystem becomes remounted read-only) use this service config:
[Unit]
Description=Save system clock on shutdown
DefaultDependencies=no
After=final.target
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh save
[Install]
WantedBy=final.target
Enable it with:
systemctl enable my_service.service
To run a script right before actual reboot/shutdown/halt/kexec (when you cannot write to the root filesystem, because it was remounted read-only) add this script executable to the /usr/lib/systemd/system-shutdown
directory.
Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.
See:
https://www.freedesktop.org/software/systemd/man/bootup.html
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html
To run a service right before starting any of reboot/shutdown/halt/kexec services (i.e. in the last moment before root filesystem becomes remounted read-only) use this service config:
[Unit]
Description=Save system clock on shutdown
DefaultDependencies=no
After=final.target
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/fake-hwclock.sh save
[Install]
WantedBy=final.target
Enable it with:
systemctl enable my_service.service
To run a script right before actual reboot/shutdown/halt/kexec (when you cannot write to the root filesystem, because it was remounted read-only) add this script executable to the /usr/lib/systemd/system-shutdown
directory.
Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.
See:
https://www.freedesktop.org/software/systemd/man/bootup.html
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html
answered 3 mins ago
Piotr Jurkiewicz
688512
688512
add a comment |Â
add a comment |Â
protected by Stephen Kitt Jul 28 '17 at 9:42
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?