diff --git a/.pkgr.yml b/.pkgr.yml index 7597bbea8..4984a9990 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -1,3 +1,4 @@ +notifications: false targets: centos-6: dependencies: @@ -11,9 +12,11 @@ targets: - postgresql - postgresql-server - postgresql-devel + debian-8: + dependencies: + - postgresql ubuntu-16.04: dependencies: - - httpd - postgresql before: - uname -a @@ -22,14 +25,11 @@ before: - cp config/database.yml.pkgr config/database.yml - echo "gem 'mysql2'" >> Gemfile.local - "cat Gemfile.lock" - - contrib/cleanup.sh - + - contrib/packager.io/cleanup.sh env: - RAILS_ENV=production - PORT=3000 - RAILS_SERVE_STATIC_FILES=true - services: - postgres - -notifications: false +after_install: contrib/packager.io/postinstall.sh diff --git a/contrib/nginx/nginx.conf b/contrib/nginx/nginx.conf deleted file mode 100644 index d9bd10f65..000000000 --- a/contrib/nginx/nginx.conf +++ /dev/null @@ -1,128 +0,0 @@ - -#user nobody; -worker_processes 1; - -#error_log logs/error.log; -#error_log logs/error.log notice; -error_log /var/log/nginx/error.log info; - -#pid logs/nginx.pid; - - -events { - worker_connections 256; -} - - -http { - include mime.types; - default_type application/octet-stream; - include sites-enabled/*.conf; - #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - # '$status $body_bytes_sent "$http_referer" ' - # '"$http_user_agent" "$http_x_forwarded_for"'; - - #access_log logs/access.log main; - - - sendfile on; - #tcp_nopush on; - - client_max_body_size 50M; - - #keepalive_timeout 0; - keepalive_timeout 65; - proxy_cache_path /tmp/nginx/cache/ levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m; - proxy_temp_path /tmp/nginx/proxy/; - gzip on; - gzip_comp_level 6; - gzip_vary on; - gzip_min_length 1000; - gzip_proxied any; - gzip_types text/plain text/html text/css text/xml application/json application/x-javascript application/xml application/xml+rss text/javascript; - gzip_buffers 16 8k; - - server { - listen 8080; - server_name localhost; - - #charset koi8-r; - - #access_log logs/host.access.log main; - - location / { - root html; - index index.html index.htm; - } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root html; - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} - } - - - # another virtual host using mix of IP-, name-, and port-based configuration - # - #server { - # listen 8000; - # listen somename:8080; - # server_name somename alias another.alias; - - # location / { - # root html; - # index index.html index.htm; - # } - #} - - - # HTTPS server - # - #server { - # listen 443; - # server_name localhost; - - # ssl on; - # ssl_certificate cert.pem; - # ssl_certificate_key cert.key; - - # ssl_session_timeout 5m; - - # ssl_protocols SSLv2 SSLv3 TLSv1; - # ssl_ciphers HIGH:!aNULL:!MD5; - # ssl_prefer_server_ciphers on; - - # location / { - # root html; - # index index.html index.htm; - # } - #} - -} diff --git a/contrib/cleanup.sh b/contrib/packager.io/cleanup.sh similarity index 100% rename from contrib/cleanup.sh rename to contrib/packager.io/cleanup.sh diff --git a/contrib/packager.io/postinstall.sh b/contrib/packager.io/postinstall.sh new file mode 100755 index 000000000..d696e555f --- /dev/null +++ b/contrib/packager.io/postinstall.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# packager.io postinstall script +# + +PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin: + +ZAMMAD_DIR="/opt/zammad" +DB="zammad_production" +DB_USER="zammad" + +# check if database.yml exists +if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then + # get existing db pass + DB_PASS="$(grep "password:" < ${ZAMMAD_DIR}/config/database.yml | sed 's/.*password://')" +fi + +# 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}/" < ${ZAMMAD_DIR}/config/database.yml.pkgr > ${ZAMMAD_DIR}/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 +zammad scale web=1 websocket=1 worker=1 + +# stop zammad +systemctl stop zammad + +# db migration +zammad run rake db:migrate + +# start zammad +systemctl start zammad + +# nginx config +if [ -d /etc/nginx/sites-enabled ]; then + # copy nginx config + test -f /etc/nginx/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/nginx/sites-available/zammad.conf /etc/nginx/sites-available/zammad.conf + # creating symlink + test -f /etc/nginx/sites-available/zammad.conf || ln -s /etc/nginx/sites-available/zammad.conf /etc/nginx/sites-enabled/zammad.conf + # restart nginx + systemctl restart nginx +fi