Running the Service

The twistd Command

Twisted provides a utility - twistd - which allows any twisted program to be run as a service. The program handles starting and stopping as well as many other options. The most important are documented below; with the full listing available on twistd’s man page

-n, --nodaemon

Force twistd to run in the foreground.

--pidfile <pidfile>

Outputs the PID of the process to this file. The default file is twistd.pid

-d, --rundir <directory>

Use this to define the directory to run out off. Note that this should be specified when twistd is run using root and the program is not in the python path(When running as root, the current directory is not included in the python path).

-y, --python <python file>

Indicates that the application variable should be taken from the python file(once it is imported) and used as the root service.

Running the Manager

The following command will run the manager in the foreground.

$ twistd --pidfile manager.pid --nodaemon --python manager.py

Remove the --nodaemon option to daemonise the service. Then to kill the daemonised manager run:

$ kill `cat manager.pid`