Why the stop-log service run both at start and shutdown?
sudo vim /etc/systemd/system/start-log.service
[Unit]
Description=start log
[Service]
User=root
ExecStart=/bin/bash /home/debian9/start.sh
ExecStop=/bin/bash /home/debian9/stop.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
cat /home/debian9/start.sh
/bin/echo "start" >> /home/debian9/log.info
/bin/date >> /home/debian9/log.info
cat /home/debian9/stop.sh
/bin/echo "stop" >> /home/debian9/log.info
/bin/date >> /home/debian9/log.info
Enable start-log service and reboot pc.
cat log.info
start
Fri Apr 13 21:47:08 HKT 2018
Notice that no info such as stop Fri Apr 13 21:xxxxx HKT 2018
in log.info.
It means that ExecStop=/bin/bash /home/debian9/stop.sh
in start-log service can't execute at start time.
Now add a stop-log service ,i want to record some info automatically at my pc's shutdown time.
sudo vim /etc/systemd/system/stop-log.service
[Unit]
Description=stop log
Before=shutdown.target
[Service]
User=root
ExecStop=/bin/bash /home/debian9/stop_shutdown.sh
ExecStart=/bin/bash /home/debian9/start_shutdown.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Content in stopshutdown.sh and startshutdown.sh
cat /home/debian9/stop_shutdown.sh
/bin/echo "stop in shutdown" >> /home/debian9/log.info
/bin/date >> /home/debian9/log.info
cat /home/debian9/start_shutdown.sh
/bin/echo "start in shutdown" >>/home/debian9/log.info
/bin/date >> /home/debian9/log.info
Enable stop-log service and reboot pc.
cat log.info
stop in shutdown
Fri Apr 13 21:58:21 HKT 2018
start
start in shutdown
Fri Apr 13 22:00:20 HKT 2018
Fri Apr 13 22:00:20 HKT 2018
start in shutdown
appear in log.info ,it means that ExecStart=/bin/bash /home/debian9/start_shutdown.sh
in stop-log service executed ; and the time is the same as start (in start-log service),it means that ExecStart=/bin/bash /home/debian9/start_shutdown.sh
in stop-log service executed at pc'start time .
Why ExecStart in stop-log service run at the my pc's start time?