diff --git a/Docker/README.md b/Docker/README.md index dd9b475e..76eb3567 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -1,5 +1,7 @@ # Install Shinobi with Docker +> Image is based on Ubuntu Bionic (18.04). Node.js 12 is used. MariaDB is included. + 1. Download Repo ``` @@ -16,13 +18,7 @@ docker build --tag shinobi-image:1.0 . 3. This command only works on Linux because of the temporary directory used. This location must exist in RAM. `-v "/dev/shm/shinobiStreams":'/dev/shm/streams':'rw'`. ``` -docker run -d --name='Shinobi' -p '8080:8080/tcp' -v "/dev/shm/shinobiStreams":'/dev/shm/streams':'rw' \ - -v "$HOME/shinobiConfig":'/config':'rw' \ - -v "$HOME/shinobiCustomAutoLoad":'/home/Shinobi/libs/customAutoLoad':'rw' \ - -v "$HOME/shinobiDatabase":'/var/lib/mysql':'rw' \ - -v "$HOME/shinobiVideos":'/home/Shinobi/videos':'rw' \ - -v "$HOME/shinobiPlugins":'/home/Shinobi/plugins':'rw' \ - shinobi-image:1.0 +docker run -d --name='Shinobi' -p '8080:8080/tcp' -v "/dev/shm/shinobiStreams":'/dev/shm/streams':'rw' -v "$HOME/shinobiConfig":'/config':'rw' -v "$HOME/shinobiCustomAutoLoad":'/home/Shinobi/libs/customAutoLoad':'rw' -v "$HOME/shinobiDatabase":'/var/lib/mysql':'rw' -v "$HOME/shinobiVideos":'/home/Shinobi/videos':'rw' -v "$HOME/shinobiPlugins":'/home/Shinobi/plugins':'rw' shinobi-image:1.0 ``` ### Volumes @@ -36,6 +32,20 @@ docker run -d --name='Shinobi' -p '8080:8080/tcp' -v "/dev/shm/shinobiStreams":' | $HOME/shinobiVideos | A map to `/home/Shinobi/videos`. The storage location of your recorded videos. | | $HOME/shinobiPlugins | A map to `/home/Shinobi/plugins`. Mapped so that plugins can easily be modified or swapped. | +### Configurable Environment Variables + + | Environment Variable | Description | Default | + |----------------------|----------------------------------------------------------------------|--------------------| + | SUBSCRIPTION_ID | **THIS IS NOT REQUIRED**. If you are a subscriber to any of the Shinobi services you may use that key as the value for this parameter. If you have donated by PayPal you may use your Transaction ID to activate the license as well. | *None* | + | DB_USER | Username that the Shinobi process will connect to the database with. | majesticflame | + | DB_PASSWORD | Password that the Shinobi process will connect to the database with. | mizukagesbluedress | + | DB_HOST | Address that the Shinobi process will connect to the database with. | localhost | + | DB_DATABASE | Database that the Shinobi process will interact with. | ccio | + | DB_ROOT_USER | Privileged Username for the MariaDB instance. | root | + | DB_ROOT_PASSWORD | Privileged Password for the MariaDB instance. | mizukagesbluedress | + | DB_DISABLE_INCLUDED | Disable included database to use your own. Set to `true` to disable.| false | + + ### Tips Modifying `conf.json` or Superuser credentials. @@ -55,3 +65,23 @@ Container Logs ``` docker logs /Shinobi ``` + +Enter the Command Line of the Container +``` +docker exec -it /Shinobi /bin/bash +``` + +Stop and Remove +``` +docker stop /Shinobi +docker rm /Shinobi +``` + +**WARNING - DEVELOPMENT ONLY!!!** Kill all Containers and Images +> These commands will completely erase all of your docker containers and images. **You have been warned!** + +``` +docker stop /Shinobi +docker rm $(docker ps -a -f status=exited -q) +docker rmi $(docker images -a -q) +``` diff --git a/Docker/init.sh b/Docker/init.sh index 38d1c178..ab5499ab 100644 --- a/Docker/init.sh +++ b/Docker/init.sh @@ -1,64 +1,75 @@ #!/bin/sh set -e -echo "MariaDB Directory ..." -ls /var/lib/mysql +if [ "$DB_DISABLE_INCLUDED" = "false" ]; then + echo "MariaDB Directory ..." + ls /var/lib/mysql -if [ ! -f /var/lib/mysql/ibdata1 ]; then - echo "Installing MariaDB ..." - mysql_install_db --user=mysql --datadir=/var/lib/mysql --silent -fi -echo "Starting MariaDB ..." -/usr/bin/mysqld_safe --user=mysql & -sleep 5s + if [ ! -f /var/lib/mysql/ibdata1 ]; then + echo "Installing MariaDB ..." + mysql_install_db --user=mysql --datadir=/var/lib/mysql --silent + fi + echo "Starting MariaDB ..." + /usr/bin/mysqld_safe --user=mysql & + sleep 5s -chown -R mysql /var/lib/mysql + chown -R mysql /var/lib/mysql -if [ ! -f /var/lib/mysql/ibdata1 ]; then - mysql -u root --password="" <<-EOSQL -SET @@SESSION.SQL_LOG_BIN=0; -USE mysql; -DELETE FROM mysql.user ; -DROP USER IF EXISTS 'root'@'%','root'@'localhost','${DB_USER}'@'localhost','${DB_USER}'@'%'; -CREATE USER 'root'@'%' IDENTIFIED BY '${DB_PASS}' ; -CREATE USER 'root'@'localhost' IDENTIFIED BY '${DB_PASS}' ; -CREATE USER '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASS}' ; -CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}' ; -GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION ; -GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION ; -GRANT ALL PRIVILEGES ON *.* TO '${DB_USER}'@'%' WITH GRANT OPTION ; -GRANT ALL PRIVILEGES ON *.* TO '${DB_USER}'@'localhost' WITH GRANT OPTION ; -DROP DATABASE IF EXISTS test ; -FLUSH PRIVILEGES ; -EOSQL -fi + if [ ! -f /var/lib/mysql/ibdata1 ]; then + mysql -u root --password="" -e "SET @@SESSION.SQL_LOG_BIN=0; + USE mysql; + DELETE FROM mysql.user ; + DROP USER IF EXISTS 'root'@'%','root'@'localhost','${DB_USER}'@'localhost','${DB_USER}'@'%'; + CREATE USER 'root'@'%' IDENTIFIED BY '${DB_PASS}' ; + CREATE USER 'root'@'localhost' IDENTIFIED BY '${DB_PASS}' ; + CREATE USER '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASS}' ; + CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}' ; + GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION ; + GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION ; + GRANT ALL PRIVILEGES ON *.* TO '${DB_USER}'@'%' WITH GRANT OPTION ; + GRANT ALL PRIVILEGES ON *.* TO '${DB_USER}'@'localhost' WITH GRANT OPTION ; + DROP DATABASE IF EXISTS test ; + FLUSH PRIVILEGES ;" + fi + + # Create MySQL database if it does not exists + if [ -n "${DB_HOST}" ]; then + echo "Wait for MySQL server" ... + while ! mysqladmin ping -h"$DB_HOST"; do + sleep 1 + done + fi + + echo "Setting up MySQL database if it does not exists ..." + + echo "Create database schema if it does not exists ..." + mysql -e "source /home/Shinobi/sql/framework.sql" || true + + echo "Create database user if it does not exists ..." + mysql -e "source /home/Shinobi/sql/user.sql" || true + +else + + echo "Create database schema if it does not exists ..." + mysql -u "$DB_ROOT_USER" -h "$DB_HOST" -p"$DB_ROOT_PASSWORD" -e "source /home/Shinobi/sql/framework.sql" || true + + echo "Create database user if it does not exists ..." + mysql -u "$DB_ROOT_USER" -h "$DB_HOST" -p"$DB_ROOT_PASSWORD" -e "source /home/Shinobi/sql/user.sql" || true -# Create MySQL database if it does not exists -if [ -n "${DB_HOST}" ]; then - echo "Wait for MySQL server" ... - while ! mysqladmin ping -h"$DB_HOST"; do - sleep 1 - done fi -echo "Setting up MySQL database if it does not exists ..." - -echo "Create database schema if it does not exists ..." -mysql -e "source /home/Shinobi/sql/framework.sql" || true - -echo "Create database user if it does not exists ..." -mysql -e "source /home/Shinobi/sql/user.sql" || true +cronKey="$(head -c 1024 < /dev/urandom | sha256sum | awk '{print substr($1,1,29)}')" cd /home/Shinobi mkdir -p libs/customAutoLoad if [ -e "/config/conf.json" ]; then cp /config/conf.json conf.json - #Generate a random Cron key for the config file - cronKey=$(head -c 1024 < /dev/urandom | sha256sum | awk '{print substr($1,1,29)}') - #Insert key into conf.json sudo sed -i -e 's/change_this_to_something_very_random__just_anything_other_than_this/'"$cronKey"'/g' conf.json + node tools/modifyConfiguration.js cpuUsageMarker=CPU + node tools/modifyConfiguration.js subscriptionId=$SUBSCRIPTION_ID + cp conf.json /config/conf.json fi #create super.json if [ -e "/config/super.json" ]; then @@ -71,11 +82,10 @@ fi if [ ! -e "./conf.json" ]; then sudo cp conf.sample.json conf.json - sudo cp conf.sample.json /config/conf.json - #Generate a random Cron key for the config file - cronKey=$(head -c 1024 < /dev/urandom | sha256sum | awk '{print substr($1,1,29)}') - #Insert key into conf.json sudo sed -i -e 's/change_this_to_something_very_random__just_anything_other_than_this/'"$cronKey"'/g' conf.json + node tools/modifyConfiguration.js cpuUsageMarker=CPU + node tools/modifyConfiguration.js subscriptionId=$SUBSCRIPTION_ID + sudo cp conf.json /config/conf.json fi #create super.json if [ ! -e "./super.json" ]; then @@ -87,8 +97,6 @@ if [ ! -e "./super.json" ]; then sudo cp super.sample.json /config/super.json fi touch thisIsDocker.txt -node tools/modifyConfiguration.js cpuUsageMarker=CPU -echo "Getting Latest Shinobi Master ..." # Execute Command echo "Starting Shinobi ..." exec "$@" diff --git a/Dockerfile b/Dockerfile index 1d1d862a..5f748464 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,13 @@ FROM ubuntu:bionic -ENV ADMIN_USER=admin@shinobi.video \ - ADMIN_PASSWORD=admin \ - CRON_KEY=fd6c7849-904d-47ea-922b-5143358ba0de \ - PLUGINKEY_MOTION=b7502fd9-506c-4dda-9b56-8e699a6bc41c \ - PLUGINKEY_OPENCV=f078bcfe-c39a-4eb5-bd52-9382ca828e8a \ - PLUGINKEY_OPENALPR=dbff574e-9d4a-44c1-b578-3dc0f1944a3c \ - #leave these ENVs alone unless you know what you are doing - DB_USER=majesticflame \ +ENV DB_USER=majesticflame \ DB_PASSWORD=mizukagesbluedress \ DB_HOST=localhost \ DB_DATABASE=ccio \ DB_ROOT_PASSWORD=mizukagesbluedress \ - DB_ROOT_USER=root + DB_ROOT_USER=root \ + SUBSCRIPTION_ID=sub_XXXXXXXXXXXX \ + DB_DISABLE_INCLUDED=false RUN mkdir -p /home/Shinobi /config /var/lib/mysql @@ -89,6 +84,9 @@ RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 800 --slave /u WORKDIR /home/Shinobi COPY . . +RUN rm -rf /home/Shinobiplugins +COPY ./plugins /home/Shinobi/plugins +RUN chmod -R 777 /home/Shinobi/plugins RUN npm i npm@latest -g && \ npm install pm2 -g && \ npm install --unsafe-perm && \