-
Notifications
You must be signed in to change notification settings - Fork 0
/
installService.js
59 lines (47 loc) · 1.3 KB
/
installService.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
const path = require('path');
const fs = require('fs');
const os = require("os");
const { execSync } = require('child_process');
if(process.platform != "linux"){
return console.error('This command work only on linux');
}
if(os.userInfo().uid !== 0){
return console.error('This command must be run with sudo');
}
const servicePath = '/etc/systemd/system/backMeUp.service';
const enableService = () => {
execSync('systemctl enable backMeUp', {stdio: 'inherit'});
};
let userExist = true;
try{
execSync('id backmeup');
}catch(e){
userExist = false;
}
if(userExist){
console.log('user "backmeup" already exist, skip creation');
}else{
execSync('useradd backmeup');
console.log('user "backmeup" created');
}
if(fs.existsSync(servicePath)){
console.log('backMeUp Service already present');
}else{
const serviceText = `[Unit]
Description=automatic backup service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=3
User=backmeup
ExecStart=/usr/bin/env node "${path.join(__dirname, 'main.js')}"
[Install]
WantedBy=multi-user.target`;
fs.writeFileSync(servicePath, serviceText);
}
enableService();
console.log('All done');
console.log('Make sure user "backmeup" has read and write access to backup directory');
console.log('reboot system or run "systemctl start backMeUp"');