Bug 842773

Summary: Zoneminder fails at startup
Product: [Fedora] Fedora Reporter: Jonn Taylor <jonnt>
Component: zoneminderAssignee: Martin Ebourne <fedora>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 17CC: bill, fedora, germano.massullo, j, mammes, wally
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-01 00:23:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jonn Taylor 2012-07-24 14:58:14 UTC
Description of problem:

Zoneminder fails to start due to the fact that mysql is not ready to accept connection. Looks they are started at the same time.

Jul 22 20:13:33 dvr mysqld_safe[1116]: 120722 20:13:33 mysqld_safe Logging to '/var/log/mysqld.log'.
Jul 22 20:13:33 dvr zoneminder[1075]: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
Jul 22 20:13:33 dvr mysqld_safe[1116]: 120722 20:13:33 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jul 22 20:13:35 dvr zoneminder[1075]: Starting ZoneMinder: DBI connect('database=zm;host=localhost','zmuser',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at /usr/share/perl5/vendor_perl/ZoneMinder/Config.pm line 89
Jul 22 20:13:35 dvr zoneminder[1075]: Can't call method "prepare_cached" on an undefined value at /usr/share/perl5/vendor_perl/ZoneMinder/Config.pm line 91.
Jul 22 20:13:35 dvr zoneminder[1075]: BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/ZoneMinder/Config.pm line 100.
Jul 22 20:13:35 dvr zoneminder[1075]: Compilation failed in require at /usr/share/perl5/vendor_perl/ZoneMinder.pm line 33.
Jul 22 20:13:35 dvr zoneminder[1075]: BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/ZoneMinder.pm line 33.
Jul 22 20:13:35 dvr zoneminder[1075]: Compilation failed in require at /usr/bin/zmpkg.pl line 46.
Jul 22 20:13:35 dvr zoneminder[1075]: BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 46.
Jul 22 20:13:35 dvr zoneminder[1075]: [FAILED]
Jul 22 20:13:35 dvr systemd[1]: zoneminder.service: control process exited, code=exited status=255
Jul 22 20:13:35 dvr systemd[1]: Unit zoneminder.service entered failed state.

Comment 1 Jason Tibbitts 2012-07-24 15:10:03 UTC
Try adding an After= ordering clause to the service file and see if it helps.

Comment 2 Jonn Taylor 2012-07-24 15:13:08 UTC
Zoneminder still uses init file located in /etc/inid.d/zoneminder.

Comment 3 Jason Tibbitts 2012-07-24 16:26:01 UTC
Hm, indeed, it uses systemd in rawhide but not f17.

I am not sure there's anything that can be done here.  When mysql was using initscripts the ordering was correct.  With everything using systemd the ordering appears to be correct (or at least it worked OK in my testing, though I will double check).  But I do not know if there is a way to enforce ordering between services using the old and new startup methods.  At this point all I can really suggest is that you work around the issue by adding a sleep to the zoneminder initscript, though I'll be happy to look at any other options.

Comment 4 Jonn Taylor 2012-07-24 17:57:36 UTC
How about an updated packaged for fc17 to use systemd? or can I rebuild the src package from rawhide and use it on fc17?

Comment 5 Jonn Taylor 2012-07-24 18:15:56 UTC
Adding a sleep 10 to the init script gave mysql time to complete startup.

start()
{
	sleep 10
	zmupdate || return $?
	loadconf || return $?
	#Make sure the directory for our PID folder exists or create one.
	[ ! -d $pidfile ] \
		&& mkdir -m 774 $pidfile \
		&& chown $ZM_WEB_USER:$ZM_WEB_GROUP $pidfile
	#Make sure the folder for the socks file exists or create one
	GetPath="select Value from Config where Name='ZM_PATH_SOCKS'"
    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 
	[ ! -d $ZM_PATH_SOCK ] \
		&& mkdir -m 774 $ZM_PATH_SOCK \
		&& chown $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_PATH_SOCK
	echo -n $"Starting $prog: "
	$command start
	RETVAL=$?
	[ $RETVAL = 0 ] && success || failure
	echo
	[ $RETVAL = 0 ] && touch $LOCKFILE
	return $RETVAL
}

Comment 6 Jason Tibbitts 2012-07-24 18:58:02 UTC
Updating a package from sysv to systemd is not permitted within a Fedora release.  You are welcome to rebuild the F18 source package for F17 if you like.  If I was at my dev station instead of on vacation here at one of the far ends of the Earth, I'd do a build for you.

Comment 7 Axel Mammes 2013-02-01 16:42:37 UTC
This problem persists in F18 and I am struggling with it right now. 

Since zm connects via unix sockets, is there a way to tell systemd to wait for the mysqld socket to exist before trying to start zm?

Comment 8 Jason Tibbitts 2013-02-01 16:53:12 UTC
I guess mysql could use socket activation.  I don't know; that's really something that should be taken up with the mysq1 maintainers.  Dealing with this issue is supposed to be one of the reasons systemd was created, but I'm not really the person to ask about that.

Comment 9 Axel Mammes 2013-02-01 17:24:39 UTC
The system.d startup profile for zm is part of the zm rpm. I really don't think the mysql guys have anything to do with this fix.

Comment 10 Jason Tibbitts 2013-02-01 17:38:52 UTC
I'm glad that's what you think, but unfortunately you are not correct.  If mysql wants to make use of the systemd socket activation feature, where clients can connect and systemd will simply hold their connections until mysql actually starts up, then the mysql maintainers are going to have to do that.  It's nothing I can do in zoneminder.

Comment 11 Axel Mammes 2013-02-01 18:39:34 UTC
After adding After and Requires entries to /etc/systemd/system/multi-user.target.wants/zoneminder.service, zm starts up properly.

[Unit]
Description=Video security and surveillance system
After=mysqld.service
Requires=mysqld.service

[Service]
Type=forking
ExecStart=/usr/bin/zmpkg.pl start
ExecReload=/usr/bin/zmpkg.pl reload
PIDFile=/run/zoneminder/zm.pid

[Install]
WantedBy=multi-user.target

Comment 12 Bill Gradwohl 2013-05-29 15:16:01 UTC
Axel:

This is just an FYI.

I tried your fix on a fully patched F17 and it doesn't work for me. 

There was no zoneminder.service file in multi-user.target.wants, so I just created it. Don't know enough about systemd to really know what I did.

When I execute a systemctl enable for this it still segways to chkconfig, so what I have is still not part of a REAL systemd setup.

Comment 13 Fedora End Of Life 2013-07-03 22:27:40 UTC
This message is a reminder that Fedora 17 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 17. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '17'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 17's end of life.

Bug Reporter:  Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 17 is end of life. If you 
would still like  to see this bug fixed and are able to reproduce it 
against a later version  of Fedora, you are encouraged  change the 
'version' to a later Fedora version prior to Fedora 17's end of life.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 14 Fedora End Of Life 2013-08-01 00:23:35 UTC
Fedora 17 changed to end-of-life (EOL) status on 2013-07-30. Fedora 17 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 15 Bill Gradwohl 2013-09-15 23:22:40 UTC
I just installed zoneminder on a fully patched F19, and it still exhibits the failure as described above. However, the fix to add:

After=mysqld.service
Requires=mysqld.service

to /etc/systemd/system/multi-user.target.wants/zoneminder.service also as described above works.

I just wanted someone to know that adding those 2 lines to that file fixes the problem.

Comment 16 Walter Francis 2014-11-21 00:41:09 UTC
This was happening on 18, 19, 20..  Maybe it'll get a fix in 21?