Skip to content

Commit

Permalink
cli: implement /shutdown endpoint (spec-undocumented)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Jul 16, 2020
1 parent 102820f commit 36efe62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions raiden-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ function createLocalStorage(name: string): LocalStorage {
return localStorage;
}

function shutdown(this: Cli): void {
function shutdownServer(this: Cli): void {
if (this.server?.listening) {
this.log.info('Closing server...');
this.server.close();
}
}

function shutdownRaiden(this: Cli): void {
if (this.raiden.started) {
this.log.info('Stopping raiden...');
this.raiden.stop();
Expand All @@ -86,8 +88,10 @@ function shutdown(this: Cli): void {
}

function registerShutdownHooks(this: Cli): void {
process.on('SIGINT', shutdown.bind(this));
process.on('SIGTERM', shutdown.bind(this));
// raiden shutdown triggers server shutdown
this.raiden.state$.subscribe(undefined, shutdownServer.bind(this), shutdownServer.bind(this));
process.on('SIGINT', shutdownRaiden.bind(this));
process.on('SIGTERM', shutdownRaiden.bind(this));
}

async function main() {
Expand Down
5 changes: 5 additions & 0 deletions raiden-cli/src/routes/api.v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ export function makeApiV1Router(this: Cli): Router {
});
});

router.post('/shutdown', (_request: Request, response: Response) => {
this.raiden.stop();
response.json({ status: 'shutdown' });
});

return router;
}

0 comments on commit 36efe62

Please sign in to comment.