From 32bf57d35b8d80824468c30472bd07577f31674d Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 19 Jan 2018 15:15:11 -0600 Subject: [PATCH] docker support files moved to zmdockerfiles --- utils/docker/README.md | 2 +- utils/docker/entrypoint.sh | 142 ------------------------------------- utils/docker/phpdate.ini | 5 -- utils/docker/setup.sh | 75 -------------------- utils/docker/start.sh | 48 ------------- 5 files changed, 1 insertion(+), 271 deletions(-) delete mode 100755 utils/docker/entrypoint.sh delete mode 100644 utils/docker/phpdate.ini delete mode 100755 utils/docker/setup.sh delete mode 100755 utils/docker/start.sh diff --git a/utils/docker/README.md b/utils/docker/README.md index 47bf4d1a2..0dd76b32b 100644 --- a/utils/docker/README.md +++ b/utils/docker/README.md @@ -1,4 +1,4 @@ ## Docker Support Files -The files in this folder are used to support our Dockerfiles here: +Docker support files have been moved to the zmdockerfiles repo: https://github.com/ZoneMinder/zmdockerfiles diff --git a/utils/docker/entrypoint.sh b/utils/docker/entrypoint.sh deleted file mode 100755 index ee01499d1..000000000 --- a/utils/docker/entrypoint.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/bin/bash -# ZoneMinder Dockerfile entrypoint script -# Written by Andrew Bauer - -############### -# SUBROUTINES # -############### - -# Find ciritical files and perform sanity checks -initialize () { - - # Check to see if this script has access to all the commands it needs - for CMD in mysqladmin sed usermod service; do - type $CMD &> /dev/null - - if [ $? -ne 0 ]; then - echo - echo "ERROR: The script cannot find the required command \"${CMD}\"." - echo - exit 1 - fi - done - - # Look in common places for the zoneminder config file - zm.conf - for FILE in "/etc/zm.conf" "/etc/zm/zm.conf" "/usr/local/etc/zm.conf" "/usr/local/etc/zm/zm.conf"; do - if [ -f $FILE ]; then - ZMCONF=$FILE - break - fi - done - - # Look in common places for the zoneminder startup perl script - zmpkg.pl - for FILE in "/usr/bin/zmpkg.pl" "/usr/local/bin/zmpkg.pl"; do - if [ -f $FILE ]; then - ZMPKG=$FILE - break - fi - done - - # Look in common places for the zoneminder dB creation script - zm_create.sql - for FILE in "/usr/share/zoneminder/db/zm_create.sql" "/usr/local/share/zoneminder/db/zm_create.sql"; do - if [ -f $FILE ]; then - ZMCREATE=$FILE - break - fi - done - - # Look in common places for the php.ini relevant to zoneminder - php.ini - # Search order matters here because debian distros commonly have multiple php.ini's - for FILE in "/etc/php/7.0/apache2/php.ini" "/etc/php5/apache2/php.ini" "/etc/php.ini" "/usr/local/etc/php.ini"; do - if [ -f $FILE ]; then - PHPINI=$FILE - break - fi - done - - for FILE in $ZMCONF $ZMPKG $ZMCREATE $PHPINI; do - if [ -z $FILE ]; then - echo - echo "FATAL: This script was unable to determine one or more cirtical files. Cannot continue." - echo - echo "VARIABLE DUMP" - echo "-------------" - echo - echo "Path to zm.conf: ${ZMCONF}" - echo "Path to zmpkg.pl: ${ZMPKG}" - echo "Path to zm_create.sql: ${ZMCREATE}" - echo "Path to php.ini: ${PHPINI}" - echo - exit 98 - fi - done -} - -start_mysql () { - service mysql start - # Give MySQL time to wake up - SECONDS_LEFT=120 - while true; do - sleep 1 - mysqladmin ping > /dev/null 2>&1 - if [ $? -eq 0 ];then - break; # Success - fi - let SECONDS_LEFT=SECONDS_LEFT-1 - - # If we have waited >120 seconds, give up - # ZM should never have a database that large! - # if $COUNTER -lt 120 - if [ $SECONDS_LEFT -eq 0 ];then - return -1; - fi - done -} - -close_mysql () { - service mysql stop - sleep 5 -} - -################ -# MAIN PROGRAM # -################ - -echo -initialize - -# Configure then start Mysql -if [ -n "$MYSQL_SERVER" ] && [ -n "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ] && [ -n "$MYSQL_DB" ]; then - sed -i -e "s/ZM_DB_NAME=zm/ZM_DB_NAME=$MYSQL_USER/g" $ZMCONF - sed -i -e "s/ZM_DB_USER=zmuser/ZM_DB_USER=$MYSQL_USER/g" $ZMCONF - sed -i -e "s/ZM_DB_PASS=zm/ZM_DB_PASS=$MYSQL_PASS/g" $ZMCONF - sed -i -e "s/ZM_DB_HOST=localhost/ZM_DB_HOST=$MYSQL_SERVER/g" $ZMCONF - start_mysql -else - usermod -d /var/lib/mysql/ mysql - start_mysql - mysql -u root < $ZMCREATE - mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'zmuser'@'localhost' IDENTIFIED BY 'zmpass';" -fi -# Ensure we shut down mysql cleanly later: -trap close_mysql SIGTERM - -# Configure then start Apache -if [ -z "$TZ" ]; then - $TZ = UTC -fi -echo "date.timezone = $TZ" >> $PHPINI -service apache2 start - -# Start ZoneMinder -echo " * Starting ZoneMinder video surveillance recorder" -$ZMPKG start -echo " ...done." - -# Stay in a loop to keep the container running -while : -do - # perhaps output some stuff here or check apache & mysql are still running - sleep 3600 -done - diff --git a/utils/docker/phpdate.ini b/utils/docker/phpdate.ini deleted file mode 100644 index d35b47361..000000000 --- a/utils/docker/phpdate.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Date] -; Defines the default timezone used by the date functions -; http://php.net/date.timezone -date.timezone = GMT - diff --git a/utils/docker/setup.sh b/utils/docker/setup.sh deleted file mode 100755 index ecf915f16..000000000 --- a/utils/docker/setup.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -setup_mysql_first_time(){ - if [ "$(ls /var/lib/mysql)" ]; then - return - fi - - # Set MySQL in the volume - rm -rf /var/lib/mysql/* - chown -R mysql:mysql /var/lib/mysql - mysqld --initialize-insecure - - # Start MySQL - # For Xenial the following won't start mysqld - #/usr/bin/mysqld_safe & - # Use this instead: - service mysql start - - # Give MySQL time to wake up - SECONDS_LEFT=120 - while true; do - sleep 1 - mysqladmin ping - if [ $? -eq 0 ];then - break; # Success - fi - let SECONDS_LEFT=SECONDS_LEFT-1 - - # If we have waited >120 seconds, give up - # ZM should never have a database that large! - # if $COUNTER -lt 120 - if [ $SECONDS_LEFT -eq 0 ];then - return -1; - fi - done - - # Create the ZoneMinder database - mysql -u root < db/zm_create.sql - - # Add the ZoneMinder DB user - mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zmuser'@'localhost' identified by 'zmpass';" - - # Shut down mysql cleanly: - kill $(cat /var/run/mysqld/mysqld.pid) - sleep 5 -} - -setup_mysql() { - # To configure MySQL if no container did it before - setup_mysql_first_time - - # Add configuration to avoid SQL error when adding monitor - echo "sql_mode=NO_ENGINE_SUBSTITUTION" >> /etc/mysql/mysql.conf.d/mysqld.cnf -} - -setup_php() { - # Activate CGI - a2enmod -q cgi - - # Activate modrewrite - a2enmod -q rewrite - - # Setting timezone - sed -i "s#;date.timezone =#date.timezone = $PHP_TIMEZONE#" /etc/php/7.0/apache2/php.ini - - # Settings rights for volume - chown -R www-data:www-data /var/lib/zoneminder/events - chown -R www-data:www-data /var/lib/zoneminder/images -} - - -setup_mysql -setup_php - -exit 0 diff --git a/utils/docker/start.sh b/utils/docker/start.sh deleted file mode 100755 index 599b6fcb2..000000000 --- a/utils/docker/start.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -# Prepare proper amount of shared memory -# For H.264 cameras it may be necessary to increase the amount of shared memory -# to 2048 megabytes. -umount /dev/shm -mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm - -# Start MySQL -test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld -su - mysql -s /bin/sh -c "/usr/bin/mysqld_safe > /dev/null 2>&1 &" - -# Ensure we shut down mysql cleanly later: -trap close_mysql SIGTERM - -# Give MySQL time to wake up -SECONDS_LEFT=120 -while true; do - sleep 1 - mysqladmin ping - if [ $? -eq 0 ];then - break; # Success - fi - let SECONDS_LEFT=SECONDS_LEFT-1 - - # If we have waited >120 seconds, give up - # ZM should never have a database that large! - # if $COUNTER -lt 120 - if [ $SECONDS_LEFT -eq 0 ];then - return -1; - fi -done - -# Restart apache -service apache2 restart - -# Start ZoneMinder -/usr/local/bin/zmpkg.pl start && echo "Zone Minder started" - -while : -do - sleep 3600 -done - -function close_mysql { - kill $(cat /var/run/mysqld/mysqld.pid) - sleep 5 -}