diff --git a/distros/ubuntu1604/zoneminder.postinst b/distros/ubuntu1604/zoneminder.postinst index c9fbe245e..27d31953c 100644 --- a/distros/ubuntu1604/zoneminder.postinst +++ b/distros/ubuntu1604/zoneminder.postinst @@ -25,29 +25,31 @@ if [ "$1" = "configure" ]; then if [ -e "/lib/systemd/system/mysql.service" ] || [ -e "/lib/systemd/system/mariadb.service" ]; then # Ensure zoneminder is stopped deb-systemd-invoke stop zoneminder.service || exit $? - + + # # Get mysql started if it isn't running # - $(systemctl status mysql.service >/dev/null 2>&1); MYSQL_STATUS=$? - $(systemctl status mariadb.service >/dev/null 2>&1); MARIADB_STATUS=$? - # 3 = inactive, 4 = nonexistant - if [ "$MARIADB_STATUS" != "4" ]; then + if [ -e "/lib/systemd/system/mariadb.service" ]; then DBSERVICE="mariadb.service" else DBSERVICE="mysql.service" fi + if systemctl is-failed --quiet $DBSERVICE; then + echo "$DBSERVICE is in a failed state; it will not be started." + echo "If you have already resolved the problem preventing $DBSERVICE from running," + echo "run sudo systemctl restart $DBSERVICE then run sudo dpkg-reconfigure zoneminder." + exit 1 + fi - if [ "$MYSQL_STATUS" != "0" ] && [ "$MARIADB_STATUS" != "0" ]; then - # 3 = inactive, 4 = nonexistant + if ! systemctl is-active --quiet mysql.service mariadb.service; then # Due to /etc/init.d service autogeneration, mysql.service always returns the status of mariadb.service # However, mariadb.service will not return the status of mysql.service. deb-systemd-invoke start $DBSERVICE fi - + # Make sure systemctl status exit code is 0; i.e. the DB is running - if systemctl status "$DBSERVICE" >/dev/null 2>&1; then - + if systemctl is-active --quiet "$DBSERVICE"; then mysqladmin --defaults-file=/etc/mysql/debian.cnf -f reload # test if database if already present... if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then diff --git a/src/zm_db.cpp b/src/zm_db.cpp index 1b568e61e..36a7edbac 100644 --- a/src/zm_db.cpp +++ b/src/zm_db.cpp @@ -107,34 +107,34 @@ MYSQL_RES * zmDbFetch(const char * query) { } db_mutex.unlock(); return result; -} // end MYSQL_RES * zmDbFetch( const char * query ); +} // end MYSQL_RES * zmDbFetch(const char * query); -zmDbRow *zmDbFetchOne( const char *query ) { +zmDbRow *zmDbFetchOne(const char *query) { zmDbRow *row = new zmDbRow(); - if ( row->fetch( query ) ) { + if ( row->fetch(query) ) { return row; } delete row; return NULL; } -MYSQL_RES *zmDbRow::fetch( const char *query ) { - result_set = zmDbFetch( query ); +MYSQL_RES *zmDbRow::fetch(const char *query) { + result_set = zmDbFetch(query); if ( ! result_set ) return result_set; int n_rows = mysql_num_rows( result_set ); if ( n_rows != 1 ) { - Error( "Bogus number of lines return from query, %d returned for query %s.", n_rows, query ); - mysql_free_result( result_set ); + Error("Bogus number of lines return from query, %d returned for query %s.", n_rows, query); + mysql_free_result(result_set); result_set = NULL; return result_set; } - row = mysql_fetch_row( result_set ); + row = mysql_fetch_row(result_set); if ( ! row ) { - mysql_free_result( result_set ); + mysql_free_result(result_set); result_set = NULL; - Error("Error getting row from query %s. Error is %s", query, mysql_error( &dbconn ) ); + Error("Error getting row from query %s. Error is %s", query, mysql_error(&dbconn)); } else { Debug(5, "Success"); }