2016-12-17 11:10:51 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-11-20 23:30:58 +00:00
|
|
|
set -e
|
2017-11-20 22:59:01 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
function check_zammad_ready {
|
|
|
|
until [ -f "${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}" ]; do
|
|
|
|
echo "waiting for install or update to be ready..."
|
|
|
|
sleep 5
|
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-03-10 08:48:09 +00:00
|
|
|
until (echo > /dev/tcp/zammad-postgresql/5432) &> /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
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# install / update zammad
|
2017-12-02 11:58:46 +00:00
|
|
|
rsync -av --delete --exclude 'storage/fs/*' --exclude 'public/assets/images/*' ${ZAMMAD_TMP_DIR}/ ${ZAMMAD_DIR}
|
|
|
|
rsync -av ${ZAMMAD_TMP_DIR}/public/assets/images/ ${ZAMMAD_DIR}/public/assets/images
|
2017-04-23 22:25:43 +00:00
|
|
|
|
2017-03-08 18:37:05 +00:00
|
|
|
cd ${ZAMMAD_DIR}
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
echo "initialising / updating database..."
|
2017-07-22 13:14:20 +00:00
|
|
|
# db mirgrate
|
2017-11-21 15:19:57 +00:00
|
|
|
set +e
|
2017-05-12 11:21:53 +00:00
|
|
|
bundle exec rake db:migrate &> /dev/null
|
2017-11-21 15:24:57 +00:00
|
|
|
DB_CHECK="$?"
|
|
|
|
set -e
|
2017-03-08 18:37:05 +00:00
|
|
|
|
2017-11-21 15:24:57 +00:00
|
|
|
if [ "${DB_CHECK}" != "0" ]; then
|
2017-03-08 18:37:05 +00:00
|
|
|
bundle exec rake db:create
|
|
|
|
bundle exec rake db:migrate
|
|
|
|
bundle exec rake db:seed
|
|
|
|
fi
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
echo "changing settings..."
|
2017-07-22 13:14:20 +00:00
|
|
|
# es config
|
|
|
|
bundle exec rails r "Setting.set('es_url', 'http://zammad-elasticsearch:9200')"
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
until (echo > /dev/tcp/zammad-elasticsearch/9200) &> /dev/null; do
|
|
|
|
echo "zammad railsserver waiting for elasticsearch server to be ready..."
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "rebuilding es searchindex..."
|
2017-07-22 13:14:20 +00:00
|
|
|
bundle exec rake searchindex:rebuild
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# chown everything to zammad user
|
2017-07-22 13:14:20 +00:00
|
|
|
chown -R ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_DIR}
|
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
# create install ready file
|
|
|
|
su -c "echo 'zammad-init' > ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}" ${ZAMMAD_USER}
|
|
|
|
fi
|
2017-03-08 18:37:05 +00:00
|
|
|
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
# zammad nginx
|
|
|
|
if [ "$1" = 'zammad-nginx' ]; then
|
|
|
|
until [ -f "${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}" ] && [ -n "$(grep zammad-railsserver < ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE})" ] && [ -n "$(grep zammad-scheduler < ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE})" ] && [ -n "$(grep zammad-websocket < ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE})" ] ; do
|
|
|
|
echo "waiting for all zammad services to start..."
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
|
|
|
rm ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}
|
|
|
|
|
|
|
|
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
|
|
|
|
check_zammad_ready
|
|
|
|
|
|
|
|
cd ${ZAMMAD_DIR}
|
|
|
|
|
|
|
|
echo "starting railsserver..."
|
|
|
|
|
|
|
|
echo "zammad-railsserver" >> ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}
|
|
|
|
|
|
|
|
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec puma -b tcp://0.0.0.0:3000 -e ${RAILS_ENV}
|
|
|
|
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
|
|
|
|
|
2017-10-02 21:41:16 +00:00
|
|
|
cd ${ZAMMAD_DIR}
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
echo "starting scheduler..."
|
|
|
|
|
|
|
|
echo "zammad-scheduler" >> ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}
|
|
|
|
|
2017-10-02 21:41:16 +00:00
|
|
|
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/scheduler.rb run
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# zammad-websocket
|
|
|
|
if [ "$1" = 'zammad-websocket' ]; then
|
2017-11-26 20:25:57 +00:00
|
|
|
check_zammad_ready
|
|
|
|
|
2017-10-02 21:41:16 +00:00
|
|
|
cd ${ZAMMAD_DIR}
|
2017-11-26 20:25:57 +00:00
|
|
|
|
|
|
|
echo "starting websocket server..."
|
|
|
|
|
|
|
|
echo "zammad-websocket" >> ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}
|
|
|
|
|
2017-10-02 21:41:16 +00:00
|
|
|
exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/websocket-server.rb -b 0.0.0.0 start
|
2016-12-17 11:10:51 +00:00
|
|
|
fi
|