shennian 0.2.27 → 0.2.28
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 -0
- package/dist/src/commands/daemon.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
| `shennian status` | 查看后台服务状态 |
|
|
21
21
|
| `shennian logs -n 100` | 查看最近日志 |
|
|
22
22
|
| `shennian config` | 查看本地配置 |
|
|
23
|
+
| `shennian config set server cn\|global` | 切换国内 / 海外中继节点 |
|
|
23
24
|
| `shennian agent add/list/remove` | 管理自定义 Agent |
|
|
24
25
|
| `shennian upgrade` | 升级 CLI |
|
|
25
26
|
|
|
26
27
|
`start`、`stop`、`status` 可选加 `--json`。`logs` 输出日志文本,不支持 `--json`。
|
|
28
|
+
切换节点后运行 `shennian stop && shennian start` 让后台服务重新连接。
|
|
27
29
|
|
|
28
30
|
## 开发
|
|
29
31
|
|
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import { execSync, spawn } from 'node:child_process';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
-
import { getShennianDir, resolveShennianPath } from '../config/index.js';
|
|
9
|
+
import { getShennianDir, loadConfig, resolveShennianPath, saveConfig } from '../config/index.js';
|
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const SHENNIAN_DIR = getShennianDir();
|
|
12
12
|
const PID_FILE = resolveShennianPath('daemon.pid');
|
|
@@ -179,6 +179,14 @@ export function getDaemonStatus(opts = {}) {
|
|
|
179
179
|
function printJson(value) {
|
|
180
180
|
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
181
181
|
}
|
|
182
|
+
function persistServerUrlOverride(serverUrl) {
|
|
183
|
+
const normalized = serverUrl?.trim();
|
|
184
|
+
if (!normalized)
|
|
185
|
+
return;
|
|
186
|
+
const config = loadConfig();
|
|
187
|
+
config.serverUrl = normalized;
|
|
188
|
+
saveConfig(config);
|
|
189
|
+
}
|
|
182
190
|
// ─── Service definitions ─────────────────────────────────────────────────────
|
|
183
191
|
const LAUNCHD_LABEL = 'com.shennian.agent';
|
|
184
192
|
const LAUNCHD_PLIST = path.join(os.homedir(), 'Library/LaunchAgents', `${LAUNCHD_LABEL}.plist`);
|
|
@@ -639,6 +647,7 @@ async function stopDaemonProcessAndWait(timeoutMs = 5000) {
|
|
|
639
647
|
return result;
|
|
640
648
|
}
|
|
641
649
|
function enableRemoteAccess(opts = {}) {
|
|
650
|
+
persistServerUrlOverride(opts.api);
|
|
642
651
|
try {
|
|
643
652
|
fs.unlinkSync(REMOTE_ACCESS_DISABLED_FILE);
|
|
644
653
|
}
|
|
@@ -726,6 +735,7 @@ async function waitForPidExit(pid, timeoutMs = 5000) {
|
|
|
726
735
|
return !isRunning(pid);
|
|
727
736
|
}
|
|
728
737
|
async function daemonRestart(opts = {}) {
|
|
738
|
+
persistServerUrlOverride(opts.api);
|
|
729
739
|
const pid = readPid();
|
|
730
740
|
if (pid !== null && isRunning(pid)) {
|
|
731
741
|
try {
|
|
@@ -888,6 +898,7 @@ export function registerDaemonCommand(program) {
|
|
|
888
898
|
.command('start')
|
|
889
899
|
.description('Start the background service')
|
|
890
900
|
.option('--json', 'Print machine-readable status JSON')
|
|
901
|
+
.option('--api <url>', 'Server URL override')
|
|
891
902
|
.action((opts) => daemonStart(opts));
|
|
892
903
|
program
|
|
893
904
|
.command('stop')
|
|
@@ -913,6 +924,7 @@ export function registerDaemonCommand(program) {
|
|
|
913
924
|
.command('start')
|
|
914
925
|
.description('Start the background service')
|
|
915
926
|
.option('--json', 'Print machine-readable status JSON')
|
|
927
|
+
.option('--api <url>', 'Server URL override')
|
|
916
928
|
.action((opts) => {
|
|
917
929
|
warnDeprecated('start', opts.json);
|
|
918
930
|
daemonStart(opts);
|
|
@@ -929,6 +941,7 @@ export function registerDaemonCommand(program) {
|
|
|
929
941
|
.command('restart')
|
|
930
942
|
.description('Restart the background service')
|
|
931
943
|
.option('--json', 'Print machine-readable status JSON')
|
|
944
|
+
.option('--api <url>', 'Server URL override')
|
|
932
945
|
.action((opts) => {
|
|
933
946
|
warnDeprecated('stop && shennian start', opts.json);
|
|
934
947
|
daemonRestart(opts);
|