Richard
Now you’ve got SQLGrey running but you will want to have it start after a reboot as well, therefore the next job at hand is to create the startup scripts for a Leopard and Tiger installation.
Leopard
Create a file called ‘com.diymacserver.sqlgrey.plist‘ in the directory ‘/System/Library/LaunchDaemons/‘. The content of the file should look like:
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.diymacserver.sqlgrey</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/sqlgrey</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
To load and activate the .plist file and to make sure that it is started after a reboot you’ll need to load the plist file by using the command:
You can see if it loaded correctly by using the command:
This will show you all the active plist files.
You can see if everything went correctly by trying to start it using:
Tiger
Create a directory ‘SQLGrey‘ in the directory /Library/StartupItems‘.
sudo mkdir SQLGrey
Use your favourite editor to create the following files into your newly created directory. Please make sure you create them as root using the sudo command.
The first file is called ‘SQLGrey‘ and this is what its content should look like:
# SQLGrey startup item
# http://diymacserver.com
#
. /etc/rc.common
StartService ()
{
echo “Starting SQLGrey daemon”
/usr/sbin/sqlgrey -d
}
StopService ()
{
echo “Stopping SQLGrey daemon”
/usr/sbin/sqlgrey -k
}
RestartService ()
{
echo “Restarting SQLGrey daemon”
StopService
StartService
}
RunService “$1″
Set the executable bit on the script using:
The other file to create in this directory is ‘StartupParameters.plist‘, have it look like:
Description = “SQLGrey daemon”;
Provides = (“AGreylisting daemon”);
Uses = (“Disks”, “NFS”);
}
This should do it for you, you can now safely reboot and all will be fine when the mini has started again.



Comments
8:51 am
Why is there no KeepAlive key in the LaunchDaemons script? This seems important for SQLGrey, which can be a little flaky.
12:05 pm
Excellent point, I noticed the flakyness of sqlgrey on several occaions but was looking for other solutions. I completely missed this simple solution. I will give it a try on my test server to see if that would work.
4:43 pm
Thank you for all the good tips on this site. I am running sqlgrey on Tiger but the Startup item didn’t work although I got all permissions etc right as far as I can see.
I wonder why not use LaunchDaemons on Tiger, it supports it doesn’t it?
I also wonder if you tried the KeepAlive key in the Deamonscript yet, to my quite unpleasant surprice I discovered that Postfix rejects all incoming mail when SQLgrey does not run, I read in the documentation that if the SQL server stops working SQLgrey and postfix keeps delivering the mail (without the greylisting of course) and I somehow expected the same when SQLgrey was not running.
Thanks again!
5:21 pm
PS I saw now that under Tiger the KeepAlive key does not exist, but one could use OnDemand
instead if I understand correctly.
7:24 am
@Aryan, I’ve been troubled by this myself as well. I have not found a good solution yet. KeepAlive does not work as sqlgrey is spawning a daemon and ends causing the KeepAlive option to start a new instance every 10 seconds.
If I’ve found a working solution I will post it on the blog
8:16 am
Thank youfor your reply Richard. On http://archives.neohapsis.com/archives/postfix/2007-01/1083.html I see the suggestion to use a monitor utility called monit. It seems to work on Mac OSX as well http://monit.darwinports.com/ could that be a solution?
My other question was if there is any objection to use Launchd on Tiger to start SQLgrey in stead of a StartupItem?
8:58 am
Thanks for the pointer to monit, I will have a look at it.
There is no reason not to use the launchd on Tiger, at the time I wrote the stuff for Tiger i was not comfortable using launchd but Leopard forced me into it
8:41 am
I’ve got the KeepAlive option working, I just had to remove the -d option from the commandline. Instructions have been updated.
9:05 am
Great, thanks for letting us know! What exactly did you change? I use Tiger (and have a LaunchDeamon file for SQLgrey in /Library/LaunchDaemonns) and there is no KeepAlive in Tiger but OnDemand -> True should almost have the same effect.
Under the key ProgramArguments
I have an array with
string -> /usr/sbin/sqlgrey
string -> -d
Is that the -d opion you removed?
/Aryan
9:08 am
@Aryan, yes I removed the -d option. Still need to try this on Tiger, read the blog for more info.
8:23 pm
Followed your instructions for installation of sqlgrey and the launchdaemon plist file. Thank you very much. I have noticed a few anomalies since running from launchd as opposed to running it as its own daemon and wondered if anyone else noticed these, too:
1. The sqlgrey pid file (defaults to (/var/run/sqlgrey.pid) is not created.
2. Logging seems to be written to console.log and system.log as opposed to mail.log.
Neither seems to be destructive (the update_sqlgrey_config script can’t restart sqlgrey since it can’t find it’s pid file) and all seems to be working well.
Has anyone else noticed these things?
Thanks,
Bruce
9:05 am
@Bruce, thanks for mentioning this. I had not noticed this but will have a look at it to see if we can improve here.
2:50 pm
Thank you, Richard. When you start looking into it you might also notice that sqlgrey-logstats.pl no longer produces output as the log entries written to, in this case, system.log, are in a different format than when sqlgrey writes to mail.log. Therefore, sqlgrey-logstats.pl no longer recognizes the entries as coming from sqlgrey.
Merry XMAS / Happy New Year,
Bruce
5:06 pm
Hi Rich,
Hope you enjoyed a Merry XMas. Have you had a chance to look into the anomalies that I reported?
Would appreciate it.
Bruce
7:13 pm
To follow up on my earlier post of 24 Dec 09 wherein I reported a small anomaly regarding sqlgrey behavior when started from launchd…
The sqlgrey author decided that when sqlgrey is NOT started as a daemon it should log to STDOUT as opposed to syslog, the way we Mac users want it. A few small code edits will get sqlgrey back to logging to mail.log and creating its pid file.
Whether you’re using v1.6.8 or v1.7.6, load the sqlgrey executable into your favorite code editor.
1. To get logging back into mail.log, search for
log_file => $opt{daemonize} ? 'Sys::Syslog' : undef,and change it to
log_file => 'Sys::Syslog',2. To get sqlgrey to write it’s pid file, necessary to allow the update_sqlgrey_config script to force re-reading it’s config files, search for
pid_file => $opt{daemonize} ? $dflt{pidfile} : undef,and change it to
pid_file => $dflt{pidfile},Another benefit of the above code edits is that sqlgrey-logstats.pl will, once again, find its log entries in mail.log in the format that it is expecting.
Holler if you have any questions.
Happy New Decade to all!
Bruce