postinstall.sh db creation
This commit is contained in:
parent
3ec2ba3a43
commit
bafcd91a92
1 changed files with 37 additions and 7 deletions
|
@ -2,19 +2,49 @@
|
||||||
#
|
#
|
||||||
# packager.io postinstall script
|
# packager.io postinstall script
|
||||||
#
|
#
|
||||||
set -ex
|
|
||||||
|
PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin:
|
||||||
|
|
||||||
|
DB="zammad_production"
|
||||||
|
DB_USER="zammad"
|
||||||
|
|
||||||
|
# get existing db pass
|
||||||
|
DB_PASS="$(grep "password:" < /opt/zammad/config/database.yml | sed 's/.*password://')"
|
||||||
|
|
||||||
|
# check if db pass exists
|
||||||
|
if [ -z "${DB_PASS}" ]; then
|
||||||
|
# create new db pass
|
||||||
|
DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)"
|
||||||
|
|
||||||
|
# create database
|
||||||
|
cd /tmp
|
||||||
|
su - postgres -c "createdb -E UTF8 ${DB}"
|
||||||
|
|
||||||
|
# create postgres user
|
||||||
|
echo "CREATE USER \"${DB_USER}\" WITH PASSWORD '${DB_PASS}';" | su - postgres -c psql
|
||||||
|
|
||||||
|
# grant privileges
|
||||||
|
echo "GRANT ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql
|
||||||
|
|
||||||
|
# update configfile
|
||||||
|
sed -e "s/ password:/ password: ${DB_PASS}/" < /opt/zammad/config/database.yml.pkgr > /opt/zammad/config/database.yml
|
||||||
|
|
||||||
|
# zammad config set
|
||||||
|
zammad config:set DATABASE_URL=postgres://${DB_USER}:${DB_PASS}@127.0.0.1/${DB}
|
||||||
|
|
||||||
|
# fill database
|
||||||
|
zammad run rake db:migrate
|
||||||
|
zammad run rake db:seed
|
||||||
|
fi
|
||||||
|
|
||||||
# create init scripts
|
# create init scripts
|
||||||
/usr/bin/zammad scale web=1 websocket=1 worker=1
|
zammad scale web=1 websocket=1 worker=1
|
||||||
|
|
||||||
# stop zammad
|
# stop zammad
|
||||||
systemctl stop zammad
|
systemctl stop zammad
|
||||||
|
|
||||||
# db migration
|
# db migration
|
||||||
if /usr/bin/zammad config:get DATABASE_URL ; then
|
zammad run rake db:migrate
|
||||||
/usr/bin/zammad run rake db:migrate
|
|
||||||
fi
|
|
||||||
|
|
||||||
# start zammad
|
# start zammad
|
||||||
systemctl restart zammad
|
systemctl start zammad
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue