|
@@ -1,5 +1,5 @@
|
|
|
# 使用 `systemctl` 配置服务.并且使其自启动
|
|
|
-## 环境介绍
|
|
|
+## 新增服务
|
|
|
> [!note]
|
|
|
> ubuntu 21.04
|
|
|
### 定义服务
|
|
@@ -25,13 +25,13 @@ ExecStart= server
|
|
|
[Install]
|
|
|
WantedBy=multi-user.target
|
|
|
```
|
|
|
-### 启动服务
|
|
|
+### 启用服务
|
|
|
```shell
|
|
|
-sudo systemctl start serverName
|
|
|
+sudo systemctl enable serverName
|
|
|
```
|
|
|
-### 服务加入到启动项
|
|
|
+### 启动服务
|
|
|
```shell
|
|
|
-sudo systemctl enable serverName
|
|
|
+sudo systemctl start serverName
|
|
|
```
|
|
|
### 常用命令
|
|
|
> [!tip]
|
|
@@ -65,4 +65,13 @@ sudo systemctl disable serverName
|
|
|
> Warning: The unit file, source configuration file or drop-ins of githook.service changed on disk. Run > 'systemctl daemon-reload' to reload units.
|
|
|
```shell
|
|
|
systemctl daemon-reload
|
|
|
+```
|
|
|
+## 日志查看
|
|
|
+> [!tip]
|
|
|
+> 查看服务日志使用 `journalctl -u 服务名`
|
|
|
+> `journalctl`用来查看`systemctl`搜集到的日志,可以用来调试排查问题. 据说是`systemctl`携带的
|
|
|
+### 使用示例
|
|
|
+查看服务名为`githook`的服务日志
|
|
|
+```shell
|
|
|
+journalctl -u githook.service
|
|
|
```
|