Jgreylist-clean from Runwhen

jgreylist-clean , created by John Simpson is "perl script which scans the greylist directory, removes the files for any IP addresses which have not connected for some length of time (default 30 days), and removes any empty directories." [1] A person uses this in conjunction with jgreylist. John demonstrates running the script from a cron job. However there are other methods from which to run jgreylist-clean.

Runwhen and uschedule are two replacements for crond built on the principles of Dan J Berstein's (djb) software design. While uschedule more resembles cron, runwhen can cover the functionalities need to run jgreylist-clean.


Installing Runwhen

To use runwhen, the following pieces of software need to be installed in order according to their instructions:

  1. skalibs
  2. fdtools
  3. runwhen

The beauty of runwhen is service creation greatly resembles the creation of services under daemontools.


Setting up the Service Directories

First verify the daemontools "svscan" process is running. Choose a location where you want the physical service directories. I usually use "/var/service", however any directory may be used as long as it is not "/service".

Create the service directories with the following commands.

# mkdir -m 1755 /var/service/jgreylist-clean
# mkdir -m 755 /var/service/jgreylist-clean/log

Download the jgreylist-clean script, the runwhen scripts and the log run scripts.

# cd /usr/local/sbin/
# wget -c http://qmail.jms1.net/scripts/jgreylist-clean
# chmod 755 jgreylist-clean
# cd /var/service/jgreylist-clean
# touch started finished
# wget -c http://www.antagonism.org/scripts/dojgreylist-clean
# wget -c http://www.antagonism.org/scripts/jgreylist-clean-run
# mv jgreylist-clean-run run
# chmod 755 run
# cd log
# wget -c http://www.antagonism.org/scripts/log-run
# chmod 755 run

Warning, before using any of the runwhen scripts, make sure you understand what the commands do. An example similar to dogreylist-clean complete with line by line description is available here. The "log" run script rotates the logs every 1MB, keeps the latest 20 logs and writes them to the "main" directory under the "log" directory.


Activating the Service

(The below section is taken almost verbatim from the following page created by John Simpson. I felt that his description on what happens when you activate a service was the most clear and easy to understand, so why change a thing?)

Once the directories are set up, you need to make them start running. This is done by creating a symbolic link from /service/(whatever) to the physical directory where the service lives. The "svscan" program checks /service every five seconds, and when it sees a new directory (or symbolic link) there, it starts a "supervise" process for that directory. In addition, if the directory has the sticky bit set and a child directory called "log", it starts a "supervise" process for the "log" child directory and sets up a pipe between the two processes (so that the main process's logs end up being sent to the log process).

The "supervise" program works by running the "run" script inside of whatever directory it's watching. If that child process (either the "run" script itself, or whatever process it runs using "exec") stops, it starts it back up by running the "run" script again.

The following commands will create the symbolic links needed to start the jgreylist-clean service.

# ln -s /var/service/jgreylist-clean /service/

After running this command, wait ten seconds (to give it time to start) and then run the "svstat" command to see what's running:

# svstat /service/jgreylist-clean /service/jgreylist-clean/log
/service/jgreylist-clean: up (pid 7112) 7 seconds
/service/jgreylist-clean/log: up (pid 7114) 7 seconds

As long as the new services show "up" with a timer of more than one second, the services are running correctly. If the timer on a service is 0 or 1 second, then wait about five seconds and run the same command - it should now be higher than 1 second. If it's still 0 or 1, then the service is having a problem and you need to fix it. This page provides some steps to troubleshoot daemontools service installations.


Downloads

File: dojgreylist-clean
Size: 79 bytes
Date: 2008-05-02 14:49:56 -0700
MD5: dd4860d5554e701b84b2f6744453ebb0
SHA-1: e4a4f3d2f26e1fac6efa62b28def068fa04c2879
RIPEMD-160: e9c99f88423ba602b511b22c229ec7bd6bb9f71e
PGP Signature: dojgreylist-clean.asc
File: jgreylist-clean-run
Size: 376 bytes
Date: 2008-05-02 14:49:56 -0700
MD5: 56dacc74d550f56eb8512b88b355f60f
SHA-1: e43b084c58a6eb6a7130381cb3581198b34527ff
RIPEMD-160: cf4daf0983c9e8d0780ea20253d8a5a0a865bb12
PGP Signature: jgreylist-clean-run.asc
File: log-run
Size: 47 bytes
Date: 2008-05-02 14:49:56 -0700
MD5: 1cc7ef3d56be3ec766a9b382d19d1604
SHA-1: d04a2286a41bddd77577443253ac67654f0b7425
RIPEMD-160: 4df90694ac5cb454b6e360c69278e244c6cdf924
PGP Signature: log-run.asc