Skip to content

Commit 4c1556d

Browse files
committed
docs(systemd-service-manager): 更新文档添加命令说明和使用示例
- 在 README.md 中添加 Commands 章节,详细说明所有可用命令 - 添加 Common options 章节,说明通用选项用法 - 添加 Examples 章节,提供具体使用示例 - 更新 CLI 帮助信息,增加命令描述和选项说明 - 修复构建输出路径,在测试中更新本地脚本路径配置
1 parent c12d53e commit 4c1556d

4 files changed

Lines changed: 66 additions & 14 deletions

File tree

scripts/bash/systemd-service-manager/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
一个基于 Bash 的轻量 systemd `service` / `timer` 管理器。
44

5+
## Commands
6+
7+
- `init`:在项目目录下生成 `deploy/systemd/` 骨架、`README.md``*.example` 和默认可编辑配置。
8+
- `list`:列出项目中声明的 services 与 timers,方便确认命名和管理范围。
9+
- `install`:把 `.conf` / `.env` 渲染成 `.service` / `.timer`,并安装到 systemd 目录;支持 `--dry-run` 预览。
10+
- `uninstall`:删除当前工具生成的 unit 文件。
11+
- `start`:启动指定 service 或 timer。
12+
- `stop`:停止指定 service 或 timer。
13+
- `restart`:重启指定 service 或 timer。
14+
- `status`:查看指定对象的 `unit``scope``installed``enabled``active` 状态。
15+
- `logs`:查看 journald 日志;可配合 `--follow` 持续跟踪。
16+
- `enable`:启用开机或用户会话自启动。
17+
- `disable`:禁用开机或用户会话自启动。
18+
19+
## Common options
20+
21+
- `--project <path>`:指定项目根目录,默认使用当前目录。
22+
- `--dry-run`:只输出计划生成或安装的结果,不真正写入 systemd unit。
23+
- `--follow`:只给 `logs` 使用,持续跟随日志输出。
24+
525
## Build
626

727
```bash
@@ -11,10 +31,20 @@ bash scripts/bash/systemd-service-manager/build.sh
1131
## Outputs
1232

1333
- `bin/systemd-service-manager`
14-
- `scripts/bash/systemd-service-manager.sh`
34+
- `scripts/bash/systemd-service-manager/systemd-service-manager.local.sh`
1535

1636
打包后的单文件产物内嵌了 `init` 所需模板,因此把脚本单独复制到其他目录后,仍可直接执行 `init` 生成 `deploy/systemd/` 骨架。
1737

38+
## Examples
39+
40+
```bash
41+
systemd-service-manager init
42+
systemd-service-manager list --project /path/to/app
43+
systemd-service-manager install service api --project /path/to/app
44+
systemd-service-manager install timer cleanup --project /path/to/app --dry-run
45+
systemd-service-manager logs service api --project /path/to/app --follow
46+
```
47+
1848
## Test
1949

2050
```bash

scripts/bash/systemd-service-manager/lib/cli.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ ssm_show_help() {
1111
Usage: systemd-service-manager <command> [options]
1212
1313
Commands:
14-
init
15-
list
16-
install
17-
uninstall
18-
start
19-
stop
20-
restart
21-
status
22-
logs
23-
enable
24-
disable
25-
help
14+
init 初始化当前项目的 deploy/systemd 模板骨架
15+
list 列出当前项目中声明的 services 与 timers
16+
install 渲染并安装 service/timer unit 到 systemd
17+
uninstall 删除当前工具生成的 unit 文件
18+
start 启动指定 service 或 timer
19+
stop 停止指定 service 或 timer
20+
restart 重启指定 service 或 timer
21+
status 查看指定 service 或 timer 的安装与运行状态
22+
logs 查看指定 service 或 timer 的 journald 日志
23+
enable 启用指定 service 或 timer 的自启动
24+
disable 禁用指定 service 或 timer 的自启动
25+
help 显示这份帮助信息
26+
27+
Common options:
28+
--project <path> 指定项目根目录,默认使用当前目录
29+
--dry-run 只预览将执行的操作,不实际写入 unit
30+
--follow 配合 logs 使用,持续跟随日志输出
31+
32+
Examples:
33+
systemd-service-manager init
34+
systemd-service-manager list --project /path/to/app
35+
systemd-service-manager install service api --project /path/to/app
36+
systemd-service-manager install timer cleanup --project /path/to/app --dry-run
37+
systemd-service-manager logs service api --project /path/to/app --follow
2638
EOF
2739
}
2840

scripts/bash/systemd-service-manager/tests/manager-cli.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ describe('systemd service manager cli', () => {
3434
expect(sourceHelp.stdout).toContain(
3535
'Usage: systemd-service-manager <command> [options]',
3636
)
37+
expect(sourceHelp.stdout).toContain('init 初始化当前项目的 deploy/systemd 模板骨架')
38+
expect(sourceHelp.stdout).toContain('install 渲染并安装 service/timer unit 到 systemd')
39+
expect(sourceHelp.stdout).toContain('--project <path> 指定项目根目录')
40+
expect(sourceHelp.stdout).toContain('--dry-run 只预览将执行的操作')
3741
expect(builtHelp.stdout).toBe(sourceHelp.stdout)
3842
})
3943

scripts/bash/systemd-service-manager/tests/test-utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ export function createWorkspace(): Workspace {
5454
sourceEntry: path.join(managerHome, 'main.sh'),
5555
buildScript: path.join(managerHome, 'build.sh'),
5656
builtBin: path.join(root, 'bin', 'systemd-service-manager'),
57-
builtLocal: path.join(root, 'scripts', 'bash', 'systemd-service-manager.sh'),
57+
builtLocal: path.join(
58+
root,
59+
'scripts',
60+
'bash',
61+
'systemd-service-manager',
62+
'systemd-service-manager.local.sh',
63+
),
5864
fakeSystemDir,
5965
fakeUserDir,
6066
mockBin,

0 commit comments

Comments
 (0)