Topic 9

Dates: 4/3/2019
Start-up and Run Levels. Scheduled jobs (at, cron)
Linux System Administration


Adding stop script to the unit

In directory /home/hostadm, create another shell script file, stop.sh:

#!/bin/bash
echo STOP >> /home/hostadm/timecheck.txt

Make the script executable

chmod 755  /home/hostadm/stop.sh

In directory /lib/systemd/system, modify the unit service file, test.service by adding two lines in the [Service] block:

[Unit]
Description=test startup

[Service]
Type=simple
ExecStart=/home/hostadm/test.sh
RemainAfterExit=true
ExecStop=/home/hostadm/stop.sh 

[Install]
WantedBy=default.target

Reload systemd:

systemctl daemon-reload

Run commands

systemctl stop test
systemctl status test
Check if file /home/hostadm/timecheck.txt has been updated with entry "STOP", generated by the stop.sh script.



Take me to the Course Website