dsh-ops-kit 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/README.zh-CN.md +1 -1
- package/client.js +42 -7
- package/docs/DETAIL.md +1 -71
- package/docs/DETAIL.zh.md +1 -0
- package/docs/USAGE.md +213 -0
- package/docs/USAGE.zh-CN.md +2 -0
- package/docs/preview.svg +53 -0
- package/index.js +53 -1
- package/locale/zh.json +1 -1
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -96,8 +96,8 @@ dsh plugin --profile desktop add dsh-ops-kit
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
A task-oriented walkthrough (setup checks, the ten panel pages, setting defaults,
|
|
99
|
-
data sensitivity, troubleshooting) is in
|
|
100
|
-
[docs/USAGE.zh-CN.md](docs/USAGE.zh-CN.md)
|
|
99
|
+
data sensitivity, troubleshooting) is in [docs/USAGE.md](docs/USAGE.md), also
|
|
100
|
+
available in Chinese: [docs/USAGE.zh-CN.md](docs/USAGE.zh-CN.md).
|
|
101
101
|
|
|
102
102
|
Local development install (directory):
|
|
103
103
|
|
package/README.zh-CN.md
CHANGED
package/client.js
CHANGED
|
@@ -96,7 +96,9 @@ window.__ModuleLoader__.load({
|
|
|
96
96
|
aiNeedTerm: '先连上终端,生成的命令才会发到服务器', aiModel: '模型',
|
|
97
97
|
process: '进程', byCpu: '按 CPU', byMem: '按内存', pid: 'PID', cpuUse: 'CPU', memUse: '内存', cmd: '命令',
|
|
98
98
|
end: '结束', ending: '结束中…', confirmKill: '结束这个进程?',
|
|
99
|
-
logs: '日志', logSource: '
|
|
99
|
+
logs: '日志', logSource: '日志来源(可下拉选:服务名 / pid:12345 / file:/var/log/x.log)', lines: '行数', load: '读取', auto: '自动刷新(5s)',
|
|
100
|
+
logHint: '不知道填什么?点输入框会弹出下拉列表:systemd 服务(如 nginx.service)、java 进程(pid:12345)、或日志文件(file:/var/log/xxx.log)。选 java 进程时插件自己找日志——属于某个服务就用 journalctl,否则取它打开的最新 .log / .out 文件。',
|
|
101
|
+
logPick: '先选一个来源(点输入框有下拉列表),再点「读取」。',
|
|
100
102
|
ssl: '证书', domain: '域名', checkSsl: '检查证书', daysLeft: '剩余天数', expireAt: '到期', noExpire: '没读到证书',
|
|
101
103
|
files: '文件', upload: '上传', newFolder: '新建文件夹', size: '大小', modified: '修改时间', open: '进入', download: '下载', del: '删除', folderName: '文件夹名', confirmDel: '删除这个路径?',
|
|
102
104
|
ask: '问一下', diagnose: '智能诊断', diagnosing: '诊断中…', askPh: '例如:网站为什么打不开?',
|
|
@@ -177,7 +179,9 @@ window.__ModuleLoader__.load({
|
|
|
177
179
|
aiNeedTerm: 'Connect the terminal first so the command can be sent', aiModel: 'model',
|
|
178
180
|
process: 'Processes', byCpu: 'By CPU', byMem: 'By memory', pid: 'PID', cpuUse: 'CPU', memUse: 'MEM', cmd: 'Command',
|
|
179
181
|
end: 'End', ending: 'Ending…', confirmKill: 'Kill this process?',
|
|
180
|
-
logs: 'Logs', logSource: '
|
|
182
|
+
logs: 'Logs', logSource: 'Log source (pick from the list: unit / pid:12345 / file:/var/log/x.log)', lines: 'Lines', load: 'Load', auto: 'Auto refresh (5s)',
|
|
183
|
+
logHint: 'Not sure what to type? Click the field for a list: a systemd unit (nginx.service), a java process (pid:12345), or a log file (file:/var/log/x.log). For a java process the plugin finds the log itself — journalctl when it belongs to a unit, otherwise the newest .log / .out file it has open.',
|
|
184
|
+
logPick: 'Pick a source first (click the field for the list), then press Load.',
|
|
181
185
|
ssl: 'Certificate', domain: 'Domain', checkSsl: 'Check certificate', daysLeft: 'days left', expireAt: 'expires', noExpire: 'no certificate read',
|
|
182
186
|
files: 'Files', upload: 'Upload', newFolder: 'New folder', size: 'Size', modified: 'Modified', open: 'Open', download: 'Download', del: 'Delete', folderName: 'Folder name', confirmDel: 'Delete this path?',
|
|
183
187
|
ask: 'Ask', diagnose: 'Diagnose', diagnosing: 'Diagnosing…', askPh: 'e.g. why is the site down?',
|
|
@@ -516,11 +520,14 @@ window.__ModuleLoader__.load({
|
|
|
516
520
|
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
517
521
|
}
|
|
518
522
|
|
|
519
|
-
const loadLogs = async () => {
|
|
523
|
+
const loadLogs = async (src) => {
|
|
524
|
+
const source = String(src ?? logSource).trim()
|
|
525
|
+
if (!source) { setLogText(T.logPick); return }
|
|
520
526
|
setBusy('logs')
|
|
521
527
|
try {
|
|
522
|
-
const data = await api(`tail?host=${encodeURIComponent(cHost || hosts[0]?.name)}&source=${encodeURIComponent(
|
|
523
|
-
|
|
528
|
+
const data = await api(`tail?host=${encodeURIComponent(cHost || hosts[0]?.name)}&source=${encodeURIComponent(source)}&lines=${logLines}`, {}, timeoutFor('action'))
|
|
529
|
+
const head = data.resolved ? `# ${data.via === 'journal' ? 'journalctl -u ' + data.resolved : data.resolved}\n\n` : ''
|
|
530
|
+
setLogText(head + (data.lines || data.error || ''))
|
|
524
531
|
} catch (e) { setLogText(String(e.message || e)) } finally { setBusy('') }
|
|
525
532
|
}
|
|
526
533
|
|
|
@@ -1069,7 +1076,20 @@ window.__ModuleLoader__.load({
|
|
|
1069
1076
|
h('span', { className: app.status ? 'ops-ok' : 'ops-dim', style: { fontSize: '12px' } }, app.status || ''),
|
|
1070
1077
|
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1071
1078
|
app.config ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void openFile(app.config, app.name) } }, T.configFile) : null,
|
|
1072
|
-
h('button', {
|
|
1079
|
+
h('button', {
|
|
1080
|
+
className: 'ops-btn ops-btn-sm',
|
|
1081
|
+
disabled: busy === `act:${app.kind}:${app.name}:logs`,
|
|
1082
|
+
onClick: () => {
|
|
1083
|
+
if (app.kind === 'java') {
|
|
1084
|
+
const src = `pid:${String(app.name).replace(/[^0-9]/g, '')}`
|
|
1085
|
+
setLogSource(src)
|
|
1086
|
+
setDetailTab('logs')
|
|
1087
|
+
void loadLogs(src)
|
|
1088
|
+
return
|
|
1089
|
+
}
|
|
1090
|
+
void doAction(app.kind, app.name, 'logs')
|
|
1091
|
+
},
|
|
1092
|
+
}, busy === `act:${app.kind}:${app.name}:logs` ? T.reading : T.logs),
|
|
1073
1093
|
app.kind === 'service' ? h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === `act:${app.kind}:${app.name}:stop`, onClick: () => { void doAction(app.kind, app.name, 'stop') } }, T.stop) : null,
|
|
1074
1094
|
app.kind !== 'java' ? h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === `act:${app.kind}:${app.name}:restart`, onClick: () => { void doAction(app.kind, app.name, 'restart') } }, busy === `act:${app.kind}:${app.name}:restart` ? '…' : T.restart) : null))))),
|
|
1075
1095
|
output ? h('pre', { className: 'ops-pre' }, output) : null,
|
|
@@ -1137,6 +1157,15 @@ window.__ModuleLoader__.load({
|
|
|
1137
1157
|
h('div', { className: sslResult.daysLeft !== null && sslResult.daysLeft < 15 ? 'ops-bad' : 'ops-sub', style: { fontSize: '12px' } },
|
|
1138
1158
|
sslResult.daysLeft === null ? T.noExpire : `${T.expireAt} ${sslResult.notAfter} · ${T.daysLeft} ${sslResult.daysLeft}`)) : null)))
|
|
1139
1159
|
|
|
1160
|
+
const logChoices = (() => {
|
|
1161
|
+
const apps = inv?.apps || []
|
|
1162
|
+
const services = apps.filter(a => a.kind === 'service').map(a => a.name)
|
|
1163
|
+
const pids = apps.filter(a => a.kind === 'java').map(a => `pid:${String(a.name).replace(/[^0-9]/g, '')}`)
|
|
1164
|
+
const files = ['file:/var/log/syslog', 'file:/var/log/messages', 'file:/var/log/nginx/error.log',
|
|
1165
|
+
'file:/var/log/nginx/access.log', 'file:/var/log/auth.log']
|
|
1166
|
+
return [...services, ...pids, ...files]
|
|
1167
|
+
})()
|
|
1168
|
+
|
|
1140
1169
|
const logsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1141
1170
|
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
|
|
1142
1171
|
h('div', { className: 'ops-card' },
|
|
@@ -1147,9 +1176,15 @@ window.__ModuleLoader__.load({
|
|
|
1147
1176
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'logs', onClick: () => { void loadLogs() } }, busy === 'logs' ? T.reading : T.load))),
|
|
1148
1177
|
h('div', { className: 'ops-card-b' },
|
|
1149
1178
|
h('div', { className: 'ops-chips' },
|
|
1150
|
-
h('input', {
|
|
1179
|
+
h('input', {
|
|
1180
|
+
className: 'ops-input', style: { flex: '1 1 320px' }, value: logSource, list: 'ops-log-sources',
|
|
1181
|
+
placeholder: T.logSource, onChange: e => setLogSource(e.target.value),
|
|
1182
|
+
onKeyDown: e => { if (e.key === 'Enter') void loadLogs() },
|
|
1183
|
+
}),
|
|
1184
|
+
h('datalist', { id: 'ops-log-sources' }, ...logChoices.map(o => h('option', { key: o, value: o }))),
|
|
1151
1185
|
h('label', { className: 'ops-sub' }, T.lines,
|
|
1152
1186
|
h('input', { className: 'ops-input', type: 'number', min: 20, max: 1000, value: logLines, style: { width: '90px' }, onChange: e => setLogLines(Number(e.target.value)) }))),
|
|
1187
|
+
h('p', { className: 'ops-sub', style: { margin: '0 0 8px', fontSize: '12px' } }, T.logHint),
|
|
1153
1188
|
h('pre', { className: 'ops-pre', style: { maxHeight: '55vh' } }, logText || (busy === 'logs' ? T.reading : '')))))
|
|
1154
1189
|
|
|
1155
1190
|
const filesView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
package/docs/DETAIL.md
CHANGED
|
@@ -1,71 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
## What it is
|
|
4
|
-
|
|
5
|
-
A DeepSeek Harness bundle for running Linux servers without leaving the
|
|
6
|
-
conversation. It contributes **34 agent tools and a sidebar panel**, and it
|
|
7
|
-
never needs an agent installed on the target host.
|
|
8
|
-
|
|
9
|
-
Authentication is either your existing SSH key / ssh-agent (through the system
|
|
10
|
-
`ssh` client in `BatchMode`, so the plugin never reads your key files) or a
|
|
11
|
-
password you store per host (through the plugin's own `ssh2` client, the only
|
|
12
|
-
path that keeps a secret on disk).
|
|
13
|
-
|
|
14
|
-
## What it adds
|
|
15
|
-
|
|
16
|
-
- **Inventory and connect** — host list, connectivity/latency test, public-key
|
|
17
|
-
installation, a read-only scan of ports, services, containers, nginx sites,
|
|
18
|
-
java processes, crontab and mounts.
|
|
19
|
-
- **Look at a host, read-only** — status snapshot, parallel check of every host,
|
|
20
|
-
0–100 health score, CPU/memory/disk samples, top processes, directory sizes,
|
|
21
|
-
log tails, file listings, certificate expiry, and a plain-language diagnosis.
|
|
22
|
-
- **Change something, with confirm guards** — one shell command, the same command
|
|
23
|
-
across hosts, systemd start/stop/restart, docker restart, killing a pid,
|
|
24
|
-
journal cleanup, and monitor management. Everything that changes state
|
|
25
|
-
requires `confirm: true` and fails closed instead of asking in a second turn.
|
|
26
|
-
- **Config and files** — read a config file, write one after backing it up, and
|
|
27
|
-
diff or roll back any `.bak.<ts>` version.
|
|
28
|
-
- **Backups, certificates, schedule, deploy** — MySQL dump or directory archive
|
|
29
|
-
with retention and restore, certificate probing with `certbot renew --dry-run`,
|
|
30
|
-
crontab editing, and git pull → build → restart → health check with automatic
|
|
31
|
-
rollback when the health check fails.
|
|
32
|
-
- **Alerts and AI** — delivery to Feishu / DingTalk / WeCom / any webhook with
|
|
33
|
-
per-channel levels and 10-minute dedupe, plus a natural-language `ops_ask` that
|
|
34
|
-
runs read-only commands itself.
|
|
35
|
-
|
|
36
|
-
## Panel
|
|
37
|
-
|
|
38
|
-
A sidebar page with ten sub-pages per host: overview, monitor, config, apps,
|
|
39
|
-
logs, files, terminal (a real PTY), backups, tasks and deploy. The overview runs
|
|
40
|
-
one host or all hosts and records each run in history. Restart, stop, restore and
|
|
41
|
-
rollback all ask for confirmation in the panel first.
|
|
42
|
-
|
|
43
|
-
## Requirements
|
|
44
|
-
|
|
45
|
-
- macOS or Linux host running DSH with `ssh` on `PATH`.
|
|
46
|
-
- Key or ssh-agent authentication already working for each host (`ssh -o
|
|
47
|
-
BatchMode=yes user@host true` must succeed) — or `ssh2` present in the profile
|
|
48
|
-
if you use stored passwords.
|
|
49
|
-
- Remote Linux with `systemctl` for the service tools; Docker is optional and
|
|
50
|
-
detected per call. Privileged actions need the host configured with
|
|
51
|
-
`sudo: true` and `sudo -n` allowed on the target.
|
|
52
|
-
|
|
53
|
-
## Data and safety
|
|
54
|
-
|
|
55
|
-
State lives in `$DSH_HOME/ops-kit/` (default `~/.dsh/ops-kit/`), deliberately
|
|
56
|
-
outside the profile so upgrading or removing the bundle never loses the
|
|
57
|
-
inventory: `hosts.json`, `config.json`, `history.json`, `state.json`,
|
|
58
|
-
`alerts.json`, `channels.json`, and — only when passwords are used —
|
|
59
|
-
`secrets.json`.
|
|
60
|
-
|
|
61
|
-
`secrets.json` and `channels.json` are mode 0600. Passwords in `secrets.json`
|
|
62
|
-
are **base64-encoded, not encrypted**; treat that file as a secret. Webhook URLs
|
|
63
|
-
are secrets too, which is why `channels.json` is 0600.
|
|
64
|
-
|
|
65
|
-
Tool output is clipped at 8 KB with an explicit truncation marker.
|
|
66
|
-
|
|
67
|
-
## Limitations
|
|
68
|
-
|
|
69
|
-
- SSH only: no cloud provider APIs, no Docker Compose or k8s orchestration.
|
|
70
|
-
- Metric retention is a bounded row cap, not a time-series database.
|
|
71
|
-
- Windows targets need an SSH server with a POSIX-like shell.
|
|
1
|
+

|
|
@@ -0,0 +1 @@
|
|
|
1
|
+

|
package/docs/USAGE.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# dsh-ops-kit — usage guide
|
|
2
|
+
|
|
3
|
+
Written for someone who has just installed the plugin and wants one server under
|
|
4
|
+
control. Tool parameters are deliberately not listed here: that is the schema the
|
|
5
|
+
model reads, and it drifts. This covers **prerequisites, the everyday flows, the
|
|
6
|
+
settings and troubleshooting**.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. Prerequisites (read this first — it prevents half the support questions)
|
|
11
|
+
|
|
12
|
+
The plugin reaches a host one of two ways. Decide which one applies:
|
|
13
|
+
|
|
14
|
+
| Path | Needs | Use when |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| **Key / ssh-agent** (default) | the system `ssh` can log in without a password (`ssh user@ip` just works) | most cases, preferred |
|
|
17
|
+
| **Password** | the `ssh2` package present in this profile | temporary hosts, no key set up yet |
|
|
18
|
+
|
|
19
|
+
Verify it in **your own terminal** before blaming the plugin:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
ssh -o BatchMode=yes user@ip 'echo ok' # prints ok only when it truly works
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`BatchMode=yes` matters — the plugin runs that way. Anything that would prompt
|
|
26
|
+
interactively (an unknown host key, a password request) fails the plugin outright
|
|
27
|
+
instead of asking.
|
|
28
|
+
|
|
29
|
+
### Also required
|
|
30
|
+
|
|
31
|
+
- **A POSIX shell on the target.** A Windows host only works if it runs an SSH
|
|
32
|
+
server with a POSIX-like shell.
|
|
33
|
+
- **Passwordless sudo for privileged actions.** Set `sudo: true` on the host and
|
|
34
|
+
allow `sudo -n` on the target (NOPASSWD). Otherwise restart/stop actions fail
|
|
35
|
+
with a permission error; read-only tools are unaffected.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 2. Five minutes to first result
|
|
40
|
+
|
|
41
|
+
### Add a host
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
ops_hosts action=add name=web-1 host=10.0.0.11 user=deploy key=~/.ssh/id_ed25519 defaultHost=true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
IP + user + password also works (stored in `secrets.json`), but key auth is
|
|
48
|
+
preferred.
|
|
49
|
+
|
|
50
|
+
### Prove the connection
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
ops_ssh_test host=web-1
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Returns `ok`, latency and the auth kind actually used. **Do not continue until
|
|
57
|
+
this is `ok`** — go back to section 1.
|
|
58
|
+
|
|
59
|
+
> If you added a password and got `ssh2 is not installed in this profile`, that
|
|
60
|
+
> profile lacks `ssh2`. Install it, or switch to keys — `ops_ssh_install_key
|
|
61
|
+
> host=web-1` pushes this machine's public key using the stored password, after
|
|
62
|
+
> which the password is no longer needed.
|
|
63
|
+
|
|
64
|
+
### Look at it
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
ops_status host=web-1
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
One call: uptime and load, memory, root disk, failed systemd units, containers.
|
|
71
|
+
|
|
72
|
+
Every host at once:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
ops_check_all
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Open the panel
|
|
79
|
+
|
|
80
|
+
The **Ops** page in the sidebar. It lists hosts, runs one host or all of them,
|
|
81
|
+
and is described in section 3.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 3. The ten panel pages
|
|
86
|
+
|
|
87
|
+
Click a host from the overview; the left side has ten sub-pages:
|
|
88
|
+
|
|
89
|
+
| Page | What it does |
|
|
90
|
+
|---|---|
|
|
91
|
+
| **Overview** | health score, key metrics, certificate expiry, backup state |
|
|
92
|
+
| **Monitor** | this host's checks (http / port / process / service / script), add, remove, test |
|
|
93
|
+
| **Config** | browse common config files; writing backs the old one up as `.bak.<ts>`; history and rollback |
|
|
94
|
+
| **Apps** | running services and containers with Logs / Restart / Stop |
|
|
95
|
+
| **Logs** | tail of a systemd unit or any log file |
|
|
96
|
+
| **Files** | directory listing with sizes and mtimes |
|
|
97
|
+
| **Terminal** | a real SSH PTY in the page (needs `ssh2`) |
|
|
98
|
+
| **Backups** | list, restore in one click, delete |
|
|
99
|
+
| **Tasks** | visual crontab editing |
|
|
100
|
+
| **Deploy** | one-click job: git pull → build → restart → health check |
|
|
101
|
+
|
|
102
|
+
**You do not have to remember log sources**: clicking the source field opens a list — a systemd unit (`nginx.service`), a java process (`pid:3154754`), or a log file (`file:/var/log/x.log`). For a java process the plugin finds the log itself: `journalctl -u` when the process belongs to a unit, otherwise the newest `.log` / `.out` file it has open. The resolved source is shown above the output.
|
|
103
|
+
|
|
104
|
+
**Restart, stop, restore and rollback all ask for confirmation first.**
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 4. Saying it in plain language
|
|
109
|
+
|
|
110
|
+
You never need the tool names:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
看一下 web-1 的状态
|
|
114
|
+
web-1 上 nginx 最近 50 行日志
|
|
115
|
+
磁盘满了,看看 / 下面谁占的空间
|
|
116
|
+
把 web-1 上的 my-api 重启一下(我确认)
|
|
117
|
+
所有机器上跑一下 uptime
|
|
118
|
+
web-1 的证书还有几天
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Question-style diagnosis
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
ops_ask host=web-1 question="mysql 还活着吗,为什么连不上"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The model picks **read-only** commands itself and answers. A command that would
|
|
128
|
+
change state comes back as "needs confirmation" instead of being executed.
|
|
129
|
+
|
|
130
|
+
### Batch
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
ops_batch command="df -h" hosts=[web-1,web-2]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Omit `hosts` to target every host. Destructive commands need `confirm`.
|
|
137
|
+
|
|
138
|
+
### Backups
|
|
139
|
+
|
|
140
|
+
```text
|
|
141
|
+
ops_backup host=web-1 action=backup type=mysql database=app
|
|
142
|
+
ops_backup host=web-1 action=list
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Defaults to `/home/backup`, keeps 7 copies; restore and delete both require
|
|
146
|
+
confirmation.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 5. Settings (`ops_config`)
|
|
151
|
+
|
|
152
|
+
Called with no arguments it returns the effective values. Defaults:
|
|
153
|
+
|
|
154
|
+
| Key | Default | Range | Meaning |
|
|
155
|
+
|---|---|---|---|
|
|
156
|
+
| `enabled` | `true` | — | run the scheduled background checks |
|
|
157
|
+
| `intervalMinutes` | `10` | 1–1440 | background check interval (minutes) |
|
|
158
|
+
| `diskWarnPercent` | `90` | 50–99 | alert when root disk exceeds this |
|
|
159
|
+
| `metricsMinutes` | `5` | 1–60 | metric sampling interval (minutes) |
|
|
160
|
+
| `timeoutSec` | `25` | 5–300 | general request timeout |
|
|
161
|
+
| `scanSec` | `90` | 10–600 | inventory scan timeout (raise for many or slow hosts) |
|
|
162
|
+
| `actionSec` | `45` | 10–600 | action and log-read timeout |
|
|
163
|
+
| `quickCommands` | 6 common commands | up to 12 | shortcuts under the terminal |
|
|
164
|
+
| `aiEnabled` | `true` | — | enable the `ops_ask` AI diagnosis |
|
|
165
|
+
| `aiProvider` / `aiModel` | empty = DSH default model | — | which model the ops AI uses |
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 6. Where the data lives, and how sensitive it is
|
|
170
|
+
|
|
171
|
+
Everything is under `$DSH_HOME/ops-kit/` (default `~/.dsh/ops-kit/`),
|
|
172
|
+
**deliberately outside the profile**, so upgrading or removing the plugin never
|
|
173
|
+
loses it.
|
|
174
|
+
|
|
175
|
+
| File | Contents | Sensitivity |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| `hosts.json` | host inventory | low |
|
|
178
|
+
| `secrets.json` | passwords, **base64-encoded, not encrypted**, mode 0600 | **high — treat as a key** |
|
|
179
|
+
| `channels.json` | alert webhook URLs, mode 0600 | **high — the URL is a secret** |
|
|
180
|
+
| `history.json` | history of every check run | low |
|
|
181
|
+
| `config.json` | the settings above | low |
|
|
182
|
+
| `state.json`, `alerts.json` | scheduler state and alert log | low |
|
|
183
|
+
|
|
184
|
+
`secrets.json` is **not encrypted**: anyone who can read that file has your
|
|
185
|
+
server passwords. Prefer key authentication, or make sure the account on this
|
|
186
|
+
machine is trustworthy.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 7. Troubleshooting
|
|
191
|
+
|
|
192
|
+
| Symptom | Cause and fix |
|
|
193
|
+
|---|---|
|
|
194
|
+
| `ops_ssh_test` fails but typing `ssh` works | the plugin runs in `BatchMode` and never answers prompts. Add the host key to `known_hosts`, or switch to keys |
|
|
195
|
+
| `ssh2 is not installed in this profile` | password path without `ssh2`. Install it, or use keys (`ops_ssh_install_key`) |
|
|
196
|
+
| restart reports a permission error | host not configured with `sudo: true`, or the target does not allow `sudo -n` |
|
|
197
|
+
| a truncation marker at the end of output | output over 8 KB was clipped. Narrow the request (`lines=`, a tighter command) rather than raising the cap |
|
|
198
|
+
| scheduled checks never run | `enabled` in `ops_config`; also check whether `scanSec` is too low and everything times out |
|
|
199
|
+
| alerts never arrive | expired webhook URL (group bots reset theirs), level mismatch, or the same alert was sent within 10 minutes |
|
|
200
|
+
| the panel opens but is empty | confirm the plugin is loaded in that session and that `/ops-kit/api` is not blocked by a reverse proxy |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 8. What happens with state-changing actions
|
|
205
|
+
|
|
206
|
+
| Action | Requires |
|
|
207
|
+
|---|---|
|
|
208
|
+
| start / stop / restart a service, restart a container | `confirm: true` |
|
|
209
|
+
| `ops_run` with a destructive command (`rm -rf /`, `mkfs`, `dd` to a device, `shutdown`/`reboot`) | `confirm: true`, otherwise refused outright |
|
|
210
|
+
| backup restore and delete, config rollback, one-click deploy | `confirm: true` |
|
|
211
|
+
| health checks, `ops_status`, `ops_check_all`, `ops_ssh_test`, `ops_ask` | read-only, no confirmation |
|
|
212
|
+
|
|
213
|
+
The principle: **reading is always free, writing needs a human nod.**
|
package/docs/USAGE.zh-CN.md
CHANGED
|
@@ -86,6 +86,8 @@ ops_check_all
|
|
|
86
86
|
| **计划任务** | crontab 可视化增删 |
|
|
87
87
|
| **发布** | 一键发布任务:git pull → 构建 → 重启 → 健康检查 |
|
|
88
88
|
|
|
89
|
+
**日志来源不用记**:点来源输入框会弹出列表 —— systemd 服务名(`nginx.service`)、java 进程(`pid:3154754`)、或日志文件(`file:/var/log/xxx.log`)。选 java 进程时插件自己找日志:该进程属于某个服务就用 `journalctl -u`,否则取它打开的最新的 `.log` / `.out` 文件。读取结果顶部会标出实际用的来源。
|
|
90
|
+
|
|
89
91
|
**重启 / 停止 / 回滚 / 恢复都会先弹确认**,不会点了就执行。
|
|
90
92
|
|
|
91
93
|
---
|
package/docs/preview.svg
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300" role="img" aria-label="Ops panel: three hosts with status dots, a health gauge, metric sparklines and a confirm-guarded shield">
|
|
2
|
+
<rect x="0" y="0" width="640" height="300" rx="16" fill="#F5F7FA"/>
|
|
3
|
+
<rect x="0.5" y="0.5" width="639" height="299" rx="16" fill="none" stroke="#E3E7ED"/>
|
|
4
|
+
|
|
5
|
+
<!-- host list -->
|
|
6
|
+
<rect x="48" y="48" width="170" height="204" rx="12" fill="#FFFFFF" stroke="#E3E7ED"/>
|
|
7
|
+
|
|
8
|
+
<circle cx="70" cy="82" r="5" fill="#22C55E"/>
|
|
9
|
+
<rect x="86" y="75" width="86" height="7" rx="3.5" fill="#DCE2EA"/>
|
|
10
|
+
<rect x="86" y="89" width="54" height="7" rx="3.5" fill="#EDF1F6"/>
|
|
11
|
+
|
|
12
|
+
<circle cx="70" cy="136" r="5" fill="#F59E0B"/>
|
|
13
|
+
<rect x="86" y="129" width="74" height="7" rx="3.5" fill="#DCE2EA"/>
|
|
14
|
+
<rect x="86" y="143" width="46" height="7" rx="3.5" fill="#EDF1F6"/>
|
|
15
|
+
|
|
16
|
+
<circle cx="70" cy="190" r="5" fill="#94A3B8"/>
|
|
17
|
+
<rect x="86" y="183" width="94" height="7" rx="3.5" fill="#DCE2EA"/>
|
|
18
|
+
<rect x="86" y="197" width="60" height="7" rx="3.5" fill="#EDF1F6"/>
|
|
19
|
+
|
|
20
|
+
<!-- health gauge -->
|
|
21
|
+
<rect x="232" y="48" width="176" height="204" rx="12" fill="#FFFFFF" stroke="#E3E7ED"/>
|
|
22
|
+
<circle cx="320" cy="112" r="34" fill="none" stroke="#E9EDF2" stroke-width="11"/>
|
|
23
|
+
<circle cx="320" cy="112" r="34" fill="none" stroke="#2563EB" stroke-width="11"
|
|
24
|
+
stroke-linecap="round" stroke-dasharray="153.8 59.8"
|
|
25
|
+
transform="rotate(-90 320 112)"/>
|
|
26
|
+
<polyline points="308,112 316,120 332,102" fill="none" stroke="#16A34A"
|
|
27
|
+
stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
28
|
+
|
|
29
|
+
<rect x="252" y="166" width="136" height="8" rx="4" fill="#E9EDF2"/>
|
|
30
|
+
<rect x="252" y="166" width="104" height="8" rx="4" fill="#2563EB"/>
|
|
31
|
+
<rect x="252" y="184" width="136" height="8" rx="4" fill="#E9EDF2"/>
|
|
32
|
+
<rect x="252" y="184" width="86" height="8" rx="4" fill="#22C55E"/>
|
|
33
|
+
<rect x="252" y="202" width="136" height="8" rx="4" fill="#E9EDF2"/>
|
|
34
|
+
<rect x="252" y="202" width="58" height="8" rx="4" fill="#F59E0B"/>
|
|
35
|
+
|
|
36
|
+
<!-- metrics and confirm guard -->
|
|
37
|
+
<rect x="422" y="48" width="170" height="204" rx="12" fill="#FFFFFF" stroke="#E3E7ED"/>
|
|
38
|
+
|
|
39
|
+
<polyline points="446,112 468,94 490,104 512,80 534,92 556,72 578,84"
|
|
40
|
+
fill="none" stroke="#2563EB" stroke-width="2.5"
|
|
41
|
+
stroke-linecap="round" stroke-linejoin="round"/>
|
|
42
|
+
<polyline points="446,132 468,122 490,130 512,116 534,124 556,112 578,118"
|
|
43
|
+
fill="none" stroke="#22C55E" stroke-width="2.5"
|
|
44
|
+
stroke-linecap="round" stroke-linejoin="round"/>
|
|
45
|
+
<polyline points="446,150 468,146 490,150 512,142 534,148 556,140 578,144"
|
|
46
|
+
fill="none" stroke="#F59E0B" stroke-width="2.5"
|
|
47
|
+
stroke-linecap="round" stroke-linejoin="round"/>
|
|
48
|
+
|
|
49
|
+
<path d="M507 168 l28 11 v24 c0 17 -13 28 -28 34 c-15 -6 -28 -17 -28 -34 v-24 z"
|
|
50
|
+
fill="#ECFDF5" stroke="#22C55E" stroke-width="2.5" stroke-linejoin="round"/>
|
|
51
|
+
<polyline points="495,197 504,206 520,188" fill="none" stroke="#16A34A"
|
|
52
|
+
stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
53
|
+
</svg>
|
package/index.js
CHANGED
|
@@ -592,10 +592,16 @@ function createApiHandler({ connection } = {}) {
|
|
|
592
592
|
if (route === 'app' && method === 'POST') {
|
|
593
593
|
const body = (await readBody(req)) || {}
|
|
594
594
|
const kind = String(body.kind ?? '')
|
|
595
|
-
if (!['service', 'docker'].includes(kind)) { sendJson(res, 400, { error: 'unsupported app kind' }); return }
|
|
595
|
+
if (!['service', 'docker', 'java'].includes(kind)) { sendJson(res, 400, { error: 'unsupported app kind' }); return }
|
|
596
596
|
const action = String(body.action ?? 'logs')
|
|
597
597
|
if (action !== 'logs' && body.confirm !== true) { sendJson(res, 400, { error: 'changing an app needs confirm=true' }); return }
|
|
598
598
|
const cfg = pickHost(await loadHosts(), body.host)
|
|
599
|
+
if (kind === 'java') {
|
|
600
|
+
if (action !== 'logs') { sendJson(res, 400, { error: 'a java process only supports logs' }); return }
|
|
601
|
+
const pid = Number(String(body.name ?? '').replace(/[^0-9]/g, ''))
|
|
602
|
+
sendJson(res, 200, await tailProcessLog(cfg, pid, Number(body.lines) || 200))
|
|
603
|
+
return
|
|
604
|
+
}
|
|
599
605
|
sendJson(res, 200, await hostAction(kind, cfg, String(body.name ?? ''), action))
|
|
600
606
|
return
|
|
601
607
|
}
|
|
@@ -1663,6 +1669,7 @@ async function killProcess(cfg, pid, signal = 'TERM') {
|
|
|
1663
1669
|
async function tailLog(cfg, source, lines = 200) {
|
|
1664
1670
|
const n = Math.min(Math.max(Number(lines) || 200, 20), 1000)
|
|
1665
1671
|
const raw = String(source || '')
|
|
1672
|
+
if (raw.startsWith('pid:')) return await tailProcessLog(cfg, Number(raw.slice(4)), n)
|
|
1666
1673
|
let command
|
|
1667
1674
|
if (raw.startsWith('file:')) {
|
|
1668
1675
|
const path = raw.slice(5)
|
|
@@ -1676,6 +1683,51 @@ async function tailLog(cfg, source, lines = 200) {
|
|
|
1676
1683
|
return { host: cfg.name, source: raw, ok: result.ok, lines: String(result.stdout || '').slice(0, 60_000), error: result.ok ? '' : cleanStderr(result.stderr) }
|
|
1677
1684
|
}
|
|
1678
1685
|
|
|
1686
|
+
/**
|
|
1687
|
+
* Log for a bare PID (java processes have no unit name).
|
|
1688
|
+
* Uses the owning systemd unit when there is one, otherwise tails the newest
|
|
1689
|
+
* .log/.out file the process actually has open.
|
|
1690
|
+
*/
|
|
1691
|
+
async function tailProcessLog(cfg, pid, lines = 200) {
|
|
1692
|
+
const n = Math.min(Math.max(Number(lines) || 200, 20), 1000)
|
|
1693
|
+
if (!Number.isInteger(pid) || pid <= 0) throw new Error('a valid pid is required')
|
|
1694
|
+
|
|
1695
|
+
const unitRes = await ssh(cfg, `ps -o unit= -p ${pid} 2>/dev/null | tr -d ' \n'; true`, 20_000)
|
|
1696
|
+
const unit = String(unitRes.stdout || '').trim()
|
|
1697
|
+
if (unit && unit !== '-' && !unit.startsWith('session-') && !unit.includes(' ')) {
|
|
1698
|
+
const res = await ssh(cfg, `journalctl -u ${unit} -n ${n} --no-pager 2>&1`, 25_000)
|
|
1699
|
+
return {
|
|
1700
|
+
host: cfg.name, source: `pid:${pid}`, resolved: unit, via: 'journal',
|
|
1701
|
+
ok: res.ok, lines: String(res.stdout || '').slice(0, 60_000),
|
|
1702
|
+
error: res.ok ? '' : cleanStderr(res.stderr),
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
const scan = await ssh(
|
|
1707
|
+
cfg,
|
|
1708
|
+
`for f in /proc/${pid}/fd/*; do t=$(readlink "$f" 2>/dev/null); case "$t" in *.log|*.out) [ -f "$t" ] && printf '%s\\n' "$t";; esac; done 2>/dev/null | sort -u | head -20`,
|
|
1709
|
+
20_000,
|
|
1710
|
+
)
|
|
1711
|
+
const files = String(scan.stdout || '').split('\n').map(s => s.trim()).filter(f => f.startsWith('/'))
|
|
1712
|
+
if (files.length === 0) {
|
|
1713
|
+
return {
|
|
1714
|
+
host: cfg.name, source: `pid:${pid}`, resolved: '', via: 'none',
|
|
1715
|
+
ok: false, lines: '',
|
|
1716
|
+
error: `PID ${pid} 既不是 systemd 服务,也没有打开 .log / .out 文件。请到「文件」页找到日志路径,再在来源里填 file:/var/log/xxx.log`,
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
const quoted = files.map(f => JSON.stringify(f)).join(' ')
|
|
1721
|
+
const newest = await ssh(cfg, `ls -1t ${quoted} 2>/dev/null | head -1`, 20_000)
|
|
1722
|
+
const picked = String(newest.stdout || '').split('\n')[0].trim() || files[0]
|
|
1723
|
+
const res = await ssh(cfg, `tail -n ${n} ${JSON.stringify(picked)} 2>&1`, 25_000)
|
|
1724
|
+
return {
|
|
1725
|
+
host: cfg.name, source: `pid:${pid}`, resolved: picked, via: 'file',
|
|
1726
|
+
ok: res.ok, lines: String(res.stdout || '').slice(0, 60_000),
|
|
1727
|
+
error: res.ok ? '' : cleanStderr(res.stderr),
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1679
1731
|
/** TLS certificate expiry for a domain (checked from the host itself). */
|
|
1680
1732
|
async function sslCheck(cfg, domain) {
|
|
1681
1733
|
const host = String(domain || '').replace(/[^A-Za-z0-9.-]/g, '')
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ops-kit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Server operations kit for DeepSeek Harness: server cards, health charts, config browser, app manager and plain-language AI diagnosis — over SSH, no agent install.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"cordis.patch.yml",
|
|
19
19
|
"locale/*.json",
|
|
20
20
|
"docs/DETAIL.md",
|
|
21
|
+
"docs/DETAIL.zh.md",
|
|
22
|
+
"docs/preview.svg",
|
|
23
|
+
"docs/USAGE.md",
|
|
21
24
|
"docs/USAGE.zh-CN.md",
|
|
22
25
|
"icon.svg",
|
|
23
26
|
"README.md",
|
|
@@ -61,5 +64,13 @@
|
|
|
61
64
|
"bugs": {
|
|
62
65
|
"url": "https://github.com/shenlongze/dsh-ops-kit/issues"
|
|
63
66
|
},
|
|
64
|
-
"author": "shenlongze"
|
|
67
|
+
"author": "shenlongze",
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"ssh2": "^1.16.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"ssh2": {
|
|
73
|
+
"optional": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
65
76
|
}
|