惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
U
Unit 42
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
B
Blog RSS Feed
Vercel News
Vercel News
F
Fortinet All Blogs
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Jina AI
Jina AI
小众软件
小众软件
T
Threatpost
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
B
Blog
腾讯CDC
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
S
Schneier on Security
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
G
Google Developers Blog
T
Tor Project blog
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
罗磊的独立博客

博客园 - 番茄的梦想

Debian防火墙的ufw的使用 Linux—nvm教程 LNMP一键安装包安装的mysql远程连接不上的问题 linux if命令 微软sdk及运行时下载地址 解决python错误 UnicodeDecodeError: 'gb2312' codec can't decode byte 0x8b in position 1: illegal multibyt pip相关介绍 结构(位置)伪类选择器 如何清除mstsc记录 ubuntu开启远程桌面功能 使用Windows远程桌面工具来远程连接控制Ubuntu系统 缓存头Cache-Control的含义和使用 正则表达式 以A开头B结尾 取中间的内容 nginx 不带www的域名跳转www域名 IIS配置导入导出 CSS中hover选择器的使用详解 html 锚点三种实现方法 重置自增长id 如何解决Visual Studio2012 与此版本的Windows不兼容
linux service文件格式
番茄的梦想 · 2023-11-13 · via 博客园 - 番茄的梦想

systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之
分,需要开机不登陆就能运行的程序,存在系统服务里,即:/usr/lib/systemd/system目录下.
每一个服务以.service结尾,一般会分为3部分:[Unit]、[Service]和[Install]

[Unit]
部分主要是对这个服务的说明,内容包括Description和After,Description 用于描述服务,
After用于描述服务类别

Description=test # 简单描述服务
After=network.target # 描述服务类别,表示本服务需要在network服务启动后在启动
Before=xxx.service # 表示需要在某些服务启动之前启动,After和Before字段只涉及启动顺序,不涉及依赖关系。
[Service]部分是服务的关键,是服务的一些具体运行参数的设置.

Type=forking # 表示后台运行模式。
User=user # 设置服务运行的用户
Group=user # 设置服务运行的用户组
KillMode=control-group # 定义systemd如何停止服务
PIDFile=/usr/local/test/test.pid # 存放PID的绝对路径
Restart=no # 定义服务进程退出后,systemd的重启方式,默认是不重启
ExecStart=/usr/local/test/bin/startup.sh # 服务启动命令,命令需要绝对路径
ExecReload #为重启命令
ExecStop #为停止命令,
PrivateTmp=true # 表示给服务分配独立的临时空间
[Service]
注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报
错!

[Install]
[Install]部分是服务安装的相关设置,可设置为多用户的
首先,使用systemctl start [ 服务名(也是文件名) ] 可测试服务是否可以成功运行,如果不能运行 则可以使用systemctl status [ 服务名(也是文件名) ]查看错误信息和其他服务信息,然后根据报
错进行修改,直到可以start,如果不放心还可以测试restart和stop命令。
接着,只要使用systemctl enable xxxxx就可以将所编写的服务添加至开机启动即可。