@constellation-network/node-pilot 0.0.12 → 0.0.13

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 CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @constellation-network/node-pilot
21
21
  $ cpilot COMMAND
22
22
  running command...
23
23
  $ cpilot (--version|-v)
24
- @constellation-network/node-pilot/0.0.12 darwin-arm64 node-v22.15.0
24
+ @constellation-network/node-pilot/0.0.13 darwin-arm64 node-v22.15.0
25
25
  $ cpilot --help [COMMAND]
26
26
  USAGE
27
27
  $ cpilot COMMAND
@@ -62,7 +62,7 @@ EXAMPLES
62
62
  $ cpilot config
63
63
  ```
64
64
 
65
- _See code: [src/commands/config.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/config.ts)_
65
+ _See code: [src/commands/config.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/config.ts)_
66
66
 
67
67
  ## `cpilot config get [NAME]`
68
68
 
@@ -86,7 +86,7 @@ EXAMPLES
86
86
  $ cpilot config get gl0:CL_PUBLIC_HTTP_PORT
87
87
  ```
88
88
 
89
- _See code: [src/commands/config/get.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/config/get.ts)_
89
+ _See code: [src/commands/config/get.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/config/get.ts)_
90
90
 
91
91
  ## `cpilot config set NAME VALUE`
92
92
 
@@ -109,7 +109,7 @@ EXAMPLES
109
109
  $ cpilot config set gl0:CL_PUBLIC_HTTP_PORT 9000
110
110
  ```
111
111
 
112
- _See code: [src/commands/config/set.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/config/set.ts)_
112
+ _See code: [src/commands/config/set.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/config/set.ts)_
113
113
 
114
114
  ## `cpilot help [COMMAND]`
115
115
 
@@ -146,7 +146,7 @@ EXAMPLES
146
146
  $ cpilot info
147
147
  ```
148
148
 
149
- _See code: [src/commands/info.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/info.ts)_
149
+ _See code: [src/commands/info.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/info.ts)_
150
150
 
151
151
  ## `cpilot logs LAYER`
152
152
 
@@ -170,7 +170,7 @@ EXAMPLES
170
170
  $ cpilot logs
171
171
  ```
172
172
 
173
- _See code: [src/commands/logs.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/logs.ts)_
173
+ _See code: [src/commands/logs.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/logs.ts)_
174
174
 
175
175
  ## `cpilot restart [LAYER]`
176
176
 
@@ -198,7 +198,7 @@ EXAMPLES
198
198
  $ cpilot restart
199
199
  ```
200
200
 
201
- _See code: [src/commands/restart.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/restart.ts)_
201
+ _See code: [src/commands/restart.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/restart.ts)_
202
202
 
203
203
  ## `cpilot shutdown`
204
204
 
@@ -215,7 +215,7 @@ EXAMPLES
215
215
  $ cpilot shutdown
216
216
  ```
217
217
 
218
- _See code: [src/commands/shutdown.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/shutdown.ts)_
218
+ _See code: [src/commands/shutdown.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/shutdown.ts)_
219
219
 
220
220
  ## `cpilot status`
221
221
 
@@ -229,5 +229,5 @@ DESCRIPTION
229
229
  Display node status and configuration settings
230
230
  ```
231
231
 
232
- _See code: [src/commands/status.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.12/src/commands/status.ts)_
232
+ _See code: [src/commands/status.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.13/src/commands/status.ts)_
233
233
  <!-- commandsstop -->
@@ -4,6 +4,7 @@ import { checkProject } from "../checks/check-project.js";
4
4
  import { clm } from "../clm.js";
5
5
  import { configStore } from "../config-store.js";
6
6
  import { configHelper } from "../helpers/config-helper.js";
7
+ import { serviceLog } from "../helpers/service-log.js";
7
8
  import { dockerService } from "../services/docker-service.js";
8
9
  import { nodeService } from "../services/node-service.js";
9
10
  export default class Restart extends BaseCommand {
@@ -23,11 +24,15 @@ export default class Restart extends BaseCommand {
23
24
  this.checkProject(flags);
24
25
  configHelper.assertProject('No project found. ');
25
26
  if (flags.update) {
27
+ serviceLog.log('Executing "cpilot restart --update" at ' + new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angeles' }));
26
28
  const project = configStore.getActiveProject();
27
- for (const project of configStore.getRunningProjects()) {
29
+ const activeProjects = configStore.getRunningProjects();
30
+ serviceLog.log(` Active projects: ${activeProjects.join(', ')}...`);
31
+ for (const project of activeProjects) {
28
32
  configStore.setActiveProject(project);
29
33
  // eslint-disable-next-line no-await-in-loop
30
34
  if (await checkProject.hasVersionChanged()) {
35
+ serviceLog.log(' ' + project + ' version has changed. Restarting...');
31
36
  // eslint-disable-next-line no-await-in-loop
32
37
  await this.restart();
33
38
  }
@@ -36,8 +41,12 @@ export default class Restart extends BaseCommand {
36
41
  return;
37
42
  }
38
43
  if (flags.autostart) {
44
+ serviceLog.log('Executing "cpilot restart --autostart" at ' + new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angeles' }));
39
45
  const project = configStore.getActiveProject();
40
- for (const project of configStore.getRunningProjects()) {
46
+ const activeProjects = configStore.getRunningProjects();
47
+ serviceLog.log(` Active projects: ${activeProjects.join(', ')}...`);
48
+ for (const project of activeProjects) {
49
+ serviceLog.log(' ' + project + ' is restarting...');
41
50
  configStore.setActiveProject(project);
42
51
  // eslint-disable-next-line no-await-in-loop
43
52
  await this.restart();
@@ -0,0 +1,3 @@
1
+ export declare const serviceLog: {
2
+ log(s: string): void;
3
+ };
@@ -0,0 +1,10 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { configStore } from "../config-store.js";
4
+ export const serviceLog = {
5
+ log(s) {
6
+ const appDir = configStore.getAppDir();
7
+ const logFile = path.join(appDir, 'logs', 'service.log');
8
+ fs.appendFileSync(logFile, s + '\n');
9
+ },
10
+ };
@@ -4,7 +4,6 @@ import { fileURLToPath } from "node:url";
4
4
  import { clm } from "../clm.js";
5
5
  import { configStore } from "../config-store.js";
6
6
  import { shellService } from "./shell-service.js";
7
- const INSTALL_PATH = '/etc/systemd/system/';
8
7
  export const systemdService = {
9
8
  async install() {
10
9
  const { platform } = configStore.getSystemInfo();
@@ -12,33 +11,12 @@ export const systemdService = {
12
11
  clm.warn('Node Pilot services can only be installed on Linux systems. Skipping systemd service installation.\n');
13
12
  return;
14
13
  }
15
- const projectFolder = path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../scripts/services`);
16
- if (!fs.existsSync(projectFolder)) {
17
- clm.error(`Node Pilot services's folder not found: ${projectFolder}`);
14
+ const installServicesScript = path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../scripts/install_services.sh`);
15
+ if (!fs.existsSync(installServicesScript)) {
16
+ clm.error(`Node Pilot install system services script not found: ${installServicesScript}`);
18
17
  }
19
18
  clm.preStep('Installing Node Pilot system services...');
20
- const restarterPath = path.join(INSTALL_PATH, 'node-pilot-restarter.service');
21
- const updaterPath = path.join(INSTALL_PATH, 'node-pilot-updater.service');
22
- let restarterInstalled = false;
23
- let updaterInstalled = false;
24
- if (!fs.existsSync(restarterPath)) {
25
- await shellService.runCommand(`sudo cp ${path.join(projectFolder, 'node-pilot-restarter.service')} ${restarterPath}`);
26
- clm.step('Node Pilot restarter service installed successfully.');
27
- restarterInstalled = true;
28
- }
29
- if (!fs.existsSync(updaterPath)) {
30
- await shellService.runCommand(`sudo cp ${path.join(projectFolder, 'node-pilot-updater.service')} ${updaterPath}`);
31
- clm.step('Node Pilot updater service installed successfully.');
32
- updaterInstalled = true;
33
- }
34
- if (restarterInstalled || updaterInstalled) {
35
- await shellService.runCommand('sudo systemctl daemon-reload');
36
- }
37
- await shellService.runCommand('sudo systemctl enable node-pilot-restarter.service');
38
- await shellService.runCommand('sudo systemctl start node-pilot-restarter.service');
39
- clm.postStep('\nNode Pilot restarter service started successfully.');
40
- await shellService.runCommand('sudo systemctl enable node-pilot-updater.service');
41
- await shellService.runCommand('sudo systemctl start node-pilot-updater.service');
42
- clm.postStep('\nNode Pilot updater service started successfully.');
19
+ await shellService.runCommand(installServicesScript);
20
+ clm.postStep('\nNode Pilot system service started successfully.');
43
21
  }
44
22
  };
@@ -276,5 +276,5 @@
276
276
  ]
277
277
  }
278
278
  },
279
- "version": "0.0.12"
279
+ "version": "0.0.13"
280
280
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@constellation-network/node-pilot",
3
3
  "description": "An easy deployment and monitoring tool for Constellation nodes.",
4
- "version": "0.0.12",
4
+ "version": "0.0.13",
5
5
  "author": "Frank Fox",
6
6
  "bin": {
7
7
  "cpilot": "bin/run.js"
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+
3
+ CPILOT=$(command -v cpilot)
4
+ if [ -z "$CPILOT" ]; then
5
+ echo "cpilot command not found. Please ensure Node Pilot is installed and accessible in your PATH."
6
+ exit 1
7
+ fi
8
+
9
+ WORKING_DIR=/home/$USER/.config/systemd/user
10
+
11
+ mkdir -p $WORKING_DIR
12
+
13
+ cat << EOF > $WORKING_DIR/restart-unhealthy.service
14
+ [Unit]
15
+ Description=Restart unhealthy docker containers
16
+ After=docker.service
17
+ Wants=docker.service
18
+
19
+ [Service]
20
+ ExecStartPre=/bin/sleep 300
21
+ ExecStart=$WORKING_DIR/restart-unhealthy.sh
22
+ Restart=always
23
+ RestartSec=60s
24
+ EOF
25
+
26
+ cat << EOF > $WORKING_DIR/restart-unhealthy.sh
27
+ #!/usr/bin/env bash
28
+ docker ps -q -f health=unhealthy | xargs --no-run-if-empty docker restart
29
+ EOF
30
+
31
+ chmod +x $WORKING_DIR/restart-unhealthy.sh
32
+
33
+ cat << EOF > $WORKING_DIR/node-pilot-autostart.service
34
+ [Unit]
35
+ Description=Constellation Network Node Auto Restart Service
36
+ After=default.target
37
+
38
+ [Service]
39
+ ExecStart=$CPILOT restart --autostart
40
+
41
+ [Install]
42
+ WantedBy=default.target
43
+ EOF
44
+
45
+ cat << EOF > $WORKING_DIR/node-pilot-update.service
46
+ [Unit]
47
+ Description=Constellation Node Pilot Updater Service
48
+ After=default.target
49
+
50
+ [Service]
51
+ ExecStartPre=/bin/sleep 300
52
+ ExecStart=$CPILOT restart --update
53
+ Restart=always
54
+ RestartSec=5m
55
+
56
+ [Install]
57
+ WantedBy=default.target
58
+ EOF
59
+
60
+ systemctl --user daemon-reload
61
+
62
+ systemctl --user enable restart-unhealthy.service
63
+ systemctl --user enable node-pilot-autostart.service
64
+ systemctl --user enable node-pilot-update.service
65
+
66
+ systemctl --user start restart-unhealthy.service
67
+ systemctl --user start node-pilot-autostart.service
68
+ systemctl --user start node-pilot-update.service
69
+
70
+ loginctl enable-linger $USER
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- # This script monitors Docker containers and restarts any that are unhealthy.
3
-
4
- unhealthy_containers=$(docker ps -q --filter health=unhealthy)
5
- if [ -n "$unhealthy_containers" ]; then
6
- echo "Restarting unhealthy containers: $unhealthy_containers"
7
- docker restart $unhealthy_containers
8
- fi
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- echo "Executing \"cpilot restart --autostart\" at $(date "+%b %d %H:%M:%S")" >> ~/.node-pilot/logs/service.log
@@ -1,16 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>Label</key>
6
- <string>io.constellationnetwork.nodepilot.Updater</string>
7
- <key>ProgramArguments</key>
8
- <array>
9
- <string>~/.node-pilot/scripts/updater.sh</string>
10
- </array>
11
- <key>StartInterval</key>
12
- <integer>300</integer>
13
- <key>RunAtLoad</key>
14
- <boolean>true</boolean>
15
- </dict>
16
- </plist>
@@ -1,12 +0,0 @@
1
- [Unit]
2
- Description=Constellation node pilot docker container auto heal service
3
- After=multi-user.target
4
-
5
- [Service]
6
- Type=simple
7
- ExecStart=%h/.node-pilot/scripts/autoheal.sh
8
- Restart=always
9
- RestartSec=15s
10
-
11
- [Install]
12
- WantedBy=multi-user.target
@@ -1,12 +0,0 @@
1
- [Unit]
2
- Description=Constellation Network node auto_restart service
3
- After=multi-user.target
4
-
5
- [Service]
6
- Type=simple
7
- User=ubuntu
8
- ExecStartPre=%h/.node-pilot/scripts/restart_logger.sh
9
- ExecStart=cpilot restart --autostart
10
-
11
- [Install]
12
- WantedBy=multi-user.target
@@ -1,14 +0,0 @@
1
- [Unit]
2
- Description=Constellation Node Pilot Updater Service
3
- After=multi-user.target
4
-
5
- [Service]
6
- Type=simple
7
- User=ubuntu
8
- ExecStartPre=%h/.node-pilot/scripts/update_logger.sh
9
- ExecStart=cpilot restart --update
10
- Restart=always
11
- RestartSec=5m
12
-
13
- [Install]
14
- WantedBy=multi-user.target
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- echo "Executing \"cpilot restart --update\" at $(date "+%b %d %H:%M:%S")" >> ~/.node-pilot/logs/service.log