Skip to content

Commit

Permalink
Upload scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
curtishall authored Nov 21, 2023
1 parent b2a55c9 commit a355d19
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 0 deletions.
15 changes: 15 additions & 0 deletions actions/bc-database-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

# Create a new bluecherry server database, following the same procedure used
# by bluecherry's "official" script from bluecherry-apps:misc/postinstall.sh
# but using environment variables as injected from docker or docker-compose.

/usr/share/bluecherry/bc_db_tool.sh new_db \
"$MYSQL_ADMIN_LOGIN" "$MYSQL_ADMIN_PASSWORD" \
"$BLUECHERRY_DB_NAME" "$BLUECHERRY_DB_USER" "$BLUECHERRY_DB_PASSWORD" \
"$BLUECHERRY_DB_HOST" "$BLUECHERRY_USERHOST" \
|| exit 1

exit 0
36 changes: 36 additions & 0 deletions actions/bc-database-upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e

if ! echo 'exit' | mysql -h "$BLUECHERRY_DB_HOST" -D"$BLUECHERRY_DB_NAME" \
-u"$BLUECHERRY_DB_USER" -p"$BLUECHERRY_DB_PASSWORD"
then
echo "Can't connect mysql with credentials in /etc/bluecherry.conf"
echo "Please remove config or fix config"
exit 1
fi

DB_BACKUP_GZ_FILE=$(mktemp ~bluecherry/bc_db_backup.XXXXXXXXXX.sql.gz)
echo "Going to updgrade Bluecherry DB. Taking a backup into $DB_BACKUP_GZ_FILE just in case" >&2

# Backup the DB
mysqldump -h "$BLUECHERRY_DB_HOST" "$BLUECHERRY_DB_NAME" -u"$BLUECHERRY_DB_USER" \
-p"$BLUECHERRY_DB_PASSWORD" | gzip -c > $DB_BACKUP_GZ_FILE

if ! /usr/share/bluecherry/bc_db_tool.sh upgrade_db \
"$BLUECHERRY_DB_NAME" "$BLUECHERRY_DB_USER" \
"$BLUECHERRY_DB_PASSWORD" "$BLUECHERRY_DB_HOST"
then
echo Failed upgrade database, restoring backup
restore_mysql_backup "$BLUECHERRY_DB_NAME" "$BLUECHERRY_DB_USER" \
"$BLUECHERRY_DB_PASSWORD" "$BLUECHERRY_DB_HOST"
exit 1
fi

# database successfully upgraded
if [[ -f "$DB_BACKUP_GZ_FILE" ]]
then
rm -f "$DB_BACKUP_GZ_FILE"
fi

exit 0
9 changes: 9 additions & 0 deletions actions/bc-rsyslog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Save all messages from the bluecherry apps to this log file

$FileGroup bluecherry

:programname,isequal,"bc-server" -/var/log/bluecherry.log
:programname,isequal,"bc-server" -/proc/self/fd/1
:programname,isequal,"bc-server" ~

$FileGroup adm
114 changes: 114 additions & 0 deletions actions/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

set -e

echo "> Update MySQL's my.cnf from environment variables passed in from docker"
echo "> Writing /root/.my.cnf"
{
echo "[client]"; \
echo "user=$MYSQL_ADMIN_LOGIN"; \
echo "password=$MYSQL_ADMIN_PASSWORD"; \
echo "[mysql]"; \
echo "user=$MYSQL_ADMIN_LOGIN"; \
echo "password=$MYSQL_ADMIN_PASSWORD"; \
echo "[mysqldump]"; \
echo "user=$MYSQL_ADMIN_LOGIN"; \
echo "password=$MYSQL_ADMIN_PASSWORD"; \
echo "[mysqldiff]"; \
echo "user=$MYSQL_ADMIN_LOGIN"; \
echo "password=$MYSQL_ADMIN_PASSWORD"; \
} > /root/.my.cnf

echo "> Update bluecherry server's bluecherry.conf from environment variables passed in from docker"
echo "> Writing /etc/bluecherry.conf"
{
echo "# Bluecherry configuration file"; \
echo "# Used to be sure we don't use configurations not suitable for us";\
echo "version = \"1.0\";"; \
echo "bluecherry:"; \
echo "{"; \
echo " db:"; \
echo " {"; \
echo " # 0 = sqlite, 1 = pgsql, 2 = mysql"; \
echo " type = 2;"; \
echo " dbname = \"$BLUECHERRY_DB_NAME\";"; \
echo " user = \"$BLUECHERRY_DB_USER\";"; \
echo " password = \"$BLUECHERRY_DB_PASSWORD\";"; \
echo " host = \"$BLUECHERRY_DB_HOST\";"; \
echo " userhost = \"$BLUECHERRY_DB_ACCESS_HOST\";"; \
echo " };"; \
echo "};"; \
} > /etc/bluecherry.conf

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

# Hack to fix race condition where rsyslog starts too soon and throws errors
# https://github.com/bluecherrydvr/bluecherry-docker/issues/26

# sleep for 5 for good measure
sleep 5

echo "> /usr/sbin/rsyslogd"
# rm rsyslog.pid to prevent respawning
rm -f /run/rsyslogd.pid
/usr/sbin/rsyslogd
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start rsyslog: $status"
exit $status
fi

exec "$@"

/etc/init.d/php7.4-fpm start


echo "> /usr/sbin/nginx"
#source /etc/apache2/envvars
/usr/sbin/nginx
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start nginx web server: $status"
exit $status
fi


echo "> /usr/sbin/bc-server -u bluecherry -g bluecherry"
export LD_LIBRARY_PATH=/usr/lib/bluecherry
/usr/sbin/bc-server -u bluecherry -g bluecherry
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start bluecherry bc-server: $status"
exit $status
fi


# Naive check runs checks once a minute to see if either of the processes exited.
# This illustrates part of the heavy lifting you need to do if you want to run
# 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
done
19 changes: 19 additions & 0 deletions actions/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[supervisord]
nodaemon=true

[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"

[program:bluecherry]
environment=LD_LIBRARY_PATH=/usr/lib/bluecherry
command=/usr/sbin/bc-server -s -u bluecherry -g bluecherry
autostart=true
autorestart=true
startretries=3

[program:rsyslog]
command=/usr/sbin/rsyslogd -n
autostart=true
autorestart=true
startretries=3
redirect_stderr=true

0 comments on commit a355d19

Please sign in to comment.