Problem in zmpkg.pl in packaging RPM

Support and queries relating to all previous versions of ZoneMinder
Locked
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Problem in zmpkg.pl in packaging RPM

Post by cordel »

Hello everyone and Phil,
Disclaimer: The following could be considered rude and very ugly ;)
This is the only thing I am unable to get around and I'm not sure how to get around it.
If ZM is running when the package is upgraded, it will not stop :(
You have to stop ZM before updating ( and I forced this in the spec so no one gets nailed) but the correct way to do this is using condrestart so that if ZM was running before the update, it would start back up after and apply the conf and DB updates (like in the case of yum update running nightly).
Is there anything you are aware of I can do in order to force stop the old process and be able to get status?

When I execute a condrestart by hand (This was done in the upgrade process)

Code: Select all

start() {
    loadconf || return $?
    checkdb || return $?
        /usr/local/sbin/motd.sh > /etc/motd
    echo -n "Starting $prog: "
    $command start
    RETVAL=$?
    [ $RETVAL = 0 ] && echo_success
    [ $RETVAL != 0 ] && echo_failure
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/zm
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    $command stop
    RETVAL=$?
    [ $RETVAL = 0 ] && echo_success
    [ $RETVAL != 0 ] && echo_failure
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/zm
}
status() {
    result=`$command status`
    if [ "$result" = "running" ]; then
        echo "ZoneMinder is running"
        RETVAL=0
    else
        echo "ZoneMinder is stopped"
        RETVAL=1
    fi
}
case "$1" in
SNIP
'condrestart')
    result=`$command status`
    if [ "$result" = "running" ]; then
        stop
        start
    fi
    ;;
I get the following error:

Code: Select all

# service zm condrestart
Undefined subroutine &ZoneMinder::Config::ZM_DB_HOST called at /usr/lib/perl5/site_perl/5.8.5/ZoneMinder/Config.pm line 88.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/ZoneMinder/Config.pm line 99.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.5/ZoneMinder.pm line 33.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/ZoneMinder.pm line 33.
Compilation failed in require at /usr/lib/zm/bin/zmpkg.pl line 45.
BEGIN failed--compilation aborted at /usr/lib/zm/bin/zmpkg.pl line 45.
Now I'm sure this is due too the old /etc/zm.conf is still in place as a part of the problem, but that still don't allow me to kill the present process. I tried adding checkdb as part of the condrestart but this makes things real grumpy and botchs the database upgrade (glad I make backups).

I have also seperated out the update function to checkcfg and checkdb and make changes to the zm start script so I can update the zm.conf without updating the database like so:

Code: Select all

'condrestart')
	loadconf
	checkcfg
	result=`$command status`
	if [ "$result" = "running" ]; then
		stop
		checkdb
		start
	fi
	;;
and this brings me down to one call to the database that don't yet exist:

Code: Select all

Stopping ZoneMinder: Bareword "ZM_RUN_AUDIT" not allowed while "strict subs" in use at /usr/lib/zm/bin/zmpkg.pl line 206.
Execution of /usr/lib/zm/bin/zmpkg.pl aborted due to compilation errors.

# service zm status
Bareword "ZM_RUN_AUDIT" not allowed while "strict subs" in use at /usr/lib/zm/bin/zmpkg.pl line 206.
Execution of /usr/lib/zm/bin/zmpkg.pl aborted due to compilation errors.
ZoneMinder is stopped

From Top
9932 apache    16   0  7412 5648 2180 S  0.0  1.1   0:00.00 zmdc.pl
It returns as Stopped but it is not :cry:

This is as close as I can get.
I'm stumped and look forward to any assistance from anyone.
AKA: HELP :roll:

Corey
Image
Image
3939663646337

It's better to keep your mouth shut and appear stupid than open it and remove all doubt.
-Mark Twain
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

I don't know that it is proper so Phil let me know if it is not.
I set condrestart to send zmdc.pl shutdown to work around this and get status from zmdc as well.

Cheers,
Corey
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

well IMHO if you need help then i dont nkow what to do mate!!!
sorry

James
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
User avatar
chaapaï
Posts: 19
Joined: Fri Aug 13, 2004 2:26 pm
Location: France

Post by chaapaï »

hello all !

Cordel , i use a new script for testing convert zm.conf and db :

Code: Select all

#!/bin/sh
#zmscript: General script for zoneminder on SME

ZM_CONFIG=/etc/zm/zm.conf
ZM_PATH=/usr/lib/zm

usage() {
    echo
    echo " Usage: zmscript <-checkconf,-convconf,-checkdbacces,-gendbpasswd,-fixmysqlaccess,-dbupgrade>"
    echo "-checkconf      : Check if zm.conf exist and value are not null"
    echo "-convconf       : Convert all format of zm.conf for working with 1.22.0 zm.conf format"
    echo "-checkdbaccess  : Check access to zm DB."
    echo "-fixmysqlaccess : Create/fix ZM user and ZM password for mysql "
    echo "-gendbpasswd    : Generate a defaut admin and password if no exist in zm.conf"
    echo "-dbupgrade      : Check/upgrade zm DB "
    echo
}

# check if zm.conf exist
loadconf() {
    if [ -f $ZM_CONFIG ]; then
	. $ZM_CONFIG
	echo -n "ZMSCRIPT: ..load "
    else
	echo " :ERROR: $ZM_CONFIG not found."
	return 1
    fi
}

#convert zm.conf format to 1.22 
convertconf() {
    fsed=0
    for n in ZM_DB_USERA ZM_DB_PASSA ZM_DB_SERVER ZM_VERSION ZM_PATH_BUILD ZM_TIME_BUILD \
	    ZM_PATH_BIN ZM_PATH_LIB ZM_PATH_CONF ZM_PATH_WEB ZM_PATH_CGI ZM_WEB_USER \
	    ZM_WEB_GROUP ZM_DB_HOST ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
	eval "val=\$$n"
        if [ "$val" != "" ]; then
	    [ $n = "ZM_DB_USERA" ] && echo  "s|ZM_DB_USER.*|ZM_DB_USER="$val"|" >>/tmp/zm.conf.sed
	    [ $n = "ZM_DB_PASSA" ] && echo  "s|ZM_DB_PASS.*|ZM_DB_PASS="$val"|" >>/tmp/zm.conf.sed
	    [ $n = "ZM_DB_SERVER" ] && echo "s|ZM_DB_HOST.*|ZM_DB_HOST="$val"|" >>/tmp/zm.conf.sed	    
            echo "s|"$n".*|$n="$val"|" >> /tmp/zm.conf.sed
	fi
    done
    [ -f $ZM_CONFIG ] && mv -f $ZM_CONFIG $ZM_CONFIG.oldconf
    if [ -f $ZM_CONFIG ]; then 
    cat $ZM_PATH/init/zm.conf.model | sed -f /tmp/zm.conf.sed > $ZM_CONFIG
    rm -f /tmp/zm.conf.sed
    else
    cp $ZM_PATH/init/zm.conf.model $ZM_CONFIG
    fi
    echo -n " ..convert "
}

## test if values in zm.conf are empty 
testemptyvalue() {
    for n in ZM_VERSION ZM_TIME_BUILD ZM_PATH_BUILD ZM_PATH_BIN ZM_PATH_LIB \
	ZM_PATH_CONF ZM_PATH_WEB ZM_PATH_CGI ZM_WEB_USER ZM_WEB_GROUP ZM_DB_HOST  \
	ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
	eval "val=\$$n"
	[ "$val" = "" ] && ZM_CONF_EMPTY="$ZM_CONF_EMPTY $n"
    done
    if [ "$ZM_CONF_EMPTY" != "" ] ; then
	echo " :ERROR($ZM_CONFIG): $ZM_CONF_EMPTY should exist and be not empty!"
	return 1
    else
	echo -n " ..no-empty "
    fi
}

## Random String generator 
randstr(){
    randpasswd=;
    (( "$1" )) && string="0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" && for (( a=0 ; a<$1 ; a++ ))
    do
	randpasswd=$randpasswd${string:$((RANDOM%64)):1};
    done
    randpasswd=$2$randpasswd
}

## Generate ZM_DB_USER and ZM_DB_PASS if no exist and use by defaut.
gendbpasswd() {
    for n in ZM_DB_USER ZM_DB_PASS; do
	eval "val=\$$n"
	[ $n = "ZM_DB_USER" ] && randstr 10 admin
	[ $n = "ZM_DB_PASS" ] && randstr 10 pass 
	if [ "$val" != "" ]; then
	    echo  "s|"$n".*|"$n"="$val"|" >>/tmp/zm.conf.sed
	else
	    echo  "s|"$n".*|"$n"="$randpasswd"|" >>/tmp/zm.conf.sed
	fi
    done
    mv -f $ZM_PATH/init/zm.conf.model $ZM_PATH/init/zm.conf.model.old
    cat $ZM_PATH/init/zm.conf.model.old | sed -f /tmp/zm.conf.sed > $ZM_PATH/init/zm.conf.model
    rm -f /tmp/zm.conf.sed
    echo -n " ..gendbpasswd "
}

## Fix/generate access to ZM DB
fixdbaccess() {
    sql=/tmp/zm.create.sql
    echo "" >$sql
    chmod 600 $sql

    echo "CREATE DATABASE /*!32312 IF NOT EXISTS*/ $ZM_DB_NAME;" >>$sql
    echo "USE $ZM_DB_NAME;" >>$sql
    echo "GRANT all on $ZM_DB_NAME.* TO '$ZM_DB_USER'@'$ZM_DB_HOST' IDENTIFIED BY '$ZM_DB_PASS';" >>$sql



    #for sme PASSWORD is CODED.....
    MYSQL_PW=`sed q /etc/openldap/ldap.pw`

    cat $sql | mysql  -B -h $ZM_DB_HOST --user=root --password=$MYSQL_PW
    [ $? = 0 ] && echo -n " ..fixdbaccess " 
    rm -f $sql
}

## Test access to table
dbaccess() {
#    tbls=`mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS -s -e 'show tables' $ZM_DB_NAME`
    tbls=`mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS -s -e 'exit' $ZM_DB_NAME`
    RETVAL=$?
    if [ $RETVAL = 0 ]; then
	echo -n " ..DBaccess "    
        GetVer="select DefaultValue 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 '^DefaultValue'`
	RETVAL=$?
	[ $RETVAL = 0 ] && echo -n " ..readversion " 
	[ $RETVAL = 1 ] && echo -e "\n ERROR TABLES ACCESS : cannot read ZM_DYN_CURR_VERSION (your base is empty)"
	return $RETVAL
    else
	echo -e "\n ERROR MYSQL ACCESS :You have a problem with your zm.conf for access to db, please check your config or fix-it"
	return $RETVAL
    fi
}

## Test/upgrade DB version
dbupgrade()
{
    if [ "$ZM_VERSION" != "$OLD_VERSION" ]; then
	perl $ZM_PATH_BIN/zmupdate.pl -v $OLD_VERSION 
    else 
	echo -n " No need upgrade! ZM_VERSION = $ZM_VERSION"
    fi
}

primary()
{
    case $1 in
    -convconf)
	loadconf
	convertconf
	loadconf
	testemptyvalue||return $?
	;;
    -checkconf)
	loadconf||return $?
	testemptyvalue||return $?
	;;
    -checkdbaccess)
	loadconf||return $?
	testemptyvalue||return $?
	dbaccess||return $?
	;;
    -fixmysqlaccess)
	loadconf||return $?
	testemptyvalue||return $?
	fixdbaccess||return $?
	;;
    -gendbpasswd)
	loadconf
	gendbpasswd||return $?
	convertconf||return $?
	loadconf
	;;	
    -dbupgrade)
	loadconf||return $?
	convertconf||return $?
	testemptyvalue||return $?
	dbaccess||return $?
	dbupgrade||return $?
	;;
    *) usage
    ;;
    esac
}

#start 
primary $1

RETVAL=$?
[ $RETVAL = 1 ] && exit 1 
[ $RETVAL = 0 ] && echo "     SUCCESS !!" && exit 0 
and in /etc/rc.d/init.d

Code: Select all

checkdb() {
	/usr/lib/zm/init/zmscript -checkdbaccess > /dev/null 2>&1
	RETVAL=$?
	[ $RETVAL != 0 ] && echo " Problem with ZoneMinder config/db, please run /usr/lib/zm/init/zmscript "
	return $RETVAL
}

 start() {
	checkdb || return $?
 	echo -n "Starting $prog: "
Have a nice day
oooops, i'm sorry but i speak english like as spanish cow...
Locked