CentOS7 添加自定义系统服务案例
示例一:
执行脚本/root/project/systemctl/test.sh()
#########################################################################
# File Name : test.sh
# Author : Youner Liu
# Mail : younger_liucn@126.com
# Created Time: Wed 14 Sep 2016 07:13:37 PM CST
# Description :
#########################################################################
#!/bin/bash
function test()
{
count=0
num=3000
while [ ${count} -lt ${num} ]
do
if [ -f /root/project/systemctl/stop ]; then
break
fi
count=$((count+1))
date >> /root/project/systemctl/test.log
echo "hello world ${count}" >> /root/project/systemctl/test.log
sleep 1
done
}
if [ ${1} == "start" ]; then
test;
elif [ ${1} == "stop" ];then
echo "touch /root/project/systemctl/stop"
touch /root/project/systemctl/stop
fi
myservice.service源码(/usr/lib/systemd/system/myservice.service)
[Unit] Description=my service [Service] Type=forking PIDFile=/root/project/systemctl/myservice.pid ExecStart=/usr/bin/sh /root/project/systemctl/test.sh start & ExecStop=/usr/bin/sh /root/project/systemctl/test.sh stop PrivateTmp=true [Install] WantedBy=multi-user.target
测试:
[root@node0 systemctl]# systemctl start myservice.service Job for myservice.service failed because a timeout was exceeded. See "systemctl status myservice.service" and "journalctl -xe" for details. [root@node0 systemctl]# systemctl status myservice.service ● myservice.service - nginx - my service Loaded: loaded (/usr/lib/systemd/system/myservice.service; disabled; vendor preset: disabled) Active: failed (Result: timeout) since Wed 2016-09-14 21:40:46 CST; 44s ago Process: 7459 ExecStart=/usr/bin/sh /root/project/systemctl/test.sh start & (code=killed, signal=TERM) Sep 14 21:39:16 node0 systemd[1]: Starting nginx - my service... Sep 14 21:40:46 node0 systemd[1]: myservice.service start operation timed out. Terminating. Sep 14 21:40:46 node0 systemd[1]: Failed to start nginx - my service. Sep 14 21:40:46 node0 systemd[1]: Unit myservice.service entered failed state. Sep 14 21:40:46 node0 systemd[1]: myservice.service failed. [root@node0 systemctl]# cat /root/project/systemctl/test.log Wed Sep 14 21:39:16 CST 2016 hello world 1 .... Wed Sep 14 21:40:45 CST 2016 hello world 89 Wed Sep 14 21:40:46 CST 2016 hello world 90 [root@node0 systemctl]#
systemctl start myservice.service卡住90秒;然后报出timeout
这个问题应该如何解决那????
整改
脚本/root/project/systemctl/test_start.sh
#########################################################################
# File Name : test_start.sh
# Author : Youner Liu
# Mail : younger_liucn@126.com
# Created Time: Wed 14 Sep 2016 07:13:37 PM CST
# Description :
#########################################################################
#!/bin/bash
function test()
{
count=0
num=3000
echo > /root/project/systemctl/test.log
while [ ${count} -lt ${num} ]
do
if [ -f /root/project/systemctl/stop ]; then
rm -rf /root/project/systemctl/stop;
break
fi
count=$((count+1))
date >> /root/project/systemctl/test.log
echo "hello world ${count}" >> /root/project/systemctl/test.log
sleep 1
done
}
test
脚本/root/project/systemctl/test_stop.sh
######################################################################### # File Name : test_stop.sh # Author : Youner Liu # Mail : younger_liucn@126.com # Created Time: Wed 14 Sep 2016 07:13:37 PM CST # Description : ######################################################################### #!/bin/bash echo "touch /root/project/systemctl/stop" touch /root/project/systemctl/stop
脚本/root/project/systemctl/test.sh
#########################################################################
# File Name : test.sh
# Author : Youner Liu
# Mail : younger_liucn@126.com
# Created Time: Wed 14 Sep 2016 07:13:37 PM CST
# Description :
#########################################################################
#!/bin/bash
if [ ${1} == "start" ]; then
sh /root/project/systemctl/test_start.sh &
elif [ ${1} == "stop" ];then
sh /root/project/systemctl/test_start.sh &
fi
myservice.service源码(/usr/lib/systemd/system/myservice.service)
[Unit] Description=my service [Service] Type=forking #PIDFile=/root/project/systemctl/myservice.pid ExecStart=/usr/bin/sh /root/project/systemctl/test.sh start ExecStop=/usr/bin/sh /root/project/systemctl/test.sh stop PrivateTmp=true [Install] WantedBy=multi-user.target
OK
CentOS7 添加自定义系统服务案例的更多相关文章
- CentOS7利用systemctl添加自定义系统服务【转】
systemctl enable name.service 设置开机启 systemctl disable name.service 删除开机启动指令 systemctl list-units --t ...
- [转]CentOS7利用systemctl添加自定义系统服务
原文:https://www.cnblogs.com/saneri/p/7778756.html CentOS7自定义系统服务 CentOS7的服务systemctl脚本存放在:/usr/lib/sy ...
- CentOS7添加自定义脚本服务
一.CentOS7添加自定义脚本服务说明 在CentOS7下,已经不再使用chkconfig命令管理系统开机自启动服务和条件自定义脚本服务了,而是使用管理unit的方式来控制开机自启动服务和添加自定义 ...
- [实践] Android5.1.1源码 - 在Framework中添加自定义系统服务
前言 本文的方法要修改Android源码.但只要将系统服务写出来,也可以注入system_server进程将系统服务加载到system_server中. 步骤 1. 添加一个aidl文件,我将aidl ...
- Centos7 安装系统服务、开机自启动
Centos7 安装系统服务 1 编写可执行程序 * 这里可以是任意编程语言(C.C++.Java.PHP.Python.Perl ...)编写的程序: 当前假设此程序的执行目录为: /myservi ...
- 在CentOS 7上利用systemctl添加自定义系统服务 /usr/lib/systemd/
在CentOS 7上利用systemctl添加自定义系统服务[日期:2014-07-21] 来源:blog.csdn.net/yuanguozhengjust 作者:yuanguozhengjust ...
- systemctl添加自定义系统服务
[Service] Type=forking ExecStart=绝对路径 ExecStop=绝对路径 ExecReload=绝对路径 以上最精简版,文件/usr/lib/systemd/system ...
- CentOS7 利用systemctl添加自定义系统服务
一.命令systemctl介绍 CentOS 7.0中已经没有service命令,而是启用了systemctl服务器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 命 ...
- CentOS7利用systemctl添加自定义系统服务
CentOS7的每一个服务以.service结尾,一般会分为3部分:[Unit].[Service]和[Install] 转载于互联网 [Unit] 部分主要是对这个服务的说明,内容包括Descrip ...
随机推荐
- vue 单页应用中微信支付的坑
vue 单页应用中微信支付的坑 标签(空格分隔): 微信 支付 坑 vue 场景 在微信H5页面(使用 vue-router2 控制路由的 vue2 单页应用项目)中使用微信 jssdk 进行微信支付 ...
- 如何在SAP CRM WebClient UI里创建HANA Live Report
1. 使用业务角色ANALYTICSPRO登录WebClient UI: 2. 点击新建按钮: 为新建的报表分配一个HANA Live Query: 指定Query的参数: 上图WebClient U ...
- Vim中 ctags 跳转直接跳到第一个匹配行的问题
意图 用ctags搜索代码时, 用 ctrl + ] 后,只有一个匹配项直接跳转,有多个则列出所有匹配项选择跳转 问题 在 vim 中使用 ctags 是一个很令人舒服的事情,但有时一些默认的配置和不 ...
- pthread 的几个结构体
http://blog.csdn.net/yangzhongxuan/article/details/7397139 /* Copyright (C) 2002,2003,2004,2005,2006 ...
- react中性能优化的点
react提升代码性能的点 1.绑定如果改变作用域点话放在constructor里面做,这样可以保证整个程序的作用域绑定操作只会执行一次,而且避免子组件的无谓渲染. 2.内置的setState是个异步 ...
- Netbackup客户端安装网络放通端口需求,及测试网络放通方法
192.168.1.101网络放通需求如下: 客户端主机 192.168.1.101 到 服务端主机 192.168.1.100 的1556.13720.13724.1378.13782这5个 ...
- App版本号定义与说明基础知识
版本控制比较普遍的三种命名格式 GNU 风格的版本号命名格式 主版本号 . 次版本号 [. 修正版本号 [. 编译版本号 ]] 示例 : 1.2.1, 2.0, 5.0.0 build-13124 W ...
- com.microsoft.sqlserver.jdbc.SQLServerException: Socket closed 或者 该连接已关闭
com.microsoft.sqlserver.jdbc.SQLServerException: Socket closed 或者 该连接已关闭 解决方案: DBUtil公共方法如下: package ...
- 【洛谷P1196】[NOI2002]银河英雄传说
银河英雄传说 题目链接 并查集时记录下以i为首的队列的长度(如果存在这个队列)num[i],便于合并, 和点i到队首的距离front[i],便于查询(在find时维护) #include<ios ...
- 前端路由原理及vue-router介绍
前端路由原理本质就是监听 URL 的变化,然后匹配路由规则,显示相应的页面,并且无须刷新.目前单页面使用的路由就只有两种实现方式 hash history www.test.com/##/ 就是 Ha ...