-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraspberry-pi-config.js
More file actions
95 lines (83 loc) · 2.15 KB
/
Copy pathraspberry-pi-config.js
File metadata and controls
95 lines (83 loc) · 2.15 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use strict';
var commander = require('commander');
var exec = require('child_process').exec;
var installer = require('strong-service-install');
commander
.command('install')
.action(function () {
var opts = {
name: 'droplit-edge',
author: 'Droplit, Inc',
description: 'Droplit.io Edge Service',
user: process.env.USER,
command: 'node droplit-edge',
cwd: '/home/pi/droplit.io-edge',
systemd: true,
force: true
};
installer(opts, function (err, result) {
if (err) {
console.error('Failed to install service:', err.message);
process.exit(1);
} else {
console.log('Successfully installed service:', result);
process.exit(0);
}
});
});
commander
.command('reload-service')
.action(function () {
reloadService();
});
commander
.command('restart-service')
.action(function () {
restartService();
});
commander
.command('reboot')
.action(function () {
rebootSystem();
});
commander
.command('shutdown')
.action(function () {
shutdownSystem();
});
commander.parse(process.argv);
function runCommand(command, callback) {
console.log('running command:', command);
exec(command, function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
callback(error === null);
});
}
function reloadService() {
runCommand('sudo systemctl daemon-reload', function () {
setTimeout(function () {
restartService();
}, 1000);
});
}
function restartService() {
runCommand('sudo service droplit-edge restart', function (success) {
if (success) {
process.exit(0);
}
});
}
function rebootSystem() {
runCommand('sudo reboot', function () {
// nop
});
}
function shutdownSystem() {
runCommand('sudo poweroff', function () {
// nop
});
}