-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
61 lines (47 loc) · 1.81 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const fs = require('fs');
const path = require('path');
const template = require('lodash.template');
const cli = require('ghost-cli');
const getUid = require('./get-uid');
class SupervisorExtension extends cli.Extension {
setup(cmd, argv) {
const instance = this.system.getInstance();
if (!argv.local && instance.config.get('process') === 'supervisor') {
cmd.addStage('supervisor', this._setup.bind(this), [], 'Supervisor');
}
}
async _setup(argv, ctx, task) {
const uid = getUid(ctx.instance.dir);
if (!uid) {
this.ui.log('The "ghost" user has not been created, please run `ghost setup linux-user` first', 'yellow');
return task.skip();
}
const fileBaseName = `${ctx.instance.name}`;
if (fs.existsSync(path.join('/etc/supervisor/conf.d', `${fileBaseName}.conf`))) {
this.ui.log('Supervisor has already been set up. Skipping Supervisor setup');
return task.skip();
}
const service = template(fs.readFileSync(path.join(__dirname, 'ghost.supervisor.template'), 'utf8'));
const contents = service({
name: fileBaseName,
dir: process.cwd(),
user: 'ghost',
environment: this.system.environment,
// eslint-disable-next-line camelcase
ghost_exec_path: process.argv.slice(0, 2).join(' ')
});
await this.template(ctx.instance, contents, 'supervisor config', `${fileBaseName}.conf`, '/etc/supervisor/conf.d');
await this.ui.sudo('supervisorctl update');
}
uninstall(instance) {
const serviceFilename = `/etc/supervisor/conf.d/${instance.name}.conf`;
if (fs.existsSync(serviceFilename)) {
return this.ui.sudo(`rm ${serviceFilename}`).catch(
() => Promise.reject(new cli.errors.SystemError('Supervisor config file link could not be removed, you will need to do this manually.'))
);
}
return Promise.resolve();
}
}
module.exports = SupervisorExtension;