I'm writing an application that will run as a daemon on ubuntu 14.04. The purpose of this daemon is to run a for loop that will check for data in various database tables and if data is present it will spawn a goroutine to take various actions on various data. This is done to allow me doing tasks more often than cron allows me to schedule tasks.
An example would be if the daemon found a new row in the database table "notifications" it would spawn a new goroutine that would run until it's done, which in this case would mean running the command below:
err := exec.Command("sh","-c","php /var/app/send_notification.php").Run()
Yes. I've the need to execute some php scripts from go. I don't have the time allotted to rewrite all the php code in go just yet so I'll have to make this work somehow.
I've managed to write the daemon so it will do a mostly graceful shutdown if SIGINT is sent to it. It will let all goroutines complete their tasks so that no work is stopped halfway through which may end up causing problems.
The problem is now that as soon as SIGINT is sent to this daemon, any and all processes started by the exec.Command() is aborted right away.
http://rcrowley.org/articles/golang-graceful-stop.html
The link above is what I've used as a template for this daemon.
So my question is: Is there any way to allow an exec.Command() started in a goroutine to run until completion when the daemon receives SIGINT? If not, is there another way to go about executing a command from go and allowing it to run until completion after SIGINT is received by the daemon?