免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1813 | 回复: 0
打印 上一主题 下一主题

[系统管理] stop-log 服务中的ExecStart在开机中执行了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-04-14 09:56 |只看该作者 |倒序浏览
本帖最后由 yufeiluo 于 2018-04-14 10:04 编辑

下面是一个开机自启动的脚本
  1. sudo vim  /etc/systemd/system/start-log.service
复制代码

启动这个start-log 服务。
  1. sudo systemctl enable  start-log service
复制代码

重新启动电脑后,
cat  log.info   
start   
Fri Apr 13 21:47:08 HKT 2018   

注意:没有   
stop Fri Apr 13 21xxxx HKT 2018   

这样的字样。这意味着,/home/debian9/stop.sh 没有执行,start-log服务中的ExecStop没有执行
下面,新增加一个服务,我希望这个服务在关机的时候自动运行。

  1. sudo vim  /etc/systemd/system/stop-log.service

  2. [Unit]
  3. Description=stop log
  4. Before=shutdown.target  

  5. [Service]
  6. User=root
  7. ExecStop=/bin/bash  /home/debian9/stop_shutdown.sh
  8. ExecStart=/bin/bash  /home/debian9/start_shutdown.sh
  9. RemainAfterExit=yes

  10. [Install]
  11. WantedBy=multi-user.target
  12. Content in stop_shutdown.sh and start_shutdown.sh

  13. cat /home/debian9/stop_shutdown.sh
  14. /bin/echo  "stop in shutdown" >> /home/debian9/log.info
  15. /bin/date  >> /home/debian9/log.info
  16. cat /home/debian9/start_shutdown.sh
  17. /bin/echo "start in shutdown" >>/home/debian9/log.info
  18. /bin/date  >> /home/debian9/log.info
复制代码

  1. sudo systemctl enable stop-log service
复制代码

重新启动电脑

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     
注意:   
log中有start in shutdown  ,表明  stop-log 服务中的ExecStart=/bin/bash  /home/debian9/start_shutdown.sh  在开机的时候执行了,
请问,为何会这样?



您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP