4 months ago
I'm deploying a node js project, and am having issues getting it to shut down gracefully.
My start command is invoking my transpiled src directly. I'm using the nixpack defaults."start": "node ./dist/index.js",
And I'm listening for the `SIGTERM` eventprocess.on('SIGTERM', async () => {
logger.info('SIGTERM received, shutting down');
await applicationWillShutdown(container);
httpServer.close(() => {
logger.info('HTTP server closed');
});
});
httpServer.listen(PORT, async () => {
await applicationDidStart(container);
logger.info(`Started server on ${PORT}
`);
});
But I get the following on container shutdownnpm error path /app
npm error command failed
npm error signal SIGTERM
npm error command sh -c node ./dist/index.js
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-02-04T13_58_24_084Z-debug-0.log
npm warn config production Use --omit=dev instead.
The `SIGTERM received, shutting down` message is never sent.
Any idea on what I could be missing? The `/app` directory in the error makes me think it could be something inside the nixpack that either don't understand or haven't configured.
Any help would be appreciated.
Thanks
Small sidenote, the "Learn more" link below the "Make thread visible to railway team only" text on the form that you use to create these threads goes to google.com. Guessing that one slipped by QA
4 Replies
4 months ago
You will need to exit with process 0, not just SIGTERM (afaik)
(Also will fix that on the form!)
Status changed to Awaiting User Response railway[bot] • 4 months ago
4 months ago
Hello,
The reason why you are seeing that error is because you are running your app via npm, and npm is not passing down the signal correctly.
Fortunately the solution is simple, within the service settings, set the start command to node ./dist/index.js
so that your index.js file is ran directly with node and not through npm.
Best,
Brody
brody
Hello,The reason why you are seeing that error is because you are running your app via npm, and npm is not passing down the signal correctly.Fortunately the solution is simple, within the service settings, set the start command to node ./dist/index.js so that your index.js file is ran directly with node and not through npm.Best,Brody
4 months ago
I was under the impresssion that my start cmd was good, but now that I think about it, how else would I start the app. Thanks
Status changed to Awaiting Railway Response railway[bot] • 4 months ago
Status changed to Awaiting User Response railway[bot] • 4 months ago
Status changed to Solved brody • 4 months ago