Skip to content

Commit 2f4f8d7

Browse files
committed
fix(ctl): handle exic codes on isActive and isEnabled
1 parent 91333a9 commit 2f4f8d7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/ctl/src/ctl.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ export function isActive(unitName: string, unit?: Unit) {
123123
const type = getType(unitName, unit);
124124
const name = getName(unitName);
125125

126-
return execSync(`systemctl is-active ${name}.${type}`).toString().trim() === "active";
126+
try {
127+
return execSync(`systemctl is-active ${name}.${type}`).toString().trim() === "active";
128+
}
129+
catch {
130+
return false;
131+
}
127132
}
128133

129134
export function isEnabled(unitName: string, unit?: Unit) {
130135
const type = getType(unitName, unit);
131136
const name = getName(unitName);
132137

133-
return execSync(`systemctl is-enabled ${name}.${type}`).toString().trim() === "enabled";
138+
try {
139+
return execSync(`systemctl is-enabled ${name}.${type}`).toString().trim() === "enabled";
140+
}
141+
catch {
142+
return false;
143+
}
134144
}
135145

136146
export function daemonReload() {
@@ -171,6 +181,9 @@ export class Ctl {
171181
}
172182
}
173183

184+
/**
185+
* Enabled Unit will be started on next boot
186+
*/
174187
public enable() {
175188
execSync(`systemctl enable ${this.name}.${this.type}`);
176189
}

0 commit comments

Comments
 (0)