-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
46 lines (39 loc) · 1.3 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
#!/usr/bin/env node
var startOnBoot = require('start-on-windows-boot');
var argv = require('yargs')
.usage('Usage: pm2-startup <command>')
.command('install', 'Adds a registry entry which resurrects PM2 on startup.')
.command('uninstall', 'Removes the registry entry which resurrects PM2 on startup.')
.demand(1)
.argv
._;
var applicationName = 'PM2';
var applicationCommand = 'wscript.exe "' + __dirname + '\\invisible.vbs" "' + __dirname + '\\pm2_resurrect.cmd"';
switch (argv[0]) {
case 'install':
enablePm2Startup();
break;
case 'uninstall':
removePm2Startup();
break;
}
function enablePm2Startup() {
startOnBoot.enableAutoStart(applicationName, applicationCommand, function (error) {
if (error) {
console.log('Error while trying to add PM2 startup registry entry: ' + error);
}
else {
console.log('Successfully added PM2 startup registry entry.');
}
});
}
function removePm2Startup() {
startOnBoot.disableAutoStart(applicationName, function (error) {
if (error) {
console.log('Error while trying to remove PM2 startup registry entry: ' + error);
}
else {
console.log('Successfully removed PM2 startup registry entry.');
}
});
}