From 53982e7ff04e34e09300ff8a9c9c8c41fc38802d Mon Sep 17 00:00:00 2001 From: Curtis Hall Date: Mon, 15 Jan 2024 14:48:39 -0600 Subject: [PATCH 1/3] Update Dockerfile --- actions/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/Dockerfile b/actions/Dockerfile index 15d232b6..e8378f45 100644 --- a/actions/Dockerfile +++ b/actions/Dockerfile @@ -214,4 +214,4 @@ RUN chown bluecherry.bluecherry -R /var/lib/bluecherry #CMD service rsyslog start CMD /usr/sbin/php-fpm7.4 -D CMD ["/usr/sbin/nginx", "-g", "daemon off;"] -CMD "/entrypoint.sh" +ENTRYPOINT ["/entrypoint.sh"] From 3d3661c1fb41a3c98f441383d795db83d7dd2c78 Mon Sep 17 00:00:00 2001 From: Curtis Hall Date: Mon, 15 Jan 2024 16:16:29 -0600 Subject: [PATCH 2/3] Update Dockerfile --- actions/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/Dockerfile b/actions/Dockerfile index e8378f45..56f8fdd4 100644 --- a/actions/Dockerfile +++ b/actions/Dockerfile @@ -212,6 +212,6 @@ RUN chown bluecherry.bluecherry -R /var/lib/bluecherry #CMD rm -f /var/run/rsyslogd.pid #CMD ["/usr/sbin/rsyslogd", "-n", "-f", "/etc/rsyslog.conf"] #CMD service rsyslog start -CMD /usr/sbin/php-fpm7.4 -D -CMD ["/usr/sbin/nginx", "-g", "daemon off;"] +#CMD /usr/sbin/php-fpm7.4 -D +#CMD ["/usr/sbin/nginx", "-g", "daemon off;"] ENTRYPOINT ["/entrypoint.sh"] From 36bcf6ca50f9dc9b63b70dfe086cfde1223b3128 Mon Sep 17 00:00:00 2001 From: Curtis Hall Date: Mon, 15 Jan 2024 19:13:15 -0600 Subject: [PATCH 3/3] Update entrypoint.sh --- actions/entrypoint.sh | 52 ++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/actions/entrypoint.sh b/actions/entrypoint.sh index 41292d82..2c5ca1a8 100644 --- a/actions/entrypoint.sh +++ b/actions/entrypoint.sh @@ -14,7 +14,6 @@ echo "> Writing /root/.my.cnf" echo "[mysqldump]"; \ echo "user=$MYSQL_ADMIN_LOGIN"; \ echo "password=$MYSQL_ADMIN_PASSWORD"; \ - echo "host=$BLUECHERRY_DB_HOST"; \ echo "[mysqldiff]"; \ echo "user=$MYSQL_ADMIN_LOGIN"; \ echo "password=$MYSQL_ADMIN_PASSWORD"; \ @@ -45,13 +44,30 @@ echo "> chown bluecherry:bluecherry /var/lib/bluecherry/recordings" chown bluecherry:bluecherry /var/lib/bluecherry/recordings chown -R bluecherry:bluecherry /var/lib/bluecherry/.local/share/data/ - # The bluecherry container's Dockerfile sets rsyslog to route the bluecherry # server's main log file to STDOUT for process #1, which then gets picked up # by docker (so its messages get routed out through docker logs, etc.), but # the location permissions have to be reset on every start of the container: chmod 777 /proc/self/fd/1 +sleep 15 + +license_key=$(mysql bluecherry -e "SELECT license FROM Licenses;" | tail -n +2 | awk '{print $1}') +echo "License key: $license_key" + +deactivate_license() { + echo "Deactivating license..." + /usr/lib/bluecherry/licensecmd bc_v3_license_DeactivateLicense $license_key +} + +on_exit() { + echo "Container is shutting down..." + # Place your command to run before exit here +# deactivate_license $license_key + /usr/lib/bluecherry/licensecmd bc_v3_license_DeactivateLicense $license_key + exit 0 +} + # Hack to fix race condition where rsyslog starts too soon and throws errors # https://github.com/bluecherrydvr/bluecherry-docker/issues/26 @@ -59,6 +75,7 @@ chmod 777 /proc/self/fd/1 sleep 5 echo "> /usr/sbin/rsyslogd" + # rm rsyslog.pid to prevent respawning rm -f /run/rsyslogd.pid /usr/sbin/rsyslogd @@ -72,7 +89,6 @@ exec "$@" /etc/init.d/php7.4-fpm start - echo "> /usr/sbin/nginx" #source /etc/apache2/envvars /usr/sbin/nginx @@ -82,6 +98,7 @@ if [ $status -ne 0 ]; then exit $status fi +trap 'on_exit' SIGTERM SIGINT echo "> /usr/sbin/bc-server -u bluecherry -g bluecherry" export LD_LIBRARY_PATH=/usr/lib/bluecherry @@ -98,18 +115,21 @@ fi # more than one service in a container. The container exits with an error # if it detects that any of the processes has exited. # Otherwise it loops forever, waking up every 15 seconds + while sleep 15; do - ps aux |grep rsyslog |grep -q -v grep - PROCESS_1_STATUS=$? - ps aux |grep nginx |grep -q -v grep - PROCESS_2_STATUS=$? - ps aux |grep bc-server |grep -q -v grep - PROCESS_3_STATUS=$? - - # If the greps above find anything, they exit with 0 status - # If they are not both 0, then something is wrong - if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 -o $PROCESS_3_STATUS -ne 0 ]; then - echo "One of the processes has already exited." - exit 1 - fi + if ! pgrep -x rsyslog > /dev/null; then + echo "rsyslog has exited." + break + fi + if ! pgrep -x nginx > /dev/null; then + echo "nginx has exited." + break + fi + if ! pgrep -x bc-server > /dev/null; then + echo "bc-server has exited." + break + fi done + +# Deactivate license on docker stop. +on_exit