mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-26 06:30:58 +03:00
Added ability to restart the server from the frontend
Dockerfile/entrypoint.sh now uses nodemon enabling restarting from the UI in a container
This commit is contained in:
@@ -40,4 +40,4 @@ COPY --chown=$UID:$GID [ "/backend/", "/app/" ]
|
|||||||
|
|
||||||
EXPOSE 17442
|
EXPOSE 17442
|
||||||
ENTRYPOINT [ "/app/entrypoint.sh" ]
|
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!');
|
if (debugMode) logger.info('YTDL-Material in debug mode!');
|
||||||
|
|
||||||
// check if just updated
|
// check if just updated
|
||||||
const just_restarted = fs.existsSync('restart.json');
|
const just_updated = fs.existsSync('restart_update.json');
|
||||||
if (just_restarted) {
|
if (just_updated) {
|
||||||
updaterStatus = {
|
updaterStatus = {
|
||||||
updating: false,
|
updating: false,
|
||||||
details: 'Update complete! You are now on ' + CONSTS['CURRENT_VERSION']
|
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)
|
// updates & starts youtubedl (commented out b/c of repo takedown)
|
||||||
// startYoutubeDL();
|
// startYoutubeDL();
|
||||||
|
|
||||||
@@ -332,7 +334,7 @@ async function startServer() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restartServer() {
|
async function restartServer(is_update = false) {
|
||||||
const restartProcess = () => {
|
const restartProcess = () => {
|
||||||
spawn('node', ['app.js'], {
|
spawn('node', ['app.js'], {
|
||||||
detached: true,
|
detached: true,
|
||||||
@@ -340,10 +342,11 @@ async function restartServer() {
|
|||||||
}).unref()
|
}).unref()
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
logger.info('Update complete! Restarting server...');
|
|
||||||
|
logger.info(`${is_update ? 'Update complete! ' : ''}Restarting server...`);
|
||||||
|
|
||||||
// the following line restarts the server through nodemon
|
// 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) {
|
async function updateServer(tag) {
|
||||||
@@ -386,7 +389,7 @@ async function updateServer(tag) {
|
|||||||
updating: true,
|
updating: true,
|
||||||
'details': 'Update complete! Restarting server...'
|
'details': 'Update complete! Restarting server...'
|
||||||
}
|
}
|
||||||
restartServer();
|
restartServer(true);
|
||||||
}, err => {
|
}, err => {
|
||||||
updaterStatus = {
|
updaterStatus = {
|
||||||
updating: false,
|
updating: false,
|
||||||
@@ -1898,7 +1901,11 @@ app.post('/api/setConfig', optionalJwt, function(req, res) {
|
|||||||
logger.error('Tried to save invalid config file!')
|
logger.error('Tried to save invalid config file!')
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/restartServer', optionalJwt, (req, res) => {
|
||||||
|
restartServer();
|
||||||
|
res.send({success: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/tomp3', optionalJwt, async function(req, res) {
|
app.post('/api/tomp3', optionalJwt, async function(req, res) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
CMD="node app.js"
|
CMD="npm start"
|
||||||
|
|
||||||
# if the first arg starts with "-" pass it to program
|
# if the first arg starts with "-" pass it to program
|
||||||
if [ "${1#-}" != "$1" ]; then
|
if [ "${1#-}" != "$1" ]; then
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
"public/*"
|
"public/*"
|
||||||
],
|
],
|
||||||
"watch": [
|
"watch": [
|
||||||
"restart.json"
|
"restart_update.json",
|
||||||
|
"restart_general.json"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -199,6 +199,10 @@ export class PostsService implements CanActivate {
|
|||||||
return this.http.post(this.path + 'killAllDownloads', {}, this.httpOptions);
|
return this.http.post(this.path + 'killAllDownloads', {}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restartServer() {
|
||||||
|
return this.http.post(this.path + 'restartServer', {}, this.httpOptions);
|
||||||
|
}
|
||||||
|
|
||||||
loadNavItems() {
|
loadNavItems() {
|
||||||
if (isDevMode()) {
|
if (isDevMode()) {
|
||||||
return this.http.get('./assets/default.json');
|
return this.http.get('./assets/default.json');
|
||||||
|
|||||||
@@ -353,6 +353,14 @@
|
|||||||
<div *ngIf="new_config" class="container-fluid mt-1">
|
<div *ngIf="new_config" class="container-fluid mt-1">
|
||||||
<app-updater></app-updater>
|
<app-updater></app-updater>
|
||||||
</div>
|
</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>
|
</ng-template>
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
<mat-tab *ngIf="postsService.config && postsService.config.Advanced.multi_user_mode" label="Users" i18n-label="Users settings label">
|
<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
|
// snackbar helper
|
||||||
public openSnackBar(message: string, action: string = '') {
|
public openSnackBar(message: string, action: string = '') {
|
||||||
this.snackBar.open(message, action, {
|
this.snackBar.open(message, action, {
|
||||||
|
|||||||
Reference in New Issue
Block a user