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 自定义关机前脚本的更多相关文章

  1. centos7上systemd详解

    centos7上systemd详解  发表于 2016-06-07 |  分类于 linux CentOS 7继承了RHEL 7的新的特性,例如强大的systemd, 而systemd的使用也使得以往 ...

  2. centos7的systemd

    系统启动流程 POST --> Boot Sequence --> Bootloader --> kernel+initramfs(initrd) --> rootfs --& ...

  3. centos7的systemd命令对比

    centos7的systemd命令对比 http://www.linuxidc.com/Linux/2014-09/106490p2.htmhttp://www.linuxidc.com/Linux/ ...

  4. [转贴]systemd 编写服务管理脚本

    [转贴]sparkdev大神的博客, 关于 systemd的配置文件的 介绍, 自己之前二进制安装 k8s 时 超过一个 service文件 但是当时不明不白的. 现在再学习一下大神的文章 的确牛B ...

  5. Android自定义View前传-View的三大流程-Measure

    Android自定义View前传-View的三大流程-Measure 参考 <Android开发艺术探索> https://developer.android.google.cn/refe ...

  6. android 自定义view 前的基础知识

    本篇文章是自己自学自定义view前的准备,具体参考资料来自 Android LayoutInflater原理分析,带你一步步深入了解View(一) Android视图绘制流程完全解析,带你一步步深入了 ...

  7. 自定义nagios监控脚本---磁盘检测

    自定义nagios监控脚本---磁盘检测 1. 在客户端上创建脚本/usr/local/nagios/libexec/check_disk.shvim /usr/local/nagios/libexe ...

  8. Centos7 自定义systemctl服务脚本

    序言篇: 之前工作环境一直使用Centos6版本,脚本一直在使用/etc/init.d/xxx:系统升级到Cento7后,虽然之前的启动脚本也可以使用,但一直没有使用systemctl 的自定义脚本. ...

  9. Linux学习笔记之Centos7 自定义systemctl服务脚本

    0x00 概述 之前工作环境一直使用Centos6版本,脚本一直在使用/etc/init.d/xxx:系统升级到Cento7后,虽然之前的启动脚本也可以使用,但一直没有使用systemctl 的自定义 ...

随机推荐

  1. iOS之initialize与load

    initialize和load 这两个方法都是是什么时候调用的呢?都有着什么样的作用,下面看看吧! initialize +(void)initialize{ } 什么时候调用:当第一次使用这个类的时 ...

  2. python中文字符乱码(GB2312,GBK,GB18030相关的问题)

    转自博主 crifan http://againinput4.blog.163.com/blog/static/1727994912011111011432810/ 在玩wordpress的一个博客搬 ...

  3. [转载]config文件的一个很好的实现

    以下是转载于网上的一个很好的config文件的实现,留存以备案 //Config.h #pragma once #include <string> #include <map> ...

  4. 2015ACM/ICPC亚洲区长春站

    5532 Almost Sorted Array 题目大意:给你一个序列,如果它拿掉其中一个数后,可以是该序列成为非递减或非递增序列,则输出YES. 有两种思路,第一种代码比较简单,是LIS,复杂度n ...

  5. 清华学堂 LightHouse

    灯塔(LightHouse) Description As shown in the following figure, If another lighthouse is in gray area, ...

  6. 【原】iOS学习之UIApplication及其代理

    1. 什么是UIApplication UIApplication 对象是应用程序的象征,不能手动创建,不能 alloc init,一个应用程序只允许 一个 . 每个应用都有自己的 UIApplica ...

  7. Leetcode Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  8. [Java] 位运算

    https://ckjoker.github.io/2015/03/01/Java-bit-primary/

  9. js 类型转换学习

    类型转换分为显示转换和隐式转换 参考http://www.cnblogs.com/mizzle/archive/2011/08/12/2135885.html 先事件显示的 通过手动进行类型转换,Ja ...

  10. 【BZOJ】3495: PA2010 Riddle

    题意 \(n(1 \le n \le 1000000)\)个城市,\(k(1 \le k \le n)\)个国家,\(m(1 \le m \le 1000000)\)条边.要求每个国家有且仅有一个首都 ...