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包, 源码包
--------------------------------------------------------------------------------------------------- ...
随机推荐
- 「期末」一文带你系统回顾C 语言
超详细 c 语言回顾 前言 c 语言是一种底层语言,是一种系统底层级的语言,例如Windows.Linux.Unix等操作系统就是使用c语言编写的.所以由此看来,不论是火爆了25年的Java,还是近年 ...
- [hdu5901]Count primes
最简单的是利用Min25筛求$h(n)$的过程,即 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define N 1000005 ...
- idea增加jvm内存
-server -XX:PermSize=256M -XX:MaxPermSize=1024m
- 常用的分布式ID生成器
为何需要分布式ID生成器 **本人博客网站 **IT小神 www.itxiaoshen.com **拿我们系统常用Mysql数据库来说,在之前的单体架构基本是单库结构,每个业务表的ID一般从1增,通过 ...
- C#.NET 操作Windows服务(安装、卸载)
注意点: 1.安装时要请求到管理员权限. 2.卸载前,一定要停止掉Windows服务,否则需要重启或注销电脑.代码无法停止服务时,使用services.msc来停止. 开始: 1.新建一个名为&quo ...
- CODE FESTIVAL 2017 qual C F - Three Gluttons(DP)
洛谷题面传送门 & Atcoder 题面传送门 DP 好题. 首先考虑如果我们知道 C 吃了哪些寿司,能够还原出多少种符合条件的序列.我们考虑倒着钦定,即,先钦定 A,B,C 三者最后吃的那三 ...
- CF932F Escape Through Leaf
CF932F Escape Through Leaf 首先, $ O(n^2) $ dp 是很显然的,方程长这样: \[dp[u] = min\{dp[v] + a_u\times b_v\} \] ...
- Atcoder Grand Contest 002 F - Leftmost Ball(dp)
Atcoder 题面传送门 & 洛谷题面传送门 这道 Cu 的 AGC F 竟然被我自己想出来了!!!((( 首先考虑什么样的序列会被统计入答案.稍微手玩几组数据即可发现,一个颜色序列 \(c ...
- [转载]CSP-J/S 第一轮知识点选讲
CSP-J/S 第一轮知识点选讲 转载自这里 感谢原博主的大力整理! 信息学史及基本知识 一.信息学及计算机史 计算机的顶级奖项:图灵奖.冯·诺依曼奖 图灵奖:由ACM(美国计算机协会)设立于1966 ...
- linux中的颜色
echo -e "\033[30m 黑色字 \033[0m" echo -e "\033[31m 红色字 \033[0m" echo -e "\033 ...