palmier 0.3.8 → 0.3.9
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/dist/platform/linux.js +22 -15
- package/package.json +1 -1
- package/src/platform/linux.ts +27 -17
package/dist/platform/linux.js
CHANGED
|
@@ -5,6 +5,7 @@ import { execSync, exec } from "child_process";
|
|
|
5
5
|
import { promisify } from "util";
|
|
6
6
|
const execAsync = promisify(exec);
|
|
7
7
|
const UNIT_DIR = path.join(homedir(), ".config", "systemd", "user");
|
|
8
|
+
const PATH_FILE = path.join(homedir(), ".config", "palmier", "user-path");
|
|
8
9
|
function getTimerName(taskId) {
|
|
9
10
|
return `palmier-task-${taskId}.timer`;
|
|
10
11
|
}
|
|
@@ -56,6 +57,11 @@ export class LinuxPlatform {
|
|
|
56
57
|
installDaemon(config) {
|
|
57
58
|
fs.mkdirSync(UNIT_DIR, { recursive: true });
|
|
58
59
|
const palmierBin = process.argv[1] || "palmier";
|
|
60
|
+
// Save the user's shell PATH so restartDaemon can use it later
|
|
61
|
+
// (the daemon itself runs under systemd with a limited PATH).
|
|
62
|
+
const userPath = process.env.PATH || "/usr/local/bin:/usr/bin:/bin";
|
|
63
|
+
fs.mkdirSync(path.dirname(PATH_FILE), { recursive: true });
|
|
64
|
+
fs.writeFileSync(PATH_FILE, userPath, "utf-8");
|
|
59
65
|
const serviceContent = `[Unit]
|
|
60
66
|
Description=Palmier Host
|
|
61
67
|
After=network-online.target
|
|
@@ -67,7 +73,7 @@ ExecStart=${palmierBin} serve
|
|
|
67
73
|
WorkingDirectory=${config.projectRoot}
|
|
68
74
|
Restart=on-failure
|
|
69
75
|
RestartSec=5
|
|
70
|
-
Environment=PATH=${
|
|
76
|
+
Environment=PATH=${userPath}
|
|
71
77
|
|
|
72
78
|
[Install]
|
|
73
79
|
WantedBy=default.target
|
|
@@ -96,21 +102,22 @@ WantedBy=default.target
|
|
|
96
102
|
console.log("\nHost initialization complete!");
|
|
97
103
|
}
|
|
98
104
|
async restartDaemon() {
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
|
|
105
|
+
// If called from a user's terminal, save the current PATH for future use.
|
|
106
|
+
// If called from the daemon (auto-update), read the saved PATH instead.
|
|
107
|
+
if (process.stdin.isTTY) {
|
|
108
|
+
fs.mkdirSync(path.dirname(PATH_FILE), { recursive: true });
|
|
109
|
+
fs.writeFileSync(PATH_FILE, process.env.PATH || "", "utf-8");
|
|
110
|
+
}
|
|
102
111
|
const servicePath = path.join(UNIT_DIR, "palmier.service");
|
|
103
|
-
if (fs.existsSync(servicePath)) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
fs.writeFileSync(servicePath, updated, "utf-8");
|
|
113
|
-
execSync("systemctl --user daemon-reload", { encoding: "utf-8" });
|
|
112
|
+
if (fs.existsSync(servicePath) && fs.existsSync(PATH_FILE)) {
|
|
113
|
+
const userPath = fs.readFileSync(PATH_FILE, "utf-8").trim();
|
|
114
|
+
if (userPath) {
|
|
115
|
+
const content = fs.readFileSync(servicePath, "utf-8");
|
|
116
|
+
const updated = content.replace(/^Environment=PATH=.*/m, `Environment=PATH=${userPath}`);
|
|
117
|
+
if (updated !== content) {
|
|
118
|
+
fs.writeFileSync(servicePath, updated, "utf-8");
|
|
119
|
+
execSync("systemctl --user daemon-reload", { encoding: "utf-8" });
|
|
120
|
+
}
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
execSync("systemctl --user restart palmier.service", { stdio: "inherit" });
|
package/package.json
CHANGED
package/src/platform/linux.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { HostConfig, ParsedTask } from "../types.js";
|
|
|
9
9
|
const execAsync = promisify(exec);
|
|
10
10
|
|
|
11
11
|
const UNIT_DIR = path.join(homedir(), ".config", "systemd", "user");
|
|
12
|
+
const PATH_FILE = path.join(homedir(), ".config", "palmier", "user-path");
|
|
12
13
|
|
|
13
14
|
function getTimerName(taskId: string): string {
|
|
14
15
|
return `palmier-task-${taskId}.timer`;
|
|
@@ -70,6 +71,12 @@ export class LinuxPlatform implements PlatformService {
|
|
|
70
71
|
fs.mkdirSync(UNIT_DIR, { recursive: true });
|
|
71
72
|
|
|
72
73
|
const palmierBin = process.argv[1] || "palmier";
|
|
74
|
+
// Save the user's shell PATH so restartDaemon can use it later
|
|
75
|
+
// (the daemon itself runs under systemd with a limited PATH).
|
|
76
|
+
const userPath = process.env.PATH || "/usr/local/bin:/usr/bin:/bin";
|
|
77
|
+
fs.mkdirSync(path.dirname(PATH_FILE), { recursive: true });
|
|
78
|
+
fs.writeFileSync(PATH_FILE, userPath, "utf-8");
|
|
79
|
+
|
|
73
80
|
const serviceContent = `[Unit]
|
|
74
81
|
Description=Palmier Host
|
|
75
82
|
After=network-online.target
|
|
@@ -81,7 +88,7 @@ ExecStart=${palmierBin} serve
|
|
|
81
88
|
WorkingDirectory=${config.projectRoot}
|
|
82
89
|
Restart=on-failure
|
|
83
90
|
RestartSec=5
|
|
84
|
-
Environment=PATH=${
|
|
91
|
+
Environment=PATH=${userPath}
|
|
85
92
|
|
|
86
93
|
[Install]
|
|
87
94
|
WantedBy=default.target
|
|
@@ -113,23 +120,26 @@ WantedBy=default.target
|
|
|
113
120
|
}
|
|
114
121
|
|
|
115
122
|
async restartDaemon(): Promise<void> {
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
|
|
123
|
+
// If called from a user's terminal, save the current PATH for future use.
|
|
124
|
+
// If called from the daemon (auto-update), read the saved PATH instead.
|
|
125
|
+
if (process.stdin.isTTY) {
|
|
126
|
+
fs.mkdirSync(path.dirname(PATH_FILE), { recursive: true });
|
|
127
|
+
fs.writeFileSync(PATH_FILE, process.env.PATH || "", "utf-8");
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
const servicePath = path.join(UNIT_DIR, "palmier.service");
|
|
120
|
-
if (fs.existsSync(servicePath)) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
execSync("systemctl --user daemon-reload", { encoding: "utf-8" });
|
|
131
|
+
if (fs.existsSync(servicePath) && fs.existsSync(PATH_FILE)) {
|
|
132
|
+
const userPath = fs.readFileSync(PATH_FILE, "utf-8").trim();
|
|
133
|
+
if (userPath) {
|
|
134
|
+
const content = fs.readFileSync(servicePath, "utf-8");
|
|
135
|
+
const updated = content.replace(
|
|
136
|
+
/^Environment=PATH=.*/m,
|
|
137
|
+
`Environment=PATH=${userPath}`,
|
|
138
|
+
);
|
|
139
|
+
if (updated !== content) {
|
|
140
|
+
fs.writeFileSync(servicePath, updated, "utf-8");
|
|
141
|
+
execSync("systemctl --user daemon-reload", { encoding: "utf-8" });
|
|
142
|
+
}
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
145
|
execSync("systemctl --user restart palmier.service", { stdio: "inherit" });
|