##// END OF EJS Templates
docs: added 5.8.0 changelog
docs: added 5.8.0 changelog

File last commit:

r337:e82432d9
r423:f4b42dc7 v5.8.0
Show More
entrypoint.sh
230 lines | 6.1 KiB | application/x-sh | BashLexer
#!/usr/bin/env bash
set -Eeo pipefail
keys_dir=/etc/rhodecode/conf/ssh
function config_copy() {
# copy over the configs if they don't exist
echo "checking if config files needs bootstrapping"
for f in /etc/rhodecode/conf_build/*; do
fname=${f##*/}
if [ ! -f "/etc/rhodecode/conf/$fname" ]; then
echo "/etc/rhodecode/conf/$fname does not exists; Copying over as default conf bootstrap..."
cp -v $f /etc/rhodecode/conf/$fname
fi
done
}
function expose_statics() {
echo "exposing static files..."
cp -Rf /var/opt/rhodecode_static/static/ /var/opt/rhodecode_static_data
chmod -R 755 /var/opt/rhodecode_static_data
}
function db_upgrade() {
echo 'ENTRYPOINT: Upgrading database.'
/usr/local/bin/rhodecode_bin/bin/rc-upgrade-db $MAIN_INI_PATH --force-yes
}
function db_init() {
gosu $RC_USER \
/usr/local/bin/rhodecode_bin/bin/rc-setup-app \
$MAIN_INI_PATH \
--force-yes \
--skip-existing-db \
--user=$RHODECODE_USER_NAME \
--password=$RHODECODE_USER_PASS \
--email=$RHODECODE_USER_EMAIL \
--repos=$RHODECODE_REPO_DIR
}
function rhodecode_setup() {
for f in /home/$RC_USER/.rccontrol/bootstrap/*.py; do
fname=${f##*/}
echo "Running script $fname on $RC_TYPE_ID"
gosu $RC_USER /usr/local/bin/rhodecode_bin/bin/rc-ishell $MAIN_INI_PATH <<< "%run $f"
done
}
function generate_mod_dav_conf() {
conf_dir=$(dirname "$MOD_DAV_SVN_CONF_FILE")
if [[ ! -d $conf_dir ]]; then
echo "Creating svn dir $conf_dir ..."
mkdir -p $conf_dir
## 999:999 are set uid/guid in docker build images
chown -v 999:999 $conf_dir
fi
if [[ ! -f $MOD_DAV_SVN_CONF_FILE ]]; then
echo "Generating $MOD_DAV_SVN_CONF_FILE..."
touch $MOD_DAV_SVN_CONF_FILE
## 999:999 are set uid/guid in docker build images
chown -v 999:999 $MOD_DAV_SVN_CONF_FILE
fi
}
function ensure_perms() {
chmod 0600 $keys_dir/ssh_host_rsa_key
chmod 0600 $keys_dir/ssh_host_ecdsa_key
chmod 0600 $keys_dir/ssh_host_ed25519_key
if [[ ! -f $keys_dir/authorized_keys ]]; then
echo "Generating $keys_dir/authorized_keys..."
touch $keys_dir/authorized_keys
chmod 0600 $keys_dir/authorized_keys
fi
}
function generate_ssh_keys() {
if [[ ! -d $keys_dir ]]; then
echo "Creating ssh dir $keys_dir ..."
mkdir -p $keys_dir
## 999:999 are set uid/guid in docker build images
chown -v 999:999 $keys_dir
fi
if [[ ! -f $keys_dir/authorized_keys ]]; then
echo "Generating $keys_dir/authorized_keys..."
touch $keys_dir/authorized_keys
chmod -v 0600 $keys_dir/authorized_keys
fi
if [[ ! -f $keys_dir/authorized_keys_rhodecode ]]; then
echo "Generating $keys_dir/authorized_keys_rhodecode..."
touch $keys_dir/authorized_keys_rhodecode
## 999:999 are set uid/guid in docker build images
chown -v 999:999 $keys_dir/authorized_keys_rhodecode
chmod -v 0600 $keys_dir/authorized_keys_rhodecode
fi
# Generate ssh host key for the first time
if [[ ! -f $keys_dir/ssh_host_rsa_key ]]; then
echo "Generating $keys_dir/ssh_host_rsa_key ..."
gosu "$RC_USER" ssh-keygen -f $keys_dir/ssh_host_rsa_key -N '' -t rsa
gosu "$RC_USER" chmod -v 0600 $keys_dir/ssh_host_rsa_key
fi
if [[ ! -f $keys_dir/ssh_host_ecdsa_key ]]; then
echo "Generating $keys_dir/ssh_host_ecdsa_key ..."
gosu "$RC_USER" ssh-keygen -f $keys_dir/ssh_host_ecdsa_key -N '' -t ecdsa
gosu "$RC_USER" chmod -v 0600 $keys_dir/ssh_host_ecdsa_key
fi
if [[ ! -f $keys_dir/ssh_host_ed25519_key ]]; then
echo "Generating $keys_dir/ssh_host_ed25519_key ..."
gosu "$RC_USER" ssh-keygen -f $keys_dir/ssh_host_ed25519_key -N '' -t ed25519
gosu "$RC_USER" chmod -v 0600 $keys_dir/ssh_host_ed25519_key
fi
grep -qxF 'AllowUsers $RC_USER' $SSHD_CONF_FILE || sed -i "s/AllowUsers USER/AllowUsers $RC_USER/" $SSHD_CONF_FILE
}
echo "ENTRYPOINT: Running $RC_APP_TYPE with cmd '$1'"
isLikelyWeb=
case "$1" in
supervisord | pserve | gunicorn ) isLikelyWeb=1 ;;
esac
if [[ $RC_APP_TYPE = "rhodecode_vcsserver" ]]; then
# copy over default configuration files
config_copy
fi
if [[ $RC_APP_TYPE = "rhodecode_http" ]]; then
# copy over default configuration files
config_copy
# expose our static files on deploy, assuming they are in
# /var/opt/rhodecode_static/static of rhodecode image container
expose_statics
DB_INIT_FILE=/var/opt/rhodecode_data/.dbinit_bootstrapped
if [ "$FORCE_DB_INIT_FILE" = 1 ]; then
rm $DB_INIT_FILE
fi
# Avoid DB_INIT to run multiple times
if [[ ! -e $DB_INIT_FILE ]]; then
echo "ENTRYPOINT: Starting $RC_APP_TYPE initial db bootstrap"
db_init
gosu $RC_USER touch "$DB_INIT_FILE"
echo "ENTRYPOINT: marked as db-bootstrapped at $DB_INIT_FILE"
fi
RC_SETUP_FILE=/var/opt/rhodecode_data/.setup_bootstrapped
if [ "$FORCE_RC_SETUP_APP" = 1 ]; then
rm $RC_SETUP_FILE
fi
# Avoid destroying bootstrapping by simple start/stop
if [[ ! -e $RC_SETUP_FILE ]]; then
echo "ENTRYPOINT: Starting $RC_APP_TYPE initial bootstrap"
# setup application with specific options
if [ "$SETUP_APP" = 1 ]; then
rhodecode_setup
fi
gosu $RC_USER touch "$RC_SETUP_FILE"
echo "ENTRYPOINT: marked as setup-bootstrapped at $RC_SETUP_FILE"
fi
if [ "$DB_UPGRADE" = 1 ]; then
# run DB migrate
echo "Found DB_UPGRADE flag, running DB upgrade"
db_upgrade
fi
fi
if [[ $RC_APP_TYPE = "rhodecode_sshd" ]]; then
# Fix problem with Missing privilege separation directory error
mkdir -p /run/sshd
if [[ $RC_SSH_PORT != "" ]]; then
echo "setting SSHD port to $RC_SSH_PORT"
sed -i -E "s/^#?Port .+/Port $RC_SSH_PORT/" "$SSHD_CONF_FILE"
fi
if [ "$SSH_BOOTSTRAP" = 1 ]; then
# generate SSH keys
generate_ssh_keys
fi
if [ "$SSH_ENSURE_PERMS" = 1 ]; then
# ensure correct permissions are set for SSHD instance
ensure_perms
fi
fi
if [[ $RC_APP_TYPE = "rhodecode_svn" ]]; then
generate_mod_dav_conf
set -- tini -- "$@"
fi
if [ "$RC_APP_PROC" = 1 ]; then
# Fix problem with zombie processes when using executables like supervisord/gunicorn
set -- tini -- "$@"
set -- gosu $RC_USER "$@"
fi
exec "$@"