@fickydev/pigent 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli/run.ts +19 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fickydev/pigent",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Autonomous multi-agent daemon using Pi as core execution engine.",
package/src/cli/run.ts CHANGED
@@ -63,12 +63,17 @@ async function main(): Promise<void> {
63
63
  await runForeground(resolveForegroundDir());
64
64
  return;
65
65
  default:
66
+ if (await isServiceActive()) {
67
+ console.log("Pigent already running.");
68
+ console.log("Commands: pigent status, pigent logs, pigent restart, pigent update");
69
+ process.exit(0);
70
+ }
66
71
  await installAndStartService(appDir);
67
72
  }
68
73
  }
69
74
 
70
75
  async function installAndStartService(targetDir: string): Promise<void> {
71
- await ensureConfiguredApp(targetDir, true);
76
+ await ensureConfiguredApp(targetDir, needsSetup(targetDir));
72
77
 
73
78
  if (!(await hasSystemctl())) {
74
79
  console.log("[pigent] systemd user service unavailable; running in foreground");
@@ -89,6 +94,7 @@ async function installAndStartService(targetDir: string): Promise<void> {
89
94
  console.log(" pigent stop");
90
95
  console.log(" pigent restart");
91
96
  console.log(" pigent update");
97
+ process.exit(0);
92
98
  }
93
99
 
94
100
  async function startService(targetDir: string): Promise<void> {
@@ -98,6 +104,7 @@ async function startService(targetDir: string): Promise<void> {
98
104
  }
99
105
 
100
106
  await systemctl("start");
107
+ process.exit(0);
101
108
  }
102
109
 
103
110
  async function updateApp(targetDir: string): Promise<void> {
@@ -117,6 +124,7 @@ async function updateApp(targetDir: string): Promise<void> {
117
124
  await systemctl("enable", true, `${serviceName}.service`);
118
125
  await systemctl("restart");
119
126
  console.log("[pigent] updated and restarted service");
127
+ process.exit(0);
120
128
  } else {
121
129
  console.log("[pigent] updated. Run `pigent run` to start foreground daemon.");
122
130
  }
@@ -241,7 +249,7 @@ async function showLogs(): Promise<void> {
241
249
  }
242
250
 
243
251
  async function systemctl(action: string, nothrow = false, extra?: string): Promise<void> {
244
- const commandArgs = extra ? [action, extra] : [action, `${serviceName}.service`];
252
+ const commandArgs = action === "daemon-reload" ? [action] : extra ? [action, extra] : [action, `${serviceName}.service`];
245
253
  const proc = Bun.spawn(["systemctl", "--user", ...commandArgs], {
246
254
  stdout: "inherit",
247
255
  stderr: "inherit",
@@ -259,6 +267,15 @@ async function hasSystemctl(): Promise<boolean> {
259
267
  return result.exitCode === 0;
260
268
  }
261
269
 
270
+ async function isServiceActive(): Promise<boolean> {
271
+ if (!(await hasSystemctl())) return false;
272
+ const proc = Bun.spawn(["systemctl", "--user", "is-active", "--quiet", `${serviceName}.service`], {
273
+ stdout: "ignore",
274
+ stderr: "ignore",
275
+ });
276
+ return (await proc.exited) === 0;
277
+ }
278
+
262
279
  function servicePath(): string {
263
280
  return join(homedir(), ".config", "systemd", "user", `${serviceName}.service`);
264
281
  }