From ad5be4387035eec47c68c03169c82a5fa780d0c4 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Tue, 20 Sep 2011 18:42:12 -0500
Subject: zoneminder: update for runit. refs #770 closes #751

---
 abs/core/zoneminder/PKGBUILD | 28 ++++++++++++++++------------
 abs/core/zoneminder/run      | 19 +++++++++++++++++--
 2 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/abs/core/zoneminder/PKGBUILD b/abs/core/zoneminder/PKGBUILD
index f9d6f8f..00ac2c6 100755
--- a/abs/core/zoneminder/PKGBUILD
+++ b/abs/core/zoneminder/PKGBUILD
@@ -19,17 +19,8 @@ customdb
 httpd-zm.conf 
 zmfilter.pl 
 zmeventbackup
-Makefile.patch)
-md5sums=('eaefa14befd482154970541252aa1a39'
-         'b20fb25b187eb6abb21321e153a7fb25'
-         '5033bc098bf497c8aed1fc1b3c9c5f9c'
-         'f9720872736f26d17bc49d8725b75ae4'
-         '4ace13d1e20934abe192ef7372c75988'
-         '00201eba9c0a5d1ed14b10cc55410698'
-         '80c52cc3575073a7462ff6a54886a345'
-         '8b40137b6ff54f2fb26104b70edd22e9'
-         'bb308c2393e947a224d56862c85a3ad9')
-
+Makefile.patch
+run)
 
 build() {
   cd "$srcdir/ZoneMinder-$pkgver"
@@ -69,6 +60,10 @@ build() {
 
   mkdir -p $startdir/pkg/var/run/zm
 
+  #install runit files
+  mkdir -p $pkgdir/etc/sv/zm
+  install -D -m 755 $srcdir/run $pkgdir/etc/sv/zm
+
   ### remove special files
   find $startdir/pkg/ -name "perllocal.pod" \
     -o -name ".packlist"                \
@@ -77,4 +72,13 @@ build() {
 
 }
 
-# vim:set ts=2 sw=2 et:
+md5sums=('eaefa14befd482154970541252aa1a39'
+         'b20fb25b187eb6abb21321e153a7fb25'
+         '5033bc098bf497c8aed1fc1b3c9c5f9c'
+         'f9720872736f26d17bc49d8725b75ae4'
+         '4ace13d1e20934abe192ef7372c75988'
+         '00201eba9c0a5d1ed14b10cc55410698'
+         '80c52cc3575073a7462ff6a54886a345'
+         '8b40137b6ff54f2fb26104b70edd22e9'
+         'bb308c2393e947a224d56862c85a3ad9'
+         '0c7024c355ce36828627bed10d965202')
diff --git a/abs/core/zoneminder/run b/abs/core/zoneminder/run
index e458bc8..ce61c24 100755
--- a/abs/core/zoneminder/run
+++ b/abs/core/zoneminder/run
@@ -2,5 +2,20 @@
 export TERM=linux
 . /etc/rc.conf
 . /etc/rc.d/functions
-stat_runit "Starting ZoneMinder"
-exec /etc/rc.d/zm start
+
+while true ; do
+    PID=`pidof -x zmdc.pl`
+    if test -n "$PID" ; then
+        sleep 60
+	continue
+    fi
+    stat_runit "Starting ZoneMinder"
+    /etc/rc.d/zm start
+    if test $? -ne 0 ; then
+        stat_fail
+    else
+        add_daemon zm
+        stat_done
+    fi
+    sleep 30
+done
-- 
cgit v0.12

