2020-02-16 03:32:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
QUIET=false
|
|
|
|
#SFLOG="/start.log"
|
|
|
|
|
|
|
|
#print timestamp
|
|
|
|
timestamp() {
|
|
|
|
date +"%Y-%m-%d %T"
|
|
|
|
}
|
|
|
|
|
|
|
|
#screen/file logger
|
|
|
|
sflog() {
|
|
|
|
#if $1 is not null
|
|
|
|
if [ ! -z ${1+x} ]; then
|
|
|
|
message=$1
|
|
|
|
else
|
|
|
|
#exit function
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
#if $QUIET is not true
|
|
|
|
if ! $($QUIET); then
|
|
|
|
echo "${message}"
|
|
|
|
fi
|
|
|
|
#if $SFLOG is not null
|
|
|
|
if [ ! -z ${SFLOG+x} ]; then
|
|
|
|
#if $2 is regular file or does not exist
|
|
|
|
if [ -f ${SFLOG} ] || [ ! -e ${SFLOG} ]; then
|
|
|
|
echo "$(timestamp) ${message}" >> ${SFLOG}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#start services function
|
|
|
|
startc() {
|
|
|
|
sflog "Services for container are being started..."
|
|
|
|
/etc/init.d/fcgiwrap start > /dev/null
|
|
|
|
/etc/init.d/nginx start > /dev/null
|
|
|
|
sflog "The container services have started..."
|
|
|
|
}
|
|
|
|
|
|
|
|
#stop services function
|
|
|
|
stopc() {
|
|
|
|
sflog "Services for container are being stopped..."
|
|
|
|
/etc/init.d/nginx stop > /dev/null
|
|
|
|
/etc/init.d/fcgiwrap stop > /dev/null
|
|
|
|
sflog "Services for container have successfully stopped. Exiting."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
#trap "docker stop <container>" and shuts services down cleanly
|
|
|
|
trap "(stopc)" TERM INT
|
|
|
|
|
|
|
|
#startup
|
|
|
|
|
|
|
|
#test for ENV varibale $FQDN
|
|
|
|
if [ ! -z ${FQDN+x} ]; then
|
|
|
|
sflog "FQDN is set to ${FQDN}"
|
|
|
|
else
|
|
|
|
export FQDN=dehub
|
|
|
|
sflog "FQDN is set to ${FQDN}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#modify config files with fqdn
|
|
|
|
sed -i "s,MYSERVER,${FQDN},g" /etc/nginx/nginx.conf &> /dev/null
|
|
|
|
|
|
|
|
# create the individual repo directories
|
|
|
|
while [ ! -z "$1" ]; do
|
2020-03-29 20:59:01 +00:00
|
|
|
dir="/repos/$1";
|
2020-02-16 03:32:00 +00:00
|
|
|
if [ ! -d "$dir" ]; then
|
|
|
|
echo "Initializing repo $1"
|
|
|
|
mkdir "$dir"
|
2020-04-04 20:13:57 +00:00
|
|
|
dehub init -path "$dir" -bare -remote
|
2020-02-16 03:32:00 +00:00
|
|
|
chown -R git:git "$dir"
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
#start init.d services
|
|
|
|
startc
|
|
|
|
|
|
|
|
#pause script to keep container running...
|
|
|
|
sflog "Services for container successfully started."
|
|
|
|
sflog "Dumping logs"
|
|
|
|
tail -f /var/log/nginx/*.log
|