PhpTaskDaemon: Configuring, starting and monitoring the daemon

Last post I talked about the defining Tasks using the abstract Task class of the PhpTaskDaemon project. I also provided a simple example task implementation. This time I will go into how the daemon can be started, stopped and monitored. Although most of the options are already implemented and available in the develop repository of the project, some are still on the todo list. (specifying command line options such as a different configuration and log file.

The command line utility
The command line utility provided by PhpTaskDaemon is used to start, stop and request the status of the daemon. The following command shows the help message of the PhpTaskDaemon daemon.

{code}
./bin/phptaskdaemon –help
Usage: daemontaskdaemon [ options ]
–config|-c [ <string> ]  Configuration file (defaults: /etc/{name}.conf, {cwd}/application/config/{name}.ini)
–logfile|-l [ <string> ] Log file (defaults /var/log/{name}.log, {tmpdir}/{name}.log)
–tmpdir [ <string> ] Temp directory (defaults {cwd}/tmp/ or /tmp/)
–taskdir [ <string> ] Task directory (defaults {cwd}/application/daemon/)
–daemonize|-d            Run in Daemon mode (default) (fork to background)
–action|-a <string>      Action (default: start) (options: start, stop, restart, status, monitor)
–verbose|-v              Verbose
–help|-h                 Show help message (this message)
{/code}

Starting and stopping the daemon
The command below starts the daemon in verbose mode. Stopping and restarting the daemon can be done by replacing the action with stop or restart.

{code}
./bin/phptaskdaemon –verbose –action start
{/code}

A default init script is provided to start the daemon each time the host computer boots. Edit the path of the daemon executable and save it as /etc/init.id/plugweb.

Monitoring the daemon
The PhpTaskDaemon library also provides capabilities to monitor the activities of running task managers. The current activities of a running instance can be viewed using the status or monitor action. The status action displays the current managers and their activities once, while the monitor action displays and refreshes the status continuously. Use the following line to start the monitor function:

{code}
./bin/phptaskdaemon –action monitor
{/code}

Configuring the daemon
The daemon reads a configuration file with global options and manager specific options. By default the daemon reads the following configuration file: ‘application/config/phptaskdaemon.ini. It contains the locations of the logfile and temp directory. It can override manager specific properties such as the amount of forked processes to run for a particular task. See below for an example configuration file (docs/files/phptaskdaemon.ini-dist).

Overriding configuration options with the command line
Command line arguments override the options in the configuration file. The locations of the log and configuration file, the log verbosity and the locations of the temp and task directories can be overridden on the command line. An example is shown below using the properties listed above and also limits the gearman and forked managers to spawn 3 processes at maximum.

{code}
./bin/phptaskdaemon \
–log custom.log \
–config custom.ini \
–verbose 9 \
–task-dir tasks/ \
–tmp-dir tmp/ \
–max-workers 3 \
–max-forks 3
{/code}

Running a single action once
It is also possible to run a single action once, so it can be easy integrated within other systems (such as triggering a single task by the linux cron itself).

{code}
./phptaskdaemon –once –task Example
{/code}

Installing the init script
The PhpTaskDaemon project provides an init script for starting the daemon at every boot. The daemon also responses on posix signals, which means it shuts down nicely. Installing the init script is easy by copying the default init script to your /etc/init.d directory. You need to specify the path of your application in the init script.

{code type=bash}
cp docs/files/initscript-dist /etc/init.d/<projectname>
edit /etc/init.d/<projectname>
{/code}

Displaying the daemon status on a website
The daemon class can be used to request status information of the daemon activities. A sample implementation of displaying the daemon status through web is provided in a seperate sub project: PhpTaskDaemon-WebStatus. The web application consisting of a single controller and a view script for a zend framework application. To install it you will need to edit and copy the docs/files/apache.conf to your apache directory.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Share/Bookmark
This entry was posted in Algemeen, PhpTaskDaemon, Projects and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *