Linux服务加入systemctl|service管理
一.加入systemctl
1.添加
vim /usr/lib/systemd/system/user_timejob.service
# copy to /usr/lib/systemd/system
# systemctl enable customservice.service
[Unit]
Description=customservice Service
[Service]
Type=forking
User=root
ExecStart=/etc/init.d/customservice.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=True
[Install]
WantedBy=multi-user.target
解释:
[Unit]部分主要是对这个服务的说明,内容包括Description和After,Description 用于描述服务,After用于描述服务类别
[Service]部分是服务的关键,是服务的一些具体运行参数的设置.
Type=forking是后台运行的形式,
User=users是设置服务运行的用户,
Group=users是设置服务运行的用户组,
PIDFile为存放PID的文件路径,
ExecStart为服务的具体运行命令,
ExecReload为重启命令,
ExecStop为停止命令,
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报错!
[Install]部分是服务安装的相关设置,可设置为多用户的
2.启动
systemctl restart user_timejob
systemctl enable user_timejob
二.加入service
1.编写启动脚本,这里主要注意配置文件路径以及主程序路径,在/etc/init.d/中新建文件 nginx这个文件下的所有软件启动文件都要加755权限,否则会启动失败
vim /etc/init.d/user_timejob
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
nginxd=/usr/local/nginx/sbin/nginx
# See how we were called.
case "$1" in
start)
$nginxd
;;
stop)
$nginxd -s quit
;;
reload)
reload
;;
restart)
$nginxd -s reload
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
2.加入自启动
chkconfig --add user_timejob
Linux服务加入systemctl|service管理的更多相关文章
- Linux服务和systemctl详解
定义 A Linux service is an application (or set of applications) that runs in the background waiting to ...
- Linux服务:使用Supervisor管理进程
一.简介 由于基本每个公司都会用到supervisor这个进程管理工具,这里简单阐述一下. Supervisor (http://supervisord.org) 是一个用Python写Linux下的 ...
- Linux 服务管理两种方式service和systemctl
Linux 服务管理两种方式service和systemctl 1.service命令 service命令其实是去/etc/init.d目录下,去执行相关程序 # service命令启动redis脚本 ...
- Linux 服务管理的两种方式service和systemctl
service命令 service命令其实是去/etc/init.d目录下,去执行相关程序 ``` # service命令启动redis脚本 service redis start # 直接启动red ...
- Linux - 利用systemctl命令管理服务
systemctl命令是系统服务管理器指令,融合了service和chkconfig的功能,可以查看和设置服务. 这里以docker服务为例. 利用systemctl命令管理 显示服务状态:syste ...
- Linux学习-透过 systemctl 管理服务
透过 systemctl 管理单一服务 (service unit) 的启动/开机启动与观察状态 一般来说,服务的启动有两个阶段,一 个是『开机的时候设定要不要启动这个服务』, 以及『你现在要不要启动 ...
- 在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作
在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作. 操作说明如下: 1. 查看 sshd 服务是否启动: 看到上述信息就 ...
- Linux中用systemctl命令管理服务
systemctl start foo.service 启动服务systemctl restart foo.service 重启服务systemctl stop foo.service 停止服务sys ...
- [Linux]服务管理:rpm包, 源码包
--------------------------------------------------------------------------------------------------- ...
随机推荐
- jsonpath语法的基本使用
jsonpath的安装及使用方式: pip安装: Python3.7\Scripts> pip install jsonpath jsonpath的使用: obj = json.load(ope ...
- 用户案例 | 腾讯小视频&转码平台云原生容器化之路
作者 李汇波,腾讯业务运维高级工程师,目前就职于TEG 云架构平台部 技术运营与质量中心,现负责微信.QQ社交类业务的视频转码运维. 摘要 随着短视频兴起和快速发展,对于视频转码处理的需求也越来越多. ...
- [loj6051]PATH
(不妨将下标改为从1开始) 参考loj2265中关于杨表的相关知识 构造一个$n$行且第$i$行有$a_{i}$个格子的杨表,依次记录其每一次增加的时间(范围为$[1,\sum_{i=1}^{n}a_ ...
- [noi31]MST
定义dp[i]表示当前连通块状态为i的方案数(状态记录该状态每一个连通块的大小),那么从小到大枚举每条边,考虑这条边在不在最小生成树上: 1. 如果不在最小生成树上,那么这条边有$\sum_{i=1} ...
- Java设计模式之(九)——门面模式
1.什么是门面模式? Provide a unified interface to a set of interfaces in a subsystem.Facade defines a higher ...
- Spring扩展点-v5.3.9
Spring 扩展点 **本人博客网站 **IT小神 www.itxiaoshen.com 官网地址****:https://spring.io/projects/spring-framework T ...
- Arc123 D
Arc123 D 很好考场降智了. 感觉\(D\)比\(C\)好做多了. 考虑\(C_i = A_i - B_i\),那么有\(C_{i + 1} \leq C_i,B_i \leq B_{i + 1 ...
- CF1202E You Are Given Some Strings...
题目传送门. 题意简述:给出 \(t\) 与 \(s_{1,2,\cdots,n}\).求对于所有 \(i,j\in[1,n]\),\(s_i+s_j\) 在 \(t\) 中出现次数之和. 如果只有 ...
- mingling
mysql> USE mon Reading table information for completion of table and column names You can turn of ...
- python的包与模块
win +R d