なんだこれは

はてなダイアリーから移転しました。

macport で clamd と freshclam を daemon にした

clamav というウィルススキャナの、更新担当のfreshclam と ウィルスチェック担当のclamd をデーモンにしようと思ったが、調べるとmacportでできた。

install

macport の clamav-server をそのままインストールすると、LaunchDaemonを作成してくれる、らしい。

sudo port install clamav-server
messsage

インストールしたら、このようなメッセージがでる。

To configure clamd and freshclam look for the following files:
/opt/local/etc/clamd.conf
/opt/local/etc/freshclam.conf

If these files do not exist you can copy the sample conf files into place:
sudo cp /opt/local/etc/clamd.conf.sample /opt/local/etc/clamd.conf
sudo cp /opt/local/etc/freshclam.conf.sample /opt/local/etc/freshclam.conf

Edit /opt/local/etc/clamd.conf to your liking, example:
# Comment out 'Example' near the top if it exists
#Example
LogFile /opt/local/var/log/clamav/clamd.log
PidFile /opt/local/var/run/clamav/clamd.pid
LocalSocket /opt/local/var/run/clamav/clamd.socket
Foreground yes

Edit /opt/local/etc/freshclam.conf to your liking, example:
# Comment out 'Example' near the top if it exists
#Example
UpdateLogFile /opt/local/var/log/clamav/freshclam.log
PidFile /opt/local/var/run/clamav/freshclam.pid
NotifyClamd /opt/local/etc/clamd.conf

Two launchd startup items have been installed.

To load clamd and freshclam do the following:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.clamd.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.freshclam.plist

To unload clamd and freshclam do the following:
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.clamd.plist
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.freshclam.plist

To try things out do
sudo freshclam

If all is well you should see your clamav database being updated

after install

あとはこのメッセージに書いてあるように、 /opt/local/etc/clamd.conf と /opt/local/etc/freshclam.conf を編集して、launchctl で設定をロードします。

sudo launchctl load -w /Library/LaunchDaemons/org.macports.clamd.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.freshclam.plist

ロードしたあとは、launchctl で開始、ストップできます。

sudo launchctl start org.macports.clamd.plist
sudo launchctl start org.macports.freshclam.plist

起動しているかどうかは、こうやって確認できます。

sudo launchctl list | grep macport

715 0 org.macports.freshclam
105 0 org.macports.clamd

先頭が数字であれば、それは起動しているプロセスのPIDです。
先頭が-であれば起動していません。

これでclamdが起動できたので、clamdtopを実行すると、さらに詳細情報が得られます。

plist ファイル

macportsでない場合次のファイルを参考にするといいです。

clamdのplist

/Library/LaunchDaemons/org.macports.clamd.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>GroupName</key>
	<string>_clamav</string>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>org.macports.clamd</string>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>/opt/local/sbin/clamd</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>UserName</key>
	<string>root</string>
</dict>
</plist>
freshclamのplist

/Library/LaunchDaemons/org.macports.freshclam.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>GroupName</key>
	<string>_clamav</string>
	<key>Label</key>
	<string>org.macports.freshclam</string>
	<key>ProgramArguments</key>
	<array>
		<string>/opt/local/bin/freshclam</string>
	</array>
	<key>StartInterval</key>
	<integer>21600</integer>
	<key>UserName</key>
	<string>_clamav</string>
</dict>
</plist>