FAQ: Using the Scheduler with CGI Mode


How can I run Sawmill in CGI mode, and still use the Sawmill Scheduler?

Short Answer

Use an external Scheduler to run jobs or to call the Sawmill Scheduler, or run Sawmill in both CGI and web server modes.

Long Answer

Sawmill's built-in scheduler can only run scheduled jobs if Sawmill is actually running when the job's time comes. That's fine if you're running Sawmill in web server mode, where it runs all the time. But in CGI mode, Sawmill only runs when someone is actively using it, so scheduled tasks will not run. There are three main solutions to this problem: use an external scheduler to call Sawmill's scheduler, use an external scheduler to run the jobs directly, or run Sawmill on both CGI and web server modes, with the CGI mode doing everything but the scheduled jobs, and web server mode handling those.

UNIX

On UNIX, the most common scheduler is cron. You can set up cron to call Sawmill's scheduler by running the command (as root)

  crontab -e

from the UNIX command line, and then adding

  * * * * * sudo -u apache /full/path/to/sawmill -scheduler

to the resulting file. You will need to replace "apache" with the name of your CGI user, and you will need to replace /full/path/to/sawmill with the full pathname of your Sawmill executable. This tells cron tab to run Sawmill every minute, as the CGI user, with the -scheduler option (which tells Sawmill to run any scheduled jobs, and exit).

Another option is to run your Sawmill database builds and other jobs directly with cron; for instance you could add a line like this:

  0 0 * * * sudo -u apache /full/path/to/sawmill -p profilename -a ud

(replace "apache" with the name of your CGI user) to update the profile specified by configname every night at midnight (the first number is the minute of the hour when the job should be run; the second number is the hour when the job should be run, and * * * means to run it every day).

Yet another option is to run Sawmill in web server mode as well as CGI mode, with the web server mode instance running only for the purpose of running jobs. The two will not interfere with each other; just start Sawmill from the command line using

  /full/path/to/sawmill &

and it will continue to run until the next reboot. If you want Sawmill to automatically restart itself at system startup, see Running Sawmill at System Startup.

Windows

Unfortunately, Windows Scheduler does not let you run jobs every minute (like UNIX cron does), so you cannot use it to call the Sawmill Scheduler directly. However, other options are available. You can use the Windows Scheduler to run your Sawmill jobs directly. For instance, to set Sawmill to update the database for a particular profile every night, do this:

Now Windows Scheduler is configured to update your database automatically every day.

Another option is to run Sawmill in web server mode as well as CGI mode, with the web server mode instance running only for the purpose of running jobs. The two will not interfere with each other; just start Sawmill by double-clicking its icon (you can also configure it to start whenever your computer restarts, using Windows Scheduler), and scheduled jobs will run as long as Sawmill is running. If you need Sawmill to be running while you are logged out, see Running Sawmill as a Service.