Skip to content

Commit

Permalink
Merge pull request #2 from SagePtr/master
Browse files Browse the repository at this point in the history
Fix start/stop actions
  • Loading branch information
A1Gard authored May 22, 2019
2 parents b98ab06 + 3eb3c67 commit 2c22878
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
60 changes: 60 additions & 0 deletions pm2panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,66 @@ app.get('/restart', function (req, res) {
}
});

app.get('/start', function (req, res) {
// send json header
if (!req.session.islogin) {
res.writeHead(302, {
'Location': '/login'
});
res.end();

} else {
// check id exits
if (req.query.id) {
// start the process
exec("pm2 start " + req.query.id, (error, stdout, stderr) => {
res.writeHead(302, {
'Location': '/'
});
// req.session.notication = error + '\n--------\n' + stdout + '\n--------\n' + stderr;
if (error != null) {
req.session.notication = error + stderr;
} else {
req.session.notication = 'Process by id :' + req.query.id + ' started successfully';
}
res.end();
});

}

}
});

app.get('/stop', function (req, res) {
// send json header
if (!req.session.islogin) {
res.writeHead(302, {
'Location': '/login'
});
res.end();

} else {
// check id exits
if (req.query.id) {
// stop the process
exec("pm2 stop " + req.query.id, (error, stdout, stderr) => {
res.writeHead(302, {
'Location': '/'
});
// req.session.notication = error + '\n--------\n' + stdout + '\n--------\n' + stderr;
if (error != null) {
req.session.notication = error + stderr;
} else {
req.session.notication = 'Process by id :' + req.query.id + ' stopped successfully';
}
res.end();
});

}

}
});

app.get('/delete', function (req, res) {
// send json header
if (!req.session.islogin) {
Expand Down
4 changes: 2 additions & 2 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ <h2>
<a :href="'/delete?id='+process.pm_id" class="delete">
[ Delete ]
</a>
<a href="'/stop?id='+process.pm_id" v-if="process.pm2_env.status == 'online'">
<a :href="'/stop?id='+process.pm_id" v-if="process.pm2_env.status == 'online'">
[ Stop ]
</a>
<a href="'/start?id='+process.pm_id" v-else="">
<a :href="'/start?id='+process.pm_id" v-else="">
[ Start agin ]
</a>

Expand Down

0 comments on commit 2c22878

Please sign in to comment.