I have a simple script that tries to kill a running screen session, wait 5 seconds, then restart it. Trying to put this on a cron job, but having a weird issue. Here is the script:
#!/bin/bash
screen -S test -X quit
sleep 5
screen -dmS text node test.js
So the first time you run it, you get a "No session named test" error...that's fine. It then starts the session in detached mode and runs the node script.
The next time the script runs, it finds the session, issues the quit command and if you run 'screen -ls' the session is not listed.
However the program is still running...BUT, if you then open your browser and hit the site, the process then dies and you get an error that the service is no longer running...so the webserver stays running AFTER the session has been quit and only dies when you then try to access it via a web browser.
I'm testing all of this on Max OSX 10.9.5 (Mavericks)
I'm new to screen and am using it this way because I need to be able to attach to the remote server and monitor/manage the script via the console.
I've tried the following to issue a Ctrl-C command to the screen session to quit the program, but no luck:
screen -S text -X stuff "^C"
I need the be able to make sure the node script quits running when the session ends. Any direction would be appreciated. Thank you!