2019-02-15 15:11:49 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-12-17 11:10:51 +00:00
|
|
|
|
2017-11-20 23:30:58 +00:00
|
|
|
set -e
|
2017-11-20 22:59:01 +00:00
|
|
|
|
2019-02-04 20:29:24 +00:00
|
|
|
: "${AUTOWIZARD_JSON:=''}"
|
2017-12-03 18:41:55 +00:00
|
|
|
: "${ELASTICSEARCH_HOST:=zammad-elasticsearch}"
|
2018-04-14 13:17:42 +00:00
|
|
|
: "${ELASTICSEARCH_PORT:=9200}"
|
2019-07-04 10:18:14 +00:00
|
|
|
: "${ELASTICSEARCH_SCHEMA:=http}"
|
2020-03-27 12:31:22 +00:00
|
|
|
: "${ELASTICSEARCH_NAMESPACE:=zammad}"
|
2019-07-04 10:18:14 +00:00
|
|
|
: "${ELASTICSEARCH_SSL_VERIFY:=true}"
|
2017-12-03 18:41:55 +00:00
|
|
|
: "${MEMCACHED_HOST:=zammad-memcached}"
|
2018-04-14 14:23:15 +00:00
|
|
|
: "${MEMCACHED_PORT:=11211}"
|
2017-12-03 18:41:55 +00:00
|
|
|
: "${POSTGRESQL_HOST:=zammad-postgresql}"
|
2018-04-14 15:24:05 +00:00
|
|
|
: "${POSTGRESQL_PORT:=5432}"
|
2020-02-24 16:50:19 +00:00
|
|
|
: "${POSTGRESQL_USER:=zammad}"
|
|
|
|
: "${POSTGRESQL_PASS:=zammad}"
|
2018-04-09 16:07:40 +00:00
|
|
|
: "${POSTGRESQL_DB:=zammad_production}"
|
2018-04-10 09:17:23 +00:00
|
|
|
: "${POSTGRESQL_DB_CREATE:=true}"
|
2017-12-03 18:41:55 +00:00
|
|
|
: "${ZAMMAD_RAILSSERVER_HOST:=zammad-railsserver}"
|
2018-04-14 15:40:53 +00:00
|
|
|
: "${ZAMMAD_RAILSSERVER_PORT:=3000}"
|
2017-12-03 18:41:55 +00:00
|
|
|
: "${ZAMMAD_WEBSOCKET_HOST:=zammad-websocket}"
|
2018-04-14 15:40:53 +00:00
|
|
|
: "${ZAMMAD_WEBSOCKET_PORT:=6042}"
|
2017-12-03 18:41:55 +00:00
|
|
|
: "${NGINX_SERVER_NAME:=_}"
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
function check_zammad_ready {
|
2017-12-24 15:08:57 +00:00
|
|
|
sleep 15
|
2017-12-07 14:20:21 +00:00
|
|
|
until [ -f "${ZAMMAD_READY_FILE}" ]; do
|
2017-12-24 13:25:11 +00:00
|
|
|
echo "waiting for init container to finish install or update..."
|
|
|
|
sleep 10
|
2017-11-20 22:59:01 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# zammad init
|
|
|
|
if [ "$1" = 'zammad-init' ]; then
|
2017-12-24 14:04:09 +00:00
|
|
|
# install / update zammad
|
2019-02-04 20:45:33 +00:00
|
|
|
test -f "${ZAMMAD_READY_FILE}" && rm "${ZAMMAD_READY_FILE}"
|
2019-02-05 19:58:48 +00:00
|
|
|
rsync -a --delete --exclude 'public/assets/images/*' --exclude 'storage/fs/*' "${ZAMMAD_TMP_DIR}/" "${ZAMMAD_DIR}"
|
2019-02-04 20:45:33 +00:00
|
|
|
rsync -a "${ZAMMAD_TMP_DIR}"/public/assets/images/ "${ZAMMAD_DIR}"/public/assets/images
|
2017-12-24 13:25:11 +00:00
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
until (echo > /dev/tcp/"${POSTGRESQL_HOST}"/"${POSTGRESQL_PORT}") &> /dev/null; do
|
2017-04-23 22:25:43 +00:00
|
|
|
echo "zammad railsserver waiting for postgresql server to be ready..."
|
2017-03-08 18:37:05 +00:00
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
cd "${ZAMMAD_DIR}"
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2018-04-14 14:23:15 +00:00
|
|
|
# configure database
|
2019-08-29 23:11:14 +00:00
|
|
|
sed -e "s#.*adapter:.*# adapter: postgresql#g" -e "s#.*database:.*# database: ${POSTGRESQL_DB}#g" -e "s#.*username:.*# username: ${POSTGRESQL_USER}#g" -e "s#.*password:.*# password: ${POSTGRESQL_PASS}\\n host: ${POSTGRESQL_HOST}\\n port: ${POSTGRESQL_PORT}#g" < contrib/packager.io/database.yml.pkgr > config/database.yml
|
2018-04-14 14:23:15 +00:00
|
|
|
|
|
|
|
# configure memcache
|
2019-02-04 20:45:33 +00:00
|
|
|
sed -i -e "s/.*config.cache_store.*file_store.*cache_file_store.*/ config.cache_store = :dalli_store, '${MEMCACHED_HOST}:${MEMCACHED_PORT}'\\n config.session_store = :dalli_store, '${MEMCACHED_HOST}:${MEMCACHED_PORT}'/" config/application.rb
|
2017-12-03 18:41:55 +00:00
|
|
|
|
2019-02-04 20:29:24 +00:00
|
|
|
# check if database exists / update to new version
|
2020-03-06 13:41:59 +00:00
|
|
|
echo "initialising / updating database..."
|
|
|
|
if ! (bundle exec rails r 'puts User.any?' 2> /dev/null | grep -q true); then
|
2020-03-07 02:55:36 +00:00
|
|
|
if [ "${POSTGRESQL_DB_CREATE}" == "true" ]; then
|
|
|
|
bundle exec rake db:create
|
|
|
|
fi
|
|
|
|
bundle exec rake db:migrate
|
|
|
|
bundle exec rake db:seed
|
2020-03-06 13:41:59 +00:00
|
|
|
|
2020-03-07 02:55:36 +00:00
|
|
|
# create autowizard.json on first install
|
|
|
|
if [ -n "${AUTOWIZARD_JSON}" ]; then
|
|
|
|
echo "${AUTOWIZARD_JSON}" | base64 -d > auto_wizard.json
|
|
|
|
fi
|
2020-03-06 13:41:59 +00:00
|
|
|
else
|
2020-03-07 02:55:36 +00:00
|
|
|
bundle exec rake db:migrate
|
2017-03-08 18:37:05 +00:00
|
|
|
fi
|
2020-03-06 13:41:59 +00:00
|
|
|
|
2017-07-22 13:14:20 +00:00
|
|
|
# es config
|
2019-02-04 20:29:24 +00:00
|
|
|
echo "changing settings..."
|
2019-07-04 10:18:14 +00:00
|
|
|
bundle exec rails r "Setting.set('es_url', '${ELASTICSEARCH_SCHEMA}://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}')"
|
2017-12-03 18:41:55 +00:00
|
|
|
|
2020-03-27 12:31:22 +00:00
|
|
|
bundle exec rails r "Setting.set('es_index', '${ELASTICSEARCH_NAMESPACE}')"
|
|
|
|
|
2017-12-03 18:41:55 +00:00
|
|
|
if [ -n "${ELASTICSEARCH_USER}" ] && [ -n "${ELASTICSEARCH_PASS}" ]; then
|
|
|
|
bundle exec rails r "Setting.set('es_user', \"${ELASTICSEARCH_USER}\")"
|
|
|
|
bundle exec rails r "Setting.set('es_password', \"${ELASTICSEARCH_PASS}\")"
|
|
|
|
fi
|
2017-11-26 20:25:57 +00:00
|
|
|
|
2018-04-14 13:17:42 +00:00
|
|
|
until (echo > /dev/tcp/${ELASTICSEARCH_HOST}/${ELASTICSEARCH_PORT}) &> /dev/null; do
|
2017-11-26 20:25:57 +00:00
|
|
|
echo "zammad railsserver waiting for elasticsearch server to be ready..."
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
2019-07-04 10:18:14 +00:00
|
|
|
if [ "${ELASTICSEARCH_SSL_VERIFY}" == "false" ]; then
|
|
|
|
SSL_SKIP_VERIFY="-k"
|
|
|
|
else
|
|
|
|
SSL_SKIP_VERIFY=""
|
|
|
|
fi
|
2020-02-19 22:08:11 +00:00
|
|
|
|
2019-07-04 10:18:14 +00:00
|
|
|
if ! curl -s ${SSL_SKIP_VERIFY} ${ELASTICSEARCH_SCHEMA}://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_cat/indices | grep -q zammad; then
|
2018-04-14 13:17:42 +00:00
|
|
|
echo "rebuilding es searchindex..."
|
|
|
|
bundle exec rake searchindex:rebuild
|
|
|
|
fi
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# chown everything to zammad user
|
2019-02-04 20:45:33 +00:00
|
|
|
chown -R "${ZAMMAD_USER}":"${ZAMMAD_USER}" "${ZAMMAD_DIR}"
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# create install ready file
|
2019-02-04 20:45:33 +00:00
|
|
|
su -c "echo 'zammad-init' > ${ZAMMAD_READY_FILE}" "${ZAMMAD_USER}"
|
2017-11-26 20:25:57 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-04 20:29:24 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# zammad nginx
|
|
|
|
if [ "$1" = 'zammad-nginx' ]; then
|
2017-12-24 13:25:11 +00:00
|
|
|
check_zammad_ready
|
|
|
|
|
2020-03-12 22:16:24 +00:00
|
|
|
# configure nginx
|
|
|
|
sed -e "s#server .*:3000#server ${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT}#g" -e "s#server .*:6042#server ${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT}#g" -e "s#server_name .*#server_name ${NGINX_SERVER_NAME};#g" -e 's#/var/log/nginx/zammad.\(access\|error\).log#/dev/stdout#g' < contrib/nginx/zammad.conf > /etc/nginx/sites-enabled/default
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
echo "starting nginx..."
|
|
|
|
|
|
|
|
exec /usr/sbin/nginx -g 'daemon off;'
|
2017-10-02 21:41:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# zammad-railsserver
|
|
|
|
if [ "$1" = 'zammad-railsserver' ]; then
|
2018-12-27 20:48:14 +00:00
|
|
|
test -f /opt/zammad/tmp/pids/server.pid && rm /opt/zammad/tmp/pids/server.pid
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
check_zammad_ready
|
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
cd "${ZAMMAD_DIR}"
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
echo "starting railsserver..."
|
|
|
|
|
2019-02-15 15:11:49 +00:00
|
|
|
#shellcheck disable=SC2101
|
2019-02-04 20:45:33 +00:00
|
|
|
exec gosu "${ZAMMAD_USER}":"${ZAMMAD_USER}" bundle exec rails server puma -b [::] -p "${ZAMMAD_RAILSSERVER_PORT}" -e "${RAILS_ENV}"
|
2017-11-26 20:25:57 +00:00
|
|
|
fi
|
2017-10-02 21:41:16 +00:00
|
|
|
|
2016-12-17 11:10:51 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# zammad-scheduler
|
|
|
|
if [ "$1" = 'zammad-scheduler' ]; then
|
|
|
|
check_zammad_ready
|
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
cd "${ZAMMAD_DIR}"
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
echo "starting scheduler..."
|
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
exec gosu "${ZAMMAD_USER}":"${ZAMMAD_USER}" bundle exec script/scheduler.rb run
|
2017-10-02 21:41:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# zammad-websocket
|
|
|
|
if [ "$1" = 'zammad-websocket' ]; then
|
2017-11-26 20:25:57 +00:00
|
|
|
check_zammad_ready
|
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
cd "${ZAMMAD_DIR}"
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
echo "starting websocket server..."
|
|
|
|
|
2019-02-04 20:45:33 +00:00
|
|
|
exec gosu "${ZAMMAD_USER}":"${ZAMMAD_USER}" bundle exec script/websocket-server.rb -b 0.0.0.0 -p "${ZAMMAD_WEBSOCKET_PORT}" start
|
2016-12-17 11:10:51 +00:00
|
|
|
fi
|