-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (34 loc) · 1.31 KB
/
index.js
File metadata and controls
41 lines (34 loc) · 1.31 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
const express = require('express');
const { exec, spawn } = require('child_process');
const path = require('path');
const app = express();
const PORT = 5000;
app.post('/update', async (req, res) => {
try {
const update = await exec('sudo git pull --rebase', { cwd: '/home/pjlangsam/Redwood' });
const restart = await spawn('pm2', ['restart', '1']);
// update.stdout.on('data', (data) => console.log(`${data}`))
// update.stderr.on("data", data => console.log(`${data}`));
// update.on('close', async () => {
// console.log('Update Done');
// const restart = await spawn('pm2', ['restart', '1']);
restart.on('close', () => {
console.log('Restarting!');
res.status(200).send({ success: true })
})
// })
} catch (err) {
res.status(400).send({ error: `Error pulling and restarting bot ${err}`})
}
})
app.post('/kick', async(req, res) => {
try {
const restart = await spawn('pm2', ['restart', '1']);
restart.on('close', () => res.status(200).send({ success: true }))
} catch (err) {
res.status(400).send({ error: `Error pulling and restarting bot ${err}`})
}
})
app.listen(PORT, () => {
console.log(`Running on port: ${PORT}`)
})