centos7 使用systemd 自定义关机前脚本
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 自定义关机前脚本的更多相关文章
- centos7上systemd详解
		
centos7上systemd详解 发表于 2016-06-07 | 分类于 linux CentOS 7继承了RHEL 7的新的特性,例如强大的systemd, 而systemd的使用也使得以往 ...
 - centos7的systemd
		
系统启动流程 POST --> Boot Sequence --> Bootloader --> kernel+initramfs(initrd) --> rootfs --& ...
 - centos7的systemd命令对比
		
centos7的systemd命令对比 http://www.linuxidc.com/Linux/2014-09/106490p2.htmhttp://www.linuxidc.com/Linux/ ...
 - [转贴]systemd 编写服务管理脚本
		
[转贴]sparkdev大神的博客, 关于 systemd的配置文件的 介绍, 自己之前二进制安装 k8s 时 超过一个 service文件 但是当时不明不白的. 现在再学习一下大神的文章 的确牛B ...
 - Android自定义View前传-View的三大流程-Measure
		
Android自定义View前传-View的三大流程-Measure 参考 <Android开发艺术探索> https://developer.android.google.cn/refe ...
 - android 自定义view 前的基础知识
		
本篇文章是自己自学自定义view前的准备,具体参考资料来自 Android LayoutInflater原理分析,带你一步步深入了解View(一) Android视图绘制流程完全解析,带你一步步深入了 ...
 - 自定义nagios监控脚本---磁盘检测
		
自定义nagios监控脚本---磁盘检测 1. 在客户端上创建脚本/usr/local/nagios/libexec/check_disk.shvim /usr/local/nagios/libexe ...
 - Centos7 自定义systemctl服务脚本
		
序言篇: 之前工作环境一直使用Centos6版本,脚本一直在使用/etc/init.d/xxx:系统升级到Cento7后,虽然之前的启动脚本也可以使用,但一直没有使用systemctl 的自定义脚本. ...
 - Linux学习笔记之Centos7 自定义systemctl服务脚本
		
0x00 概述 之前工作环境一直使用Centos6版本,脚本一直在使用/etc/init.d/xxx:系统升级到Cento7后,虽然之前的启动脚本也可以使用,但一直没有使用systemctl 的自定义 ...
 
随机推荐
- Gerrit管理帐号
			
文档 Gerrit服务器启动后,网站上有一个Documentation链接.点击后会看到四个选项: index,searching,uploading和access control 文档内容很多,不必 ...
 - haproxy 实现多域名证书https
			
[root@ha02 keys]# openssl genrsa - Generating RSA bit long modulus ....+++ ......................... ...
 - 【Java EE 学习 17 下】【数据库导出到Excel】【多条件查询方法】
			
一.导出到Excel 1.使用DatabaseMetaData分析数据库的数据结构和相关信息. (1)测试得到所有数据库名: private static DataSource ds=DataSour ...
 - jsf初学解决faces 中文输入乱码问题
			
中文乱码,貌似在java里很常见,请看简单代码: 很简单的faces <div class="td-block"> <h:outputLabel class=&q ...
 - [译]:Orchard入门——给网站添加页面
			
原文链接:Adding Pages to Your Site 注:内容为官方文档翻译,本人遇到的page中间是布局,而非官网的body--但此内容可以在内容定义里自行修改(本文不做介绍) 在创建Orc ...
 - 如何快速地从mongo中提取数据到numpy以及pandas中去
			
mongo数据通常过于庞大,很难一下子放进内存里进行分析,如果直接在python里使用字典来存贮每一个文档,使用list来存储数据的话,将很快是内存沾满.型号拥有numpy和pandas import ...
 - Dubbo详细介绍与安装使用过程
			
今天看到一篇不错的dubbo介绍教程,原文链接:http://blog.csdn.net/xlgen157387/article/details/51865289 1 Dubbo介绍 1.1 dubb ...
 - js实现去重字符串
			
实现去重字符串主要是把重复的字符与原来的字符(先push()进入一个数组存起来)相匹配,如果match返回的不是null则说明重复,就删除掉: <script> var str = pro ...
 - 求两条线段交点zz
			
"求线段交点"是一种非常基础的几何计算, 在很多游戏中都会被使用到. 下面我就现学现卖的把最近才学会的一些"求线段交点"的算法说一说, 希望对大家有所帮助. 本 ...
 - 51nod p1201 整数划分
			
1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2, ...