I have a problem trying to update a folder and deploy its contents again. I have to use NodeJS and have gotten port 8080 to work with. I have tried to create a php script (update.php):
<?php
echo exec("git pull");
echo exec("node app.js");
?>
Now i want to start the NodeJS script to update and the ultimate goal is to be able to restart the server.
I use the express module:
app.get('/Update', function(req,res) {
exec("php update.php", function(error, stdout, stderr) {
process.exit(0);
}
}
The problem is that the NodeJS server quits when it gets a response from the script but the script tries to start the NodeJS server. This obviously cannot happen since it is already running on the specified port.
Now i found on google to use the module called 'nodemon' however I am not given sudo access so installing this is out of the question. Other results are using
ps aux | grep node
kill -9 PROCESS_ID
This also yields problems since it is hard to configure the PHP script to kill the specified process but aside from that there are other NodeJS servers running in other child folders of the parent folder I am given. This means that if I'd use 'killall node' I'd get a lot of people angry that I killed their servers.
What is the best approach to solving this problem using only port 8080 and wanting to deploy the changes in the Github repo when accessing a certain link?