2005-12-16 20:21:47 +08:00
#!/bin/sh
2008-07-25 17:48:16 +08:00
# description: ZoneMinder is the top Linux video camera security and surveillance solution. ZoneMinder is intended for use in single or multi-camera video security applications.Copyright: Philip Coombes, Corey DeLasaux 2003-2008
2006-04-24 03:50:34 +08:00
# chkconfig: 2345 99 00
2006-11-16 17:06:37 +08:00
# processname: zmpkg.pl
2005-12-16 20:21:47 +08:00
# Source function library.
. /etc/rc.d/init.d/functions
prog=ZoneMinder
2006-11-16 17:06:37 +08:00
ZM_CONFIG="@ZM_CONFIG@"
pidfile="@ZM_RUNDIR@"
LOCKFILE=/var/lock/subsys/zm
2005-12-16 20:21:47 +08:00
2006-04-24 03:50:34 +08:00
loadconf()
{
if [ -f $ZM_CONFIG ]; then
. $ZM_CONFIG
else
echo "ERROR: $ZM_CONFIG not found."
return 1
fi
}
2006-11-16 17:06:37 +08:00
loadconf
command="$ZM_PATH_BIN/zmpkg.pl"
2006-04-24 03:50:34 +08:00
start()
{
2006-11-16 17:06:37 +08:00
zmupdate || return $?
2006-04-24 03:50:34 +08:00
loadconf || return $?
2006-11-16 17:06:37 +08:00
#Make sure the directory for our PID folder exists or create one.
2010-11-29 05:22:05 +08:00
[ ! -d $pidfile ] \
2006-11-16 17:06:37 +08:00
&& mkdir -m 774 $pidfile \
&& chown $ZM_WEB_USER:$ZM_WEB_GROUP $pidfile
#Make sure the folder for the socks file exists or create one
2006-04-24 03:50:34 +08:00
GetPath="select Value from Config where Name='ZM_PATH_SOCKS'"
2007-09-07 23:39:44 +08:00
dbHost=`echo $ZM_DB_HOST | cut -d: -f1`
dbPort=`echo $ZM_DB_HOST | cut -d: -s -f2`
if [ "$dbPort" = "" ]
then
ZM_PATH_SOCK=`echo $GetPath | mysql -B -h$ZM_DB_HOST -u$ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
else
ZM_PATH_SOCK=`echo $GetPath | mysql -B -h$dbHost -P$dbPort -u$ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
fi
2006-04-24 03:50:34 +08:00
[ ! -d $ZM_PATH_SOCK ] \
&& mkdir -m 774 $ZM_PATH_SOCK \
2006-11-16 17:06:37 +08:00
&& chown $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_PATH_SOCK
echo -n $"Starting $prog: "
2005-12-16 20:21:47 +08:00
$command start
RETVAL=$?
2006-11-16 17:06:37 +08:00
[ $RETVAL = 0 ] && success || failure
2005-12-16 20:21:47 +08:00
echo
2006-11-16 17:06:37 +08:00
[ $RETVAL = 0 ] && touch $LOCKFILE
2005-12-16 20:21:47 +08:00
return $RETVAL
}
2006-04-24 03:50:34 +08:00
stop()
{
2006-11-16 17:06:37 +08:00
loadconf
2005-12-16 20:21:47 +08:00
echo -n $"Stopping $prog: "
$command stop
RETVAL=$?
2006-11-16 17:06:37 +08:00
[ $RETVAL = 0 ] && success || failure
2005-12-16 20:21:47 +08:00
echo
2006-11-16 17:06:37 +08:00
[ $RETVAL = 0 ] && rm -f $LOCKFILE
2005-12-16 20:21:47 +08:00
}
2006-04-24 03:50:34 +08:00
2006-11-16 17:06:37 +08:00
zmstatus()
2006-04-24 03:50:34 +08:00
{
2006-11-16 17:06:37 +08:00
loadconf
2005-12-16 20:21:47 +08:00
result=`$command status`
if [ "$result" = "running" ]; then
echo "ZoneMinder is running"
2006-11-16 17:06:37 +08:00
$ZM_PATH_BIN/zmu -l
2005-12-16 20:21:47 +08:00
RETVAL=0
else
echo "ZoneMinder is stopped"
RETVAL=1
fi
}
2006-11-16 17:06:37 +08:00
zmupdate()
{
2013-08-23 03:13:22 +08:00
if [ -x $ZM_PATH_BIN/zmupdate.pl ]; then
2013-12-14 23:05:15 +08:00
# Commenting out as it is not needed. Leaving as a placeholder for future use.
# $ZM_PATH_BIN/zmupdate.pl -f
2006-11-16 17:06:37 +08:00
fi
}
2005-12-16 20:21:47 +08:00
case "$1" in
2006-04-24 03:50:34 +08:00
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'condrestart')
loadconf
result=`$ZM_PATH_BIN/zmdc.pl check`
if [ "$result" = "running" ]; then
$ZM_PATH_BIN/zmdc.pl shutdown > /dev/null
2006-11-16 17:06:37 +08:00
rm -f $LOCKFILE
2006-04-24 03:50:34 +08:00
start
fi
;;
'status')
2006-11-16 17:06:37 +08:00
status httpd
status mysqld
zmstatus
2006-04-24 03:50:34 +08:00
;;
*)
echo "Usage: $0 { start | stop | restart | condrestart | status }"
RETVAL=1
;;
2005-12-16 20:21:47 +08:00
esac
exit $RETVAL