Frequently Asked Questions

The NearlyFreeSpeech.NET FAQ (*)

Customization (*)

Q. What is a run script?

If you configure a site type that supports arbitrary daemon processes, the infrastructure that initializes them does not process command line arguments. In the rare case that you don't need any, you can run the daemon executable directly from the 'Command' field of the Daemon management interface. In all other cases, you will need a run script.

A run script is a short shell script that lets you customize the environment for your daemon without worrying about the massive stack of stuff we have to do to make sure your daemon runs in the context of your site. A typical, minimal run script is an executable file that looks like this:

#!/bin/sh
exec /home/protected/bin/mydaemon.py --port=12345 --run-in-foreground

(The above is a fictional example; it is not a valid command. You will have to customize it for however your specific process specifies what port to use and to stay in the foreground.)

Then, you enter the path to the run script as the command in your daemon configuration. This lets you customize the daemon's command line arguments. You can also take other actions if needed, like setting environment variables, removing temporary files from previous runs, running preflight database checks, etc.

When writing run scripts, always make sure the following key elements are present:

  1. The shebang line is the first line of the run script. (#!/bin/sh)
  2. The exec command in front of the daemon executable. (Saves RAM = lower costs, may also avoid problems with signal delivery.)
  3. The daemon process must run in the foreground. (Otherwise it will be repeatedly killed and restarted.)
  4. Starting the daemon is the last line in the run script. (Anything after that will almost never be run.)
  5. Executable permissions on the run script. (chmod a+x myrun.sh)