|
3 | 3 | const fs = require('fs');
|
4 | 4 | const execa = require('execa');
|
5 | 5 | const cli = require('../../lib');
|
| 6 | +const getUid = require('./get-uid'); |
6 | 7 |
|
7 | 8 | class SystemdProcessManager extends cli.ProcessManager {
|
8 | 9 | get systemdName() {
|
9 | 10 | return `ghost_${this.instance.name}`;
|
10 | 11 | }
|
11 | 12 |
|
12 | 13 | start() {
|
13 |
| - if (!this._precheck()) { |
14 |
| - return Promise.reject( |
15 |
| - new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup systemd` and try again.') |
16 |
| - ); |
17 |
| - } |
| 14 | + this._precheck(); |
18 | 15 |
|
19 | 16 | return this.ui.sudo(`systemctl start ${this.systemdName}`)
|
20 | 17 | .catch((error) => Promise.reject(new cli.errors.ProcessError(error)));
|
21 | 18 | }
|
22 | 19 |
|
23 | 20 | stop() {
|
24 |
| - if (!this._precheck()) { |
25 |
| - return Promise.reject( |
26 |
| - new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup systemd` and try again.') |
27 |
| - ); |
28 |
| - } |
| 21 | + this._precheck(); |
29 | 22 |
|
30 | 23 | return this.ui.sudo(`systemctl stop ${this.systemdName}`)
|
31 | 24 | .catch((error) => Promise.reject(new cli.errors.ProcessError(error)));
|
32 | 25 | }
|
33 | 26 |
|
34 | 27 | restart() {
|
35 |
| - if (!this._precheck()) { |
36 |
| - return Promise.reject( |
37 |
| - new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup systemd` and try again.') |
38 |
| - ); |
39 |
| - } |
| 28 | + this._precheck(); |
40 | 29 |
|
41 | 30 | return this.ui.sudo(`systemctl restart ${this.systemdName}`)
|
42 | 31 | .catch((error) => Promise.reject(new cli.errors.ProcessError(error)));
|
@@ -82,17 +71,23 @@ class SystemdProcessManager extends cli.ProcessManager {
|
82 | 71 | }
|
83 | 72 |
|
84 | 73 | _precheck() {
|
| 74 | + let uid = getUid(this.instance.dir); |
| 75 | + |
| 76 | + if (!uid) { |
| 77 | + throw new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup linux-user systemd` and try again.') |
| 78 | + } |
| 79 | + |
85 | 80 | if (this.instance.cliConfig.get('extension.systemd', false)) {
|
86 |
| - return true; |
| 81 | + return; |
87 | 82 | }
|
88 | 83 |
|
89 | 84 | // service file exists but for some reason the right property in cliConfig hasn't been set
|
90 | 85 | if (fs.existsSync(`/lib/systemd/system/${this.systemdName}.service`)) {
|
91 | 86 | this.instance.cliConfig.set('extension.systemd', true);
|
92 |
| - return true; |
| 87 | + return; |
93 | 88 | }
|
94 | 89 |
|
95 |
| - return false; |
| 90 | + throw new cli.errors.SystemError('Systemd process manager has not been set up. Run `ghost setup systemd` and try again.'); |
96 | 91 | }
|
97 | 92 |
|
98 | 93 | static willRun() {
|
|
0 commit comments