Added ability to restart the server from the frontend

Dockerfile/entrypoint.sh now uses nodemon enabling restarting from the UI in a container
pull/360/head
Isaac Abadi 4 years ago
parent 1f0153b17e
commit 4643efbae0

@ -40,4 +40,4 @@ COPY --chown=$UID:$GID [ "/backend/", "/app/" ]
EXPOSE 17442
ENTRYPOINT [ "/app/entrypoint.sh" ]
CMD [ "node", "app.js" ]
CMD [ "npm", "start" ]

@ -142,15 +142,17 @@ var timestamp_server_start = Date.now();
if (debugMode) logger.info('YTDL-Material in debug mode!');
// check if just updated
const just_restarted = fs.existsSync('restart.json');
if (just_restarted) {
const just_updated = fs.existsSync('restart_update.json');
if (just_updated) {
updaterStatus = {
updating: false,
details: 'Update complete! You are now on ' + CONSTS['CURRENT_VERSION']
}
fs.unlinkSync('restart.json');
fs.unlinkSync('restart_update.json');
}
if (fs.existsSync('restart_general.json')) fs.unlinkSync('restart_general.json');
// updates & starts youtubedl (commented out b/c of repo takedown)
// startYoutubeDL();
@ -332,7 +334,7 @@ async function startServer() {
});
}
async function restartServer() {
async function restartServer(is_update = false) {
const restartProcess = () => {
spawn('node', ['app.js'], {
detached: true,
@ -340,10 +342,11 @@ async function restartServer() {
}).unref()
process.exit()
}
logger.info('Update complete! Restarting server...');
logger.info(`${is_update ? 'Update complete! ' : ''}Restarting server...`);
// the following line restarts the server through nodemon
fs.writeFileSync('restart.json', 'internal use only');
fs.writeFileSync(`restart${is_update ? '_update' : '_general'}.json`, 'internal use only');
}
async function updateServer(tag) {
@ -386,7 +389,7 @@ async function updateServer(tag) {
updating: true,
'details': 'Update complete! Restarting server...'
}
restartServer();
restartServer(true);
}, err => {
updaterStatus = {
updating: false,
@ -1898,7 +1901,11 @@ app.post('/api/setConfig', optionalJwt, function(req, res) {
logger.error('Tried to save invalid config file!')
res.sendStatus(400);
}
});
app.post('/api/restartServer', optionalJwt, (req, res) => {
restartServer();
res.send({success: true});
});
app.post('/api/tomp3', optionalJwt, async function(req, res) {

@ -1,7 +1,7 @@
#!/bin/sh
set -eu
CMD="node app.js"
CMD="npm start"
# if the first arg starts with "-" pass it to program
if [ "${1#-}" != "$1" ]; then

@ -14,7 +14,8 @@
"public/*"
],
"watch": [
"restart.json"
"restart_update.json",
"restart_general.json"
]
},
"repository": {

@ -199,6 +199,10 @@ export class PostsService implements CanActivate {
return this.http.post(this.path + 'killAllDownloads', {}, this.httpOptions);
}
restartServer() {
return this.http.post(this.path + 'restartServer', {}, this.httpOptions);
}
loadNavItems() {
if (isDevMode()) {
return this.http.get('./assets/default.json');

@ -353,6 +353,14 @@
<div *ngIf="new_config" class="container-fluid mt-1">
<app-updater></app-updater>
</div>
<mat-divider></mat-divider>
<div *ngIf="new_config" class="container">
<div class="row">
<div class="col-12 mt-4">
<button (click)="restartServer()" mat-stroked-button color="warn"><ng-container i18n="Restart server button">Restart server</ng-container></button>
</div>
</div>
</div>
</ng-template>
</mat-tab>
<mat-tab *ngIf="postsService.config && postsService.config.Advanced.multi_user_mode" label="Users" i18n-label="Users settings label">

@ -255,6 +255,14 @@ export class SettingsComponent implements OnInit {
});
}
restartServer() {
this.postsService.restartServer().subscribe(res => {
this.postsService.openSnackBar('Restarting!');
}, err => {
this.postsService.openSnackBar('Failed to restart the server.');
});
}
// snackbar helper
public openSnackBar(message: string, action: string = '') {
this.snackBar.open(message, action, {

Loading…
Cancel
Save