@constellation-network/node-pilot 0.0.12 → 0.0.14

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.14 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.14/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.14/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.14/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.14/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.14/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.14/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.14/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.14/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();
@@ -66,16 +75,24 @@ export default class Restart extends BaseCommand {
66
75
  // const pAll = layersToRun.map(l => nodeService.getNodeInfo(l));
67
76
  // const info = await Promise.all(pAll);
68
77
  // const isRunning = info.some(n => n.state !== 'Unavailable');
69
- if (await dockerService.isRunning()) {
70
- await nodeService.leaveClusterAllLayers();
71
- const { layersToRun } = configStore.getProjectInfo();
72
- await nodeService.pollForLayersState(layersToRun, 'Offline');
73
- clm.preStep('Stopping the node...');
74
- await dockerService.dockerDown();
78
+ if (configStore.isRestarting())
79
+ return;
80
+ configStore.setIsRestarting(true);
81
+ try {
82
+ if (await dockerService.isRunning()) {
83
+ await nodeService.leaveClusterAllLayers();
84
+ const { layersToRun } = configStore.getProjectInfo();
85
+ await nodeService.pollForLayersState(layersToRun, 'Offline');
86
+ clm.preStep('Stopping the node...');
87
+ await dockerService.dockerDown();
88
+ }
89
+ clm.preStep('Checking for a new version...');
90
+ await checkProject.runUpgrade();
91
+ clm.preStep('Starting the node...');
92
+ await dockerService.dockerUp();
93
+ }
94
+ finally {
95
+ configStore.setIsRestarting(false);
75
96
  }
76
- clm.preStep('Checking for a new version...');
77
- await checkProject.runUpgrade();
78
- clm.preStep('Starting the node...');
79
- await dockerService.dockerUp();
80
97
  }
81
98
  }
@@ -18,6 +18,7 @@ declare class ConfigStore {
18
18
  getSystemInfo(): SystemInfo;
19
19
  hasProjectFlag(name: string): any;
20
20
  hasProjects(): boolean;
21
+ isRestarting(): boolean;
21
22
  setActiveProject(name: string): void;
22
23
  setClusterStats(info: Partial<ClusterStats>): void;
23
24
  setDockerEnvInfo(info: Partial<{
@@ -27,6 +28,7 @@ declare class ConfigStore {
27
28
  setEnvInfo(info: Partial<EnvInfo>): void;
28
29
  setEnvLayerInfo(network: NetworkType, layer: TessellationLayer, info: Partial<EnvLayerInfo>): void;
29
30
  setEnvNetworkInfo(network: NetworkType, info: Partial<EnvNetworkInfo>): void;
31
+ setIsRestarting(val: boolean): void;
30
32
  setNetworkInfo(info: Partial<NetworkInfo>): void;
31
33
  setProjectFlag(name: string, value: boolean): any;
32
34
  setProjectInfo(info: Partial<ProjectInfo>): void;
@@ -20,7 +20,7 @@ class ConfigStore {
20
20
  this.pilotStore = new JSONStorage(path.join(appDir, 'config'));
21
21
  const appInfo = this.pilotStore.getItem('pilot');
22
22
  if (!appInfo) {
23
- this.pilotStore.setItem('pilot', { appDir, project: 'undefined', projects: [], running: [] });
23
+ this.pilotStore.setItem('pilot', { appDir, project: 'undefined', projects: [], restarting: false, running: [] });
24
24
  }
25
25
  const { project } = this.pilotStore.getItem('pilot');
26
26
  this.projectStore = project === 'undefined' ? new EmptyStorage() : new JSONStorage(path.join(appDir, project, 'config'));
@@ -104,6 +104,10 @@ class ConfigStore {
104
104
  const { projects } = this.pilotStore.getItem('pilot');
105
105
  return projects.length > 0;
106
106
  }
107
+ isRestarting() {
108
+ const { restarting } = this.pilotStore.getItem('pilot');
109
+ return restarting;
110
+ }
107
111
  setActiveProject(name) {
108
112
  const { appDir, project, projects } = this.pilotStore.getItem('pilot');
109
113
  if (projects && projects.includes(name)) {
@@ -142,6 +146,9 @@ class ConfigStore {
142
146
  networks = {};
143
147
  this.projectStore.setItem('network-env', { ...networks, [network]: { ...networks[network], ...info } });
144
148
  }
149
+ setIsRestarting(val) {
150
+ this.setPilotInfo({ restarting: val });
151
+ }
145
152
  setNetworkInfo(info) {
146
153
  const oldInfo = this.projectStore.getItem('network');
147
154
  this.projectStore.setItem('network', { ...oldInfo, ...info });
@@ -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.14"
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.14",
5
5
  "author": "Frank Fox",
6
6
  "bin": {
7
7
  "cpilot": "bin/run.js"
@@ -0,0 +1,71 @@
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
+ ExecStart=$WORKING_DIR/restart-unhealthy.sh
21
+ Restart=always
22
+ RestartSec=60s
23
+
24
+ [Install]
25
+ WantedBy=docker.service
26
+ EOF
27
+
28
+ cat << EOF > $WORKING_DIR/restart-unhealthy.sh
29
+ #!/usr/bin/env bash
30
+ docker ps -q -f health=unhealthy | xargs --no-run-if-empty docker restart
31
+ EOF
32
+
33
+ chmod +x $WORKING_DIR/restart-unhealthy.sh
34
+
35
+ cat << EOF > $WORKING_DIR/node-pilot-autostart.service
36
+ [Unit]
37
+ Description=Constellation Network Node Auto Restart Service
38
+ After=default.target
39
+
40
+ [Service]
41
+ ExecStart=$CPILOT restart --autostart
42
+
43
+ [Install]
44
+ WantedBy=default.target
45
+ EOF
46
+
47
+ cat << EOF > $WORKING_DIR/node-pilot-update.service
48
+ [Unit]
49
+ Description=Constellation Node Pilot Updater Service
50
+ After=default.target
51
+
52
+ [Service]
53
+ ExecStart=$CPILOT restart --update
54
+ Restart=always
55
+ RestartSec=5m
56
+
57
+ [Install]
58
+ WantedBy=default.target
59
+ EOF
60
+
61
+ systemctl --user daemon-reload
62
+
63
+ systemctl --user enable restart-unhealthy.service
64
+ systemctl --user enable node-pilot-autostart.service
65
+ systemctl --user enable node-pilot-update.service
66
+
67
+ systemctl --user start restart-unhealthy.service
68
+ systemctl --user start node-pilot-autostart.service
69
+ systemctl --user start node-pilot-update.service
70
+
71
+ 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