in reply to CGI Process Control

Unless the cron job that starts the morning news stream is owned by the same user account that is running httpd on that machine, a CGI process to kill the playback would need root privilege (or at least appropriate sudo permission). And as a web-based interface, that is not an attractive solution.

My first inclination would be to tailor the cron job so that it not only launches the audio stream player, but also watches (say, at 1 or 2 sec intervals) for the presence of a "stop.playback" file in some designated path. (This means the playback has to be launched as a background process, so the main script being run by cron can continue to operate.) Then the web interaction simply consists of creating the "stop.playback" file on demand, and the cron job script, on seeing this file, kills its child playback process, deletes the file, and exits.

(update: assuming it can happen that the child playback finishes normally (or can be said to be "done") before some unrelated CGI action creates the "stop.playback" file, the cron script would need to check for this condition as well, and exit. You probably don't want today's instance to still be running when cron starts tomorrow's instance.)

Replies are listed 'Best First'.
Re^2: CGI Process Control
by SkipHuffman (Monk) on Dec 26, 2007 at 13:53 UTC

    Typically the user of CGI is "nobody" right? Can "nobody" run a cron job? I did add some code to my CGI to shut down the sound, and it works fine on streams started from Apache, but as you implied, the cron started stream is unaffected.

    I don't like polling for a file, seems inelegant. Rather have a push process.

    The stream that I run from cron is permanent(or nearly so). It is the feed from my local NPR station, plays news until 9:00, then goes into really bad classical music, probably until 4:00.

    Edit: Ok, answered my own question. Yes, "nobody" appears to be able to run a cron job. I moved my timed feed to be owned by "nobody" (discovered that I had to su into root, then from root to nobody). Hopefully I will be able to take better control now.

    Skip