Added Corey changes.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1936 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2006-04-23 19:50:34 +00:00
parent 593909fd58
commit 31a630d746
1 changed files with 158 additions and 21 deletions

View File

@ -1,16 +1,140 @@
#!/bin/sh
# description: Control ZoneMinder as a Service
# chkconfig: 2345 99 99
# chkconfig: 2345 99 00
# Source function library.
. /etc/rc.d/init.d/functions
prog=ZoneMinder
ZM_VERSION="@VERSION@"
ZM_PATH_BIN="@BINDIR@"
ZM_CONFIG="@SYSCONFDIR@/zm.conf"
command="$ZM_PATH_BIN/zmpkg.pl"
start() {
loadconf()
{
if [ -f $ZM_CONFIG ]; then
. $ZM_CONFIG
else
echo "ERROR: $ZM_CONFIG not found."
return 1
fi
}
# Check for old config and update if needed
checkcfg()
{
# Check config
if [ "$ZM_DB_HOST" = "" -o "$ZM_DB_NAME" = "" -o "$ZM_DB_USER" = "" -o "$ZM_DB_PASS" = "" ]; then
if [ "$ZM_DB_SERVER" != "" -a "$ZM_DB_NAME" != "" -a "$ZM_DB_USERA" != "" -a "$ZM_DB_PASSA" != "" ]; then
echo -n "Converting $ZM_CONFIG"
cp $ZM_CONFIG $ZM_CONFIG.old && \
cat $ZM_CONFIG.old | \
grep -v ZM_DB_USERB | \
grep -v ZM_DB_PASSB | \
sed -e 's/ZM_DB_USERA/ZM_DB_USER/' | \
sed -e 's/ZM_DB_PASSA/ZM_DB_PASS/' >$ZM_CONFIG && \
rm -f $ZM_CONFIG.old
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
fi
if [ "$ZM_DB_SERVER" != "" -a "$ZM_DB_NAME" != "" -a "$ZM_DB_USER" != "" -a "$ZM_DB_PASS" != "" ]; then
echo -n "Converting $ZM_CONFIG to 1.22.0"
cp $ZM_CONFIG $ZM_CONFIG.old
rm -f $ZM_CONFIG
cat $ZM_CONFIG.old | \
sed -e 's/ZM_DB_SERVER/ZM_DB_HOST/' >/tmp/$$
. /tmp/$$
cp $ZM_CONFIG.rpmnew $ZM_CONFIG && chmod 644 $ZM_CONFIG
for n in ZM_DB_HOST ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
eval "val=\$$n"
if [ "$val" != "" ]; then
cp $ZM_CONFIG /tmp/$$.rpmnew &&
sed 's/^'$n='.*$/'$n=$val'/g' /tmp/$$.rpmnew >$ZM_CONFIG
fi
done
rm /tmp/$$
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
else
echo "In $ZM_CONFIG there should not be null values."
return 1
fi
loadconf
fi
}
checkdb()
{
# Check database exisits and version
GetVer="select Value from Config where Name='ZM_DYN_DB_VERSION'"
OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
if [ "$OLD_VERSION" = "" ]; then
GetVer="select Value from Config where Name='ZM_DYN_CURR_VERSION'"
OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'`
if [ "$OLD_VERSION" = "" ]; then
echo -n "You must run zmupdate.pl manualy"
return 1
fi
fi
RETVAL=$?
if [ $RETVAL != 0 ]; then
tbls=`mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS -s -e 'show tables' $ZM_DB_NAME`
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo -n "Initialize $prog database: "
echo tbls | grep Config >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL != 0 ]; then
cat $ZM_PATH_UPDATE/zmschema.sql | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
return $RETVAL
fi
( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f )
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
return $RETVAL
else
echo "No access to ZoneMinder database. Run $ZM_PATH_BIN/zminit manually."
return $RETVAL
fi
else
[ "$ZM_VERSION" = "$OLD_VERSION" ] && return 0
echo -n "Upgrade $prog database: "
$ZM_PATH_BIN/zmupdate.pl --version=$OLD_VERSION --noi && ( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f )
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
return $RETVAL
fi
}
start()
{
loadconf || return $?
checkcfg || return $?
checkdb || return $?
/usr/local/sbin/motd.sh > /etc/motd
echo -n "Starting $prog: "
[ ! -d @ZM_RUNDIR@ ] \
&& mkdir -m 774 @ZM_RUNDIR@ \
&& chown $ZM_WEB_USER:$ZM_WEB_GROUP @ZM_RUNDIR@
GetPath="select Value from Config where Name='ZM_PATH_SOCKS'"
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'`
[ ! -d $ZM_PATH_SOCK ] \
&& mkdir -m 774 $ZM_PATH_SOCK \
&&chown $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_PATH_SOCK
$command start
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
@ -19,7 +143,9 @@ start() {
[ $RETVAL = 0 ] && touch /var/lock/subsys/zm
return $RETVAL
}
stop() {
stop()
{
echo -n $"Stopping $prog: "
$command stop
RETVAL=$?
@ -28,7 +154,9 @@ stop() {
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/zm
}
status() {
status()
{
result=`$command status`
if [ "$result" = "running" ]; then
echo "ZoneMinder is running"
@ -40,22 +168,31 @@ status() {
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'condrestart')
loadconf
checkcfg
result=`$ZM_PATH_BIN/zmdc.pl check`
if [ "$result" = "running" ]; then
$ZM_PATH_BIN/zmdc.pl shutdown > /dev/null
start
fi
;;
'status')
status
;;
*)
echo "Usage: $0 { start | stop | restart | condrestart | status }"
RETVAL=1
;;
esac
exit $RETVAL