├── .dockerignore ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── Dockerfile ├── README.md ├── READMETEMPLATE.md └── root ├── defaults └── my.cnf └── etc ├── cont-init.d ├── 30-config └── 40-initialise-db └── services.d ├── mariadb └── run ├── web └── run └── zoneminder └── run /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .gitignore 3 | .github 4 | .gitattributes 5 | READMETEMPLATE.md 6 | README.md 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [linuxserverurl]: https://linuxserver.io 4 | [![linuxserver.io](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/linuxserver_medium.png)][linuxserverurl] 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ## Thanks, team linuxserver.io 21 | 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [linuxserverurl]: https://linuxserver.io 4 | [![linuxserver.io](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/linuxserver_medium.png)][linuxserverurl] 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ## Thanks, team linuxserver.io 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lsiobase/ubuntu:xenial 2 | 3 | # set version label 4 | ARG BUILD_DATE 5 | ARG VERSION 6 | LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" 7 | LABEL maintainer="sparklyballs" 8 | 9 | # environment variables 10 | ARG DEBIAN_FRONTEND="noninteractive" 11 | ENV MYSQL_DIR="/data" 12 | ENV DATADIR=$MYSQL_DIR/database 13 | 14 | # packages as variables 15 | ARG BUILD_DEPENDENCIES="\ 16 | cmake \ 17 | dh-autoreconf \ 18 | dpatch \ 19 | g++ \ 20 | gcc \ 21 | git \ 22 | libavcodec-dev \ 23 | libavdevice-dev \ 24 | libavfilter-dev \ 25 | libavformat-dev \ 26 | libavresample-dev \ 27 | libavutil-dev \ 28 | libcurl4-openssl-dev \ 29 | libjpeg-turbo8-dev \ 30 | libmp4v2-dev \ 31 | libmysqlclient-dev \ 32 | libnetpbm10-dev \ 33 | libpcre3-dev \ 34 | libpolkit-gobject-1-dev \ 35 | libpostproc-dev \ 36 | libswscale-dev \ 37 | libtheora-dev \ 38 | libtool \ 39 | libv4l-dev \ 40 | libvlccore-dev \ 41 | libvlc-dev \ 42 | libvorbis-dev \ 43 | libvpx-dev \ 44 | libx264-dev \ 45 | php-dev \ 46 | php-pear \ 47 | yasm" 48 | 49 | ARG RUNTIME_DEPENDENCIES="\ 50 | apache2 \ 51 | ffmpeg \ 52 | libapache2-mod-php \ 53 | libarchive-zip-perl \ 54 | libav-tools \ 55 | libbz2-dev \ 56 | libclass-std-fast-perl \ 57 | libcurl3 \ 58 | libdata-dump-perl \ 59 | libdata-uuid-perl \ 60 | libdate-manip-perl \ 61 | libdbd-mysql-perl \ 62 | libdbi-perl \ 63 | libdevice-serialport-perl \ 64 | libio-socket-multicast-perl \ 65 | libjpeg-turbo8 \ 66 | libmime-lite-perl \ 67 | libmime-perl \ 68 | libmp4v2-2 \ 69 | libpcre3 \ 70 | libsoap-wsdl-perl \ 71 | libssl-dev \ 72 | libsys-cpu-perl \ 73 | libsys-meminfo-perl \ 74 | libsys-mmap-perl \ 75 | libvlc5 \ 76 | libvlccore8 \ 77 | libwww-perl \ 78 | mariadb-client \ 79 | mariadb-server \ 80 | net-tools \ 81 | php \ 82 | php-cli \ 83 | php-mysql \ 84 | unzip \ 85 | vlc-data \ 86 | zip" 87 | 88 | RUN \ 89 | echo "**** add repositories ****" && \ 90 | apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 && \ 91 | echo "deb [arch=amd64,i386] http://mirrors.coreix.net/mariadb/repo/10.1/ubuntu xenial main" >> \ 92 | /etc/apt/sources.list.d/mariadb.list && \ 93 | echo "deb-src http://mirrors.coreix.net/mariadb/repo/10.1/ubuntu xenial main" >> \ 94 | /etc/apt/sources.list.d/mariadb.list && \ 95 | echo "**** install packages ****" && \ 96 | apt-get update && \ 97 | apt-get install -y \ 98 | --no-install-recommends \ 99 | $BUILD_DEPENDENCIES \ 100 | $RUNTIME_DEPENDENCIES && \ 101 | echo "**** install php_apcu and php_apcu-bc ****" && \ 102 | pecl install apcu && \ 103 | pecl install apcu_bc-beta && \ 104 | echo "extension=apc.so" >> /etc/php/7.0/mods-available/z_apc.ini && \ 105 | echo "extension=apcu.so" >> /etc/php/7.0/mods-available/apcu.ini && \ 106 | ln -sf \ 107 | /etc/php/7.0/mods-available/apcu.ini \ 108 | /etc/php/7.0/apache2/conf.d/20-apcu.ini && \ 109 | ln -sf \ 110 | /etc/php/7.0/mods-available/apcu.ini \ 111 | /etc/php/7.0/cli/conf.d/20-apcu.ini && \ 112 | ln -sf \ 113 | /etc/php/7.0/mods-available/z_apc.ini \ 114 | /etc/php/7.0/apache2/conf.d/40-apc.ini && \ 115 | ln -sf \ 116 | /etc/php/7.0/mods-available/z_apc.ini \ 117 | /etc/php/7.0/cli/conf.d/40-apc.ini && \ 118 | echo "**** build zoneminder ****" && \ 119 | git clone https://github.com/ZoneMinder/ZoneMinder /tmp/zoneminder && \ 120 | cd /tmp/zoneminder && \ 121 | git submodule update --init --recursive && \ 122 | cmake \ 123 | -DCMAKE_INSTALL_PREFIX=/usr \ 124 | -DZM_CGIDIR=/usr/share/webapps/zoneminder/cgi-bin \ 125 | -DZM_CONFIG_DIR=/etc/zm \ 126 | -DZM_CONFIG_SUBDIR=/etc/zm/conf.d \ 127 | -DZM_DIR_EVENTS=/data/zoneminder/events \ 128 | -DZM_DIR_IMAGES=/data/zoneminder/images \ 129 | -DZM_DIR_SOUNDS=/data/zoneminder/sounds \ 130 | -DZM_LOGDIR=/config/log/zoneminder \ 131 | -DZM_PATH_ARP=/usr/sbin/arp \ 132 | -DZM_RUNDIR=/var/run/zoneminder \ 133 | -DZM_SOCKDIR=/var/run/zoneminder \ 134 | -DZM_WEBDIR=/usr/share/webapps/zoneminder/htdocs \ 135 | -DZM_WEB_GROUP=abc \ 136 | -DZM_WEB_USER=abc \ 137 | . && \ 138 | make && \ 139 | make install && \ 140 | echo "**** configure zoneminder exports folder and add abc to video group ****" && \ 141 | sed -i \ 142 | -e "s#\(ZM_DIR_EXPORTS.*=\).*#\1/data/zoneminder/exports#g" \ 143 | /etc/zm/conf.d/01-system-paths.conf && \ 144 | adduser abc video && \ 145 | echo "**** configure apache ****" && \ 146 | cp misc/apache.conf /defaults/default.conf && \ 147 | a2enmod cgi rewrite && \ 148 | sed -i \ 149 | -e "s/\(.*APACHE_RUN_USER=\).*/\1abc/g" \ 150 | -e "s/\(.*APACHE_RUN_GROUP=\).*/\1abc/g" \ 151 | /etc/apache2/envvars && \ 152 | echo "**** configure my.cnf and mysqld_safe ****" && \ 153 | sed \ 154 | -i -e 's/^#sql_mode/sql_mode/g' \ 155 | -i -e 's/NO_ENGINE_SUBSTITUTION.*/NO_ENGINE_SUBSTITUTION/g' \ 156 | -i -e 's/key_buffer\b/key_buffer_size/g' \ 157 | -i -e 's#/var/log/mysql#/config/log/mysql#g' \ 158 | -i -e 's/\(max_allowed_packet.*=\).*/\1 128M/g' \ 159 | -i -e 's/\(user.*=\).*/\1 abc/g' \ 160 | -i -e 's/\(wait_timeout.*=\).*/\1 1200/g' \ 161 | -i -e "s#\(datadir.*=\).*#\1 $DATADIR#g" \ 162 | -ri -e 's/^(bind-address|skip-networking)/;\1/' \ 163 | /etc/mysql/my.cnf && \ 164 | sed -i \ 165 | "s/user='mysql'/user='abc'/g" \ 166 | /usr/bin/mysqld_safe && \ 167 | echo "**** uninstall build packages and reinstall runtime packages ****" && \ 168 | apt-get purge -y --auto-remove \ 169 | $BUILD_DEPENDENCIES && \ 170 | apt-get install -y \ 171 | --no-install-recommends \ 172 | $RUNTIME_DEPENDENCIES && \ 173 | echo "**** cleanup ****" && \ 174 | rm -rf \ 175 | /tmp/* \ 176 | /var/lib/apt/lists/* \ 177 | /var/lib/mysql \ 178 | /var/tmp/* && \ 179 | mkdir -p \ 180 | /var/lib/mysql 181 | 182 | # add local files 183 | COPY root/ / 184 | 185 | # ports and volumes 186 | EXPOSE 80 187 | VOLUME /config /data 188 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [linuxserverurl]: https://linuxserver.io 2 | [forumurl]: https://forum.linuxserver.io 3 | [ircurl]: https://www.linuxserver.io/irc/ 4 | [podcasturl]: https://www.linuxserver.io/podcast/ 5 | 6 | [![linuxserver.io](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/linuxserver_medium.png)][linuxserverurl] 7 | 8 | ## This is a Container in active development by the [LinuxServer.io][linuxserverurl] team and is not recommended for use by the general public. 9 | 10 | If you want to comment\contribute on this container , are looking for support on any of our other work , or are curious about us in general, check out the following. 11 | 12 | * [forum.linuxserver.io][forumurl] 13 | * [IRC][ircurl] on freenode at `#linuxserver.io` 14 | * [Podcast][podcasturl] covers everything to do with getting the most from your Linux Server plus a focus on all things Docker and containerisation! 15 | 16 | -------------------------------------------------------------------------------- /READMETEMPLATE.md: -------------------------------------------------------------------------------- 1 | [linuxserverurl]: https://linuxserver.io 2 | [forumurl]: https://forum.linuxserver.io 3 | [ircurl]: https://www.linuxserver.io/irc/ 4 | [podcasturl]: https://www.linuxserver.io/podcast/ 5 | [appurl]: www.example.com 6 | [hub]: https://hub.docker.com/r/example/example/ 7 | 8 | [![linuxserver.io](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/linuxserver_medium.png)][linuxserverurl] 9 | 10 | The [LinuxServer.io][linuxserverurl] team brings you another container release featuring easy user mapping and community support. Find us for support at: 11 | * [forum.linuxserver.io][forumurl] 12 | * [IRC][ircurl] on freenode at `#linuxserver.io` 13 | * [Podcast][podcasturl] covers everything to do with getting the most from your Linux Server plus a focus on all things Docker and containerisation! 14 | 15 | # 16 | 17 | Provide a short, concise description of the application. No more than two SHORT paragraphs. Link to sources where possible and include an image illustrating your point if necessary. Point users to the original applications website, as that's the best place to get support - not here. 18 | 19 | Our Plex container has immaculate docs so follow that if in doubt for layout. 20 | 21 | `IMPORTANT, replace all instances of with the correct dockerhub repo (ie linuxserver/plex) and information (ie, plex)` 22 | 23 | ## Usage 24 | 25 | ``` 26 | docker create \ 27 | --name= \ 28 | -v :/config \ 29 | -e PGID= -e PUID= \ 30 | -p 1234:1234 \ 31 | 32 | ``` 33 | 34 | ## Parameters 35 | 36 | `The parameters are split into two halves, separated by a colon, the left hand side representing the host and the right the container side. 37 | For example with a port -p external:internal - what this shows is the port mapping from internal to external of the container. 38 | So -p 8080:80 would expose port 80 from inside the container to be accessible from the host's IP on port 8080 39 | http://192.168.x.x:8080 would show you what's running INSIDE the container on port 80.` 40 | 41 | 42 | 43 | * `-p 1234` - the port(s) 44 | * `-v /config` - explain what lives here 45 | * `-e PGID` for GroupID - see below for explanation 46 | * `-e PUID` for UserID - see below for explanation 47 | 48 | It is based on alpine linux with s6 overlay, for shell access whilst the container is running do `docker exec -it /bin/bash`. 49 | 50 | ### User / Group Identifiers 51 | 52 | Sometimes when using data volumes (`-v` flags) permissions issues can arise between the host OS and the container. We avoid this issue by allowing you to specify the user `PUID` and group `PGID`. Ensure the data volume directory on the host is owned by the same user you specify and it will "just work" ™. 53 | 54 | In this instance `PUID=1001` and `PGID=1001`. To find yours use `id user` as below: 55 | 56 | ``` 57 | $ id 58 | uid=1001(dockeruser) gid=1001(dockergroup) groups=1001(dockergroup) 59 | ``` 60 | 61 | ## Setting up the application 62 | 63 | Insert a basic user guide here to get a n00b up and running with the software inside the container. DELETE ME 64 | 65 | 66 | ## Info 67 | 68 | * Shell access whilst the container is running: `docker exec -it /bin/bash` 69 | * To monitor the logs of the container in realtime: `docker logs -f ` 70 | 71 | * container version number 72 | 73 | `docker inspect -f '{{ index .Config.Labels "build_version" }}' ` 74 | 75 | * image version number 76 | 77 | `docker inspect -f '{{ index .Config.Labels "build_version" }}' ` 78 | 79 | ## Versions 80 | 81 | + **dd.MM.yy:** Initial Release. 82 | -------------------------------------------------------------------------------- /root/defaults/my.cnf: -------------------------------------------------------------------------------- 1 | ## custom configuration file, please be aware that changing options here may break things 2 | 3 | [mysqld_safe] 4 | nice = 0 5 | 6 | [mysqld] 7 | max_connections = 100 8 | connect_timeout = 5 9 | wait_timeout = 600 10 | max_allowed_packet = 16M 11 | thread_cache_size = 128 12 | sort_buffer_size = 4M 13 | bulk_insert_buffer_size = 16M 14 | tmp_table_size = 32M 15 | max_heap_table_size = 32M 16 | binlog_format=mixed 17 | # 18 | # * MyISAM 19 | # 20 | # This replaces the startup script and checks MyISAM tables if needed 21 | # the first time they are touched. On error, make copy and try a repair. 22 | myisam_recover_options = BACKUP 23 | key_buffer_size = 128M 24 | #open-files-limit = 2000 25 | table_open_cache = 400 26 | myisam_sort_buffer_size = 512M 27 | concurrent_insert = 2 28 | read_buffer_size = 2M 29 | read_rnd_buffer_size = 1M 30 | # 31 | # * Query Cache Configuration 32 | # 33 | # Cache only tiny result sets, so we can fit more in the query cache. 34 | query_cache_limit = 128K 35 | query_cache_size = 64M 36 | # for more write intensive setups, set to DEMAND or OFF 37 | #query_cache_type = DEMAND 38 | # 39 | # * Logging and Replication 40 | # 41 | # Both location gets rotated by the cronjob. 42 | # Be aware that this log type is a performance killer. 43 | # As of 5.1 you can enable the log at runtime! 44 | #general_log_file = /config/log/mysql/mysql.log 45 | #general_log = 1 46 | # 47 | # Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. 48 | # 49 | # we do want to know about network errors and such 50 | log_warnings = 2 51 | # 52 | # Enable the slow query log to see queries with especially long duration 53 | #slow_query_log[={0|1}] 54 | slow_query_log_file = /config/log/mysql/mariadb-slow.log 55 | long_query_time = 10 56 | #log_slow_rate_limit = 1000 57 | log_slow_verbosity = query_plan 58 | 59 | #log-queries-not-using-indexes 60 | #log_slow_admin_statements 61 | # 62 | # The following can be used as easy to replay backup logs or for replication. 63 | # note: if you are setting up a replication slave, see README.Debian about 64 | # other settings you may need to change. 65 | #server-id = 1 66 | #report_host = master1 67 | #auto_increment_increment = 2 68 | #auto_increment_offset = 1 69 | log_bin = /config/log/mysql/mariadb-bin 70 | log_bin_index = /config/log/mysql/mariadb-bin.index 71 | # not fab for performance, but safer 72 | #sync_binlog = 1 73 | expire_logs_days = 10 74 | max_binlog_size = 100M 75 | # slaves 76 | #relay_log = /config/log/mysql/relay-bin 77 | #relay_log_index = /config/log/mysql/relay-bin.index 78 | #relay_log_info_file = /config/log/mysql/relay-bin.info 79 | #log_slave_updates 80 | #read_only 81 | # 82 | # If applications support it, this stricter sql_mode prevents some 83 | # mistakes like inserting invalid dates etc. 84 | #sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL 85 | # 86 | # * InnoDB 87 | # 88 | # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. 89 | # Read the manual for more InnoDB related options. There are many! 90 | default_storage_engine = InnoDB 91 | # you can't just change log file size, requires special procedure 92 | #innodb_log_file_size = 50M 93 | innodb_buffer_pool_size = 256M 94 | innodb_log_buffer_size = 8M 95 | innodb_file_per_table = 1 96 | innodb_open_files = 400 97 | innodb_io_capacity = 400 98 | innodb_flush_method = O_DIRECT 99 | # 100 | # * Security Features 101 | # 102 | # Read the manual, too, if you want chroot! 103 | # chroot = /var/lib/mysql/ 104 | # 105 | # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". 106 | # 107 | # ssl-ca=/etc/mysql/cacert.pem 108 | # ssl-cert=/etc/mysql/server-cert.pem 109 | # ssl-key=/etc/mysql/server-key.pem 110 | 111 | # 112 | # * Galera-related settings 113 | # 114 | [galera] 115 | # Mandatory settings 116 | #wsrep_on=ON 117 | #wsrep_provider= 118 | #wsrep_cluster_address= 119 | #default_storage_engine=InnoDB 120 | #innodb_autoinc_lock_mode=2 121 | # 122 | # Allow server to accept connections on all interfaces. 123 | # 124 | #bind-address=0.0.0.0 125 | # 126 | # Optional setting 127 | #wsrep_slave_threads=1 128 | #innodb_flush_log_at_trx_commit=0 129 | 130 | [mysqldump] 131 | quick 132 | quote-names 133 | max_allowed_packet = 16M 134 | 135 | [mysql] 136 | #no-auto-rehash # faster start of mysql but no tab completion 137 | 138 | [isamchk] 139 | key_buffer_size = 16M 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /root/etc/cont-init.d/30-config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bash 2 | 3 | # set php timezone 4 | PHP_TZ=${PHP_TZ:-Europe/London} 5 | sed -i "s#;date.timezone =.*#date.timezone = $PHP_TZ#" /etc/php/7.0/apache2/php.ini 6 | 7 | # make folders if required 8 | mkdir -p \ 9 | "$DATADIR" \ 10 | /config/{apache,log/mysql,log/zoneminder,mysql,zoneminder} \ 11 | /data/{zoneminder/events,zoneminder/exports,zoneminder/images,zoneminder/sounds} \ 12 | /var/run/mysqld \ 13 | /var/run/zoneminder 14 | 15 | 16 | # copy apache config 17 | [[ ! -f /config/apache/zoneminder.conf ]] && \ 18 | cp /defaults/default.conf /config/apache/zoneminder.conf 19 | cp /config/apache/zoneminder.conf /etc/apache2/sites-available/000-default.conf 20 | 21 | # cleanup stale pid and sock files 22 | [[ -e /var/run/mysqld/mysqld.sock || -e /var/run/mysqld/mysqld.pid ]] && \ 23 | rm -rf /var/run/mysqld/* 24 | [[ -e /var/run/zoneminder/zmdc.sock || -e /var/run/zoneminder/zm.pid ]] && \ 25 | rm -rf /var/run/zoneminder/* 26 | [[ -e /var/run/apache2/apache2.pid ]] && \ 27 | rm -rf /var/run/apache2/* 28 | 29 | # setup custom cnf file 30 | [[ ! -f /config/mysql/custom.cnf ]] && \ 31 | cp /defaults/my.cnf /config/mysql/custom.cnf 32 | [[ ! -L /etc/mysql/conf.d/custom.cnf && -f /etc/mysql/conf.d/custom.cnf ]] && \ 33 | rm /etc/mysql/conf.d/custom.cnf 34 | [[ ! -L /etc/mysql/conf.d/custom.cnf ]] && \ 35 | ln -s /config/mysql/custom.cnf /etc/mysql/conf.d/custom.cnf 36 | 37 | # set permissions 38 | if [ -e /etc/mysql/debian.cnf ] ; then 39 | chown abc:abc /etc/mysql/debian.cnf 40 | chmod 644 /etc/mysql/debian.cnf 41 | fi 42 | 43 | chgrp -c abc /etc/zm/zm.conf 44 | chmod 640 /etc/zm/zm.conf 45 | chown abc:abc \ 46 | /data 47 | chown -R abc:abc \ 48 | /config \ 49 | /data/zoneminder 50 | chmod -R 777 \ 51 | /var/lib/apache2 \ 52 | /var/run/mysqld \ 53 | /var/run/zoneminder 54 | -------------------------------------------------------------------------------- /root/etc/cont-init.d/40-initialise-db: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bash 2 | 3 | 4 | # set start function that creates user and password, used later 5 | start_mysql(){ 6 | mysqld --init-file="$tempSqlFile" & 7 | pid="$!" 8 | RET=1 9 | while [[ RET -ne 0 ]]; do 10 | mysql -uroot -e "status" > /dev/null 2>&1 11 | RET=$? 12 | sleep 1 13 | done 14 | mysql -uroot < /usr/share/zoneminder/db/zm_create.sql 15 | mysql -uroot -e "grant select,insert,update,delete,create,alter,index,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';" 16 | } 17 | 18 | # test for existence of mysql file in datadir and start initialise if not present 19 | if [ ! -d "$DATADIR/mysql" ]; then 20 | 21 | # set basic sql command 22 | tempSqlFile='/tmp/mysql-first-time.sql' 23 | cat > "$tempSqlFile" <<-EOSQL 24 | DELETE FROM mysql.user ; 25 | EOSQL 26 | 27 | # set what to display if no password set with variable MYSQL_ROOT_PASSWORD 28 | NOPASS_SET='/tmp/no-pass.nfo' 29 | cat > $NOPASS_SET <<-EOFPASS 30 | ################################################################# 31 | # No root password or too short a password ,min of 4 characters # 32 | # No root password will be set, this is not a good thing # 33 | # You shoud set one after initialisation with the command # 34 | # mysqladmin -u root password # 35 | ################################################################# 36 | EOFPASS 37 | 38 | # test for empty password variable, if it's set to 0 or less than 4 characters 39 | if [ -z "$MYSQL_ROOT_PASSWORD" ]; then 40 | TEST_LEN="0" 41 | else 42 | TEST_LEN=${#MYSQL_ROOT_PASSWORD} 43 | fi 44 | if [ "$TEST_LEN" -lt "4" ]; then 45 | MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '' ;" 46 | else 47 | MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;" 48 | fi 49 | 50 | # add rest of sql commands based on password set or not 51 | cat >> "$tempSqlFile" <<-EONEWSQL 52 | $MYSQL_PASS 53 | GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; 54 | DROP DATABASE IF EXISTS test ; 55 | EONEWSQL 56 | echo "Setting Up Initial Databases" 57 | 58 | # set some permissions needed before we begin initialising 59 | chown -R abc:abc /config/log/mysql /var/run/mysqld 60 | chmod -R 777 /config/log/mysql /var/run/mysqld 61 | 62 | # initialise database structure 63 | mysql_install_db --datadir="$DATADIR" 64 | 65 | # start mysql and apply our sql commands we set above 66 | start_mysql 67 | 68 | # shut down after apply sql commands, waiting for pid to stop 69 | mysqladmin -u root shutdown 70 | wait "$pid" 71 | echo "Database Setup Completed" 72 | 73 | # display a message about password if not set or too short 74 | if [ "$TEST_LEN" -lt "4" ]; then 75 | printf '\n\n\n%s\n\n\n' "$(