systemd_service/README.md

105 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2024-05-10 15:11:25 +08:00
# systemd_service
2024-05-10 23:49:00 +08:00
Systemd 的 service 文件示例
2024-05-10 15:11:25 +08:00
2024-05-10 23:49:00 +08:00
<br/>
## 文件说明
### 仓库文件
#### 说明文件
``` bash
description/description.service
```
#### 示例文件
- docker
``` bash
examples/docker.service
```
- redis
``` bash
examples/redis.service
```
- tomcat
``` bash
examples/tomcat.service
```
- nginx
``` bash
examples/nginx.service
```
2024-05-10 23:49:00 +08:00
### 安装目录
``` bash
/usr/lib/systemd/system/
```
``` bash
/etc/systemd/system/
```
> 其中 /etc/systemd/system/ 目录中的 service 文件在开机时自执行
<br/>
## 命令示例
- 重载配置文件
``` bash
systemctl daemon-reload
```
- 查看服务状态
``` bash
systemctl status [service 文件名称]
```
示例:
``` bash
systemctl status docker.service
```
- 启动服务
``` bash
systemctl start [service 文件名称]
```
示例:
``` bash
systemctl start docker.service
```
- 停止服务
``` bash
systemctl stop [service 文件名称]
```
示例:
``` bash
systemctl stop docker.service
```
- 重启服务
``` bash
systemctl restart [service 文件名称]
```
示例:
``` bash
systemctl restart docker.service
```
- 开启开机自启动
``` bash
systemctl enable [service 文件名称]
```
示例:
``` bash
systemctl enable docker.service
```
- 取消开机自启动
``` bash
systemctl disable [service 文件名称]
```
示例:
``` bash
systemctl disable docker.service
```