首页 > 其他 > 详细

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

时间:2017-01-07 16:36:41      阅读:2965      评论:0      收藏:0      [点我收藏+]

systemd (centos7)

需求,关机前执行脚本


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

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

[root@localhost ~]# vi /usr/lib/systemd/system/cust_power.service
[Unit]
Description=poweroff cust
After=getty@tty1.service display-manager.service plymouth-start.service
Before=systemd-poweroff.service
DefaultDependencies=no

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

[root@localhost ~]# vi /usr/lib/systemd/system/cust_reboot.service
[Unit]
Description=reboot cust
After=getty@tty1.service display-manager.service plymouth-start.service
Before=systemd-reboot.service
DefaultDependencies=no

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

[root@localhost ~]# vi /usr/lib/systemd/system/cust_halt.service
[Unit]
Description=halt cust
After=getty@tty1.service display-manager.service plymouth-start.service
Before=systemd-halt.service
DefaultDependencies=no

[Service]
ExecStart=/usr/sbin/shutdown_cust.sh
Type=forking

[Install]
WantedBy=halt.target

软连接
ln -s /usr/lib/systemd/system/cust_halt.service /usr/lib/systemd/system/halt.target.wants/
ln -s /usr/lib/systemd/system/cust_power.service /usr/lib/systemd/system/power.target.wants/
ln -s /usr/lib/systemd/system/cust_reboot.service /usr/lib/systemd/system/reboot.target.wants/

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

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

原文:http://www.cnblogs.com/pdjun/p/6259504.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!