Run Docker db/apache setup once, not on every startup; kill mysql cleanly
This commit is contained in:
parent
d2e83d197d
commit
6a097393ba
|
@ -59,4 +59,8 @@ RUN echo 'zoneminder:zoneminder' | chpasswd
|
|||
# Expose ssh and http ports
|
||||
EXPOSE 22 80
|
||||
|
||||
CMD "/tmp/start.sh"
|
||||
# Initial database and apache setup:
|
||||
RUN "/ZoneMinder/utils/docker/setup.sh"
|
||||
|
||||
CMD ["/ZoneMinder/utils/docker/start.sh"]
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Start MySQL
|
||||
/usr/bin/mysqld_safe &
|
||||
|
||||
# Give MySQL time to wake up
|
||||
SECONDS_LEFT=120
|
||||
while true; do
|
||||
sleep 1
|
||||
mysqladmin ping
|
||||
if [ $? -eq 0 ];then
|
||||
break; # Success
|
||||
fi
|
||||
let SECONDS_LEFT=SECONDS_LEFT-1
|
||||
|
||||
# If we have waited >120 seconds, give up
|
||||
# ZM should never have a database that large!
|
||||
# if $COUNTER -lt 120
|
||||
if [ $SECONDS_LEFT -eq 0 ];then
|
||||
return -1;
|
||||
fi
|
||||
done
|
||||
|
||||
# Create the ZoneMinder database
|
||||
mysql -u root < db/zm_create.sql
|
||||
|
||||
# Add the ZoneMinder DB user
|
||||
mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zmuser'@'localhost' identified by 'zmpass';"
|
||||
|
||||
# Activate CGI
|
||||
a2enmod cgi
|
||||
|
||||
# Activate modrewrite
|
||||
a2enmod rewrite
|
||||
|
||||
# Shut down mysql cleanly:
|
||||
kill $(cat /var/run/mysqld/mysqld.pid)
|
||||
sleep 5
|
||||
|
||||
exit 0
|
|
@ -9,6 +9,9 @@ mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
|
|||
# Start MySQL
|
||||
/usr/bin/mysqld_safe &
|
||||
|
||||
# Ensure we shut down mysql cleanly later:
|
||||
trap close_mysql SIGTERM
|
||||
|
||||
# Give MySQL time to wake up
|
||||
SECONDS_LEFT=120
|
||||
while true; do
|
||||
|
@ -27,18 +30,6 @@ while true; do
|
|||
fi
|
||||
done
|
||||
|
||||
# Create the ZoneMinder database
|
||||
mysql -u root < db/zm_create.sql
|
||||
|
||||
# Add the ZoneMinder DB user
|
||||
mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zmuser'@'localhost' identified by 'zmpass';"
|
||||
|
||||
# Activate CGI
|
||||
a2enmod cgi
|
||||
|
||||
# Activate modrewrite
|
||||
a2enmod rewrite
|
||||
|
||||
# Restart apache
|
||||
service apache2 restart
|
||||
|
||||
|
@ -46,4 +37,14 @@ service apache2 restart
|
|||
/usr/local/bin/zmpkg.pl start
|
||||
|
||||
# Start SSHD
|
||||
/usr/sbin/sshd -D
|
||||
/usr/sbin/sshd
|
||||
|
||||
while :
|
||||
do
|
||||
sleep 3600
|
||||
done
|
||||
|
||||
function close_mysql {
|
||||
kill $(cat /var/run/mysqld/mysqld.pid)
|
||||
sleep 5
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue