Issue
I have a nodejs server which will be started using nohup. So basically it will not have stdin.
I have created daemon for my nodejs server which does all start stop restart status functions.
But I dont want to stop the nodejs server immediately. I want to stop it after certain tasks. So I have to send command to the server's stdin. So that shutdown will be controlled by the server itself. Yes I can do that by creating a API. But its my last option.
Yes my server takes input from stdin and its working well. But using nohup I will not have stdin therefore no way to enter command in that case.
So my question is, if there is a way so that I can change the stdin to other file and my server will take input from it in the same way it does in case of stdin.
Solution
If you are in Linux or Mac you can send signals to your server process. In Windows you can too but I don't know the command.
For example if you want to reload your server you can do
kill -s SIGUSR2 processId
And in your server
process.on('SIGUSR2', function() {
console.log('Got SIGUSR2, reloading server...');
});
Answered By - Gaston Sanchez Answer Checked By - Candace Johnson (WPSolving Volunteer)