centos7 使用systemd 自定义关机前脚本

systemd (centos7)

需求,关机前执行脚本


关机脚本
vi /usr/bin/shutdown_cust.sh
#!/bin/bash
echo "zhengchangguanji" >> /tmp/log.log

chmod +x /usr/bin/shutdown_cust.sh
设置关机执行

vi /lib/systemd/system/cust_shut.service
[Unit]
Description=poweroff cust
After=getty@tty1.service display-manager.service plymouth-start.service
Before=systemd-poweroff.service systemd-reboot.service systemd-halt.service
DefaultDependencies=no

[Service]
ExecStart=/usr/bin/shutdown_cust.sh
Type=forking
[Install]
WantedBy=poweroff.target
WantedBy=reboot.target
WantedBy=halt.target

软连接
ln -s /usr/lib/systemd/system/cust_shut.service /usr/lib/systemd/system/halt.target.wants/
ln -s /usr/lib/systemd/system/cust_shut.service /usr/lib/systemd/system/poweroff.target.wants/
ln -s /usr/lib/systemd/system/cust_shut.service /usr/lib/systemd/system/reboot.target.wants/

重启 查看tmp下面会不会多出来log.log 文件

posted @ 2017-01-07 15:25  不会游泳的鱼pdj  阅读(1564)  评论(0编辑  收藏  举报