ZoneMinder / zmdockerfiles

Dockerfiles for the ZoneMinder project build system and for running ZoneMinder
210 stars 106 forks source link

Empty external database (without schema) fail to start (entrypoint do not create schema ) #59

Closed wayofka closed 4 years ago

wayofka commented 4 years ago

Using external database, database (without schema) and user created only, entrypoint.sh do not handle this, see below in chk_remote_mysql (). Entrypoint.sh call zm_create.sql only when connect to sql server and db not found, but this need user with high privileges. You should consider option when you have external database and user, and call create schema sql only. zm_create.sql need to be parametrized with database name ( database name "zm" is hardcoded )

# Check the status of the remote mysql server using supplied credentials
chk_remote_mysql () {
    if [ "$remoteDB" -eq "1" ]; then
        echo -n " * Looking for remote database server"
        if [ "$(mysql_running)" -eq "1" ]; then
            echo "   ...found."
        else
            echo "   ...failed!"
            return
        fi
        echo -n " * Looking for existing remote database"
        if [ "$(zm_db_exists)" -eq "1" ]; then
            echo "   ...found."
        else
            echo "   ...not found."
            echo -n " * Attempting to create remote database using provided credentials"
            mysql -u${ZM_DB_USER} -p${ZM_DB_PASS} -h${ZM_DB_HOST} < $ZMCREATE
            RETVAL=$?
            if [ "$RETVAL" = "0" ]; then
                echo "   ...done."
            else
                echo "   ...failed!"
                echo " * Error: Remote database must be manually configred."
            fi
        fi
    else
        # This should never happen
        echo " * Error: chk_remote_mysql subroutine called but no sql credentials were given!"
    fi
}

Workaround

Note: database name have to be "zm", otherwise update zm_create.sql

  1. In external mysql, create database and user;
    create database zm;
    grant all privileges on zm.* TO 'user'@'%' identified by 'password';
    flush privileges;
  2. call zm_create.sql from zoneminder container, BUT skip call entrypoint.sh Note: using podman , but for docker is the same

# podman run -it --rm --entrypoint="" zoneminder:latest-el7 /bin/sh -c 'mysql --verbose -h12.34.56.78 -uuser -ppassword zm < /usr/share/zoneminder/db/zm_create.sql '> zm_create.log

  1. run container with external db
    
    # podman run -d -t -p 1080:443 \
    -e TZ='America/Los_Angeles' \
    -e ZM_DB_USER='zmuser' \
    -e ZM_DB_PASS='zmpassword' \
    -e ZM_DB_NAME='zoneminder_database' \
    -e ZM_DB_HOST='my_central_db_server' \


Thank you for making Zoneminder.
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.