From f4efae18c916827c8634dc82e765f9414e592937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 3 Oct 2017 11:27:27 +0200 Subject: [PATCH] changed systemd scripts to use env file --- script/systemd/install-zammad-systemd-services.sh | 11 ++++++++++- script/systemd/zammad-rails.service | 15 +++++---------- script/systemd/zammad-scheduler.service | 14 ++++++-------- script/systemd/zammad-websocket.service | 15 +++++---------- script/systemd/zammad.env | 8 ++++++++ script/systemd/zammad.service | 6 +++--- 6 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 script/systemd/zammad.env diff --git a/script/systemd/install-zammad-systemd-services.sh b/script/systemd/install-zammad-systemd-services.sh index ef394d855..32eca195f 100755 --- a/script/systemd/install-zammad-systemd-services.sh +++ b/script/systemd/install-zammad-systemd-services.sh @@ -3,12 +3,21 @@ # enable zammad systemd services # +ZAMMAD_ENV_DIR="/etc/zammad" +SYSTEMD_SERVICE_DIR="/etc/systemd/system" + if [ "$(whoami)" != 'root' ]; then echo "you need to be root to run this script!" exit 1 fi -cp zammad.service zammad-rails.service zammad-scheduler.service zammad-websocket.service /etc/systemd/system +test -d ${ZAMMAD_ENV_DIR} || mkdir -p ${ZAMMAD_ENV_DIR} + +test -d ${SYSTEMD_SERVICE_DIR} || mkdir -p ${SYSTEMD_SERVICE_DIR} + +cp zammad.env ${ZAMMAD_ENV_DIR} + +cp zammad.service zammad-rails.service zammad-scheduler.service zammad-websocket.service ${SYSTEMD_SERVICE_DIR} systemctl daemon-reload diff --git a/script/systemd/zammad-rails.service b/script/systemd/zammad-rails.service index 0deb54a2d..68107b735 100644 --- a/script/systemd/zammad-rails.service +++ b/script/systemd/zammad-rails.service @@ -6,19 +6,14 @@ After=zammad.service Requires=zammad.service [Service] -Type=simple -User=zammad -Group=zammad +EnvironmentFile=/etc/zammad/zammad.env +User=${ZAMMAD_USER:-zammad} +Group=${ZAMMAD_GROUP:-zammad} Restart=always -WorkingDirectory=/opt/zammad +WorkingDirectory=${ZAMMAD_WORKING_DIRECTORY:-/opt/zammad} -Environment=RAILS_ENV=production -Environment=BUNDLE_BINARY=bundle -Environment=ZAMMAD_BIND_IP=127.0.0.1 -Environment=ZAMMAD_RAILS_PORT=3000 - -ExecStart=/bin/bash -l -c "${BUNDLE_BINARY} exec script/rails server -b ${ZAMMAD_BIND_IP} -p ${ZAMMAD_RAILS_PORT}" +ExecStart=/bin/bash -l -c "${BUNDLE_BINARY:-bundle} exec script/rails server -b ${ZAMMAD_BIND_IP:-127.0.0.1} -p ${ZAMMAD_RAILS_PORT:-3000}" [Install] WantedBy=zammad.service diff --git a/script/systemd/zammad-scheduler.service b/script/systemd/zammad-scheduler.service index ee1fe4b3a..b4a6a0e53 100644 --- a/script/systemd/zammad-scheduler.service +++ b/script/systemd/zammad-scheduler.service @@ -6,17 +6,15 @@ After=zammad.service Requires=zammad.service [Service] -Type=simple -User=zammad -Group=zammad +Type=forking +EnvironmentFile=/etc/zammad/zammad.env +User=${ZAMMAD_USER:-zammad} +Group=${ZAMMAD_GROUP:-zammad} Restart=always -WorkingDirectory=/opt/zammad +WorkingDirectory=${ZAMMAD_WORKING_DIRECTORY:-/opt/zammad} -Environment=RAILS_ENV=production -Environment=BUNDLE_BINARY=bundle - -ExecStart=/bin/bash -l -c "${BUNDLE_BINARY} exec script/scheduler.rb start -t" +ExecStart=/bin/bash -l -c "${BUNDLE_BINARY:-bundle} exec script/scheduler.rb start" [Install] WantedBy=zammad.service diff --git a/script/systemd/zammad-websocket.service b/script/systemd/zammad-websocket.service index 2e875f376..d022e78d4 100644 --- a/script/systemd/zammad-websocket.service +++ b/script/systemd/zammad-websocket.service @@ -6,19 +6,14 @@ After=zammad.service Requires=zammad.service [Service] -Type=simple -User=zammad -Group=zammad +EnvironmentFile=/etc/zammad/zammad.env +User=${ZAMMAD_USER:-zammad} +Group=${ZAMMAD_GROUP:-zammad} Restart=always -WorkingDirectory=/opt/zammad +WorkingDirectory=${ZAMMAD_WORKING_DIRECTORY:-/opt/zammad} -Environment=RAILS_ENV=production -Environment=BUNDLE_BINARY=bundle -Environment=ZAMMAD_BIND_IP=127.0.0.1 -Environment=ZAMMAD_WEBSOCKET_PORT=6042 - -ExecStart=/bin/bash -l -c "${BUNDLE_BINARY} exec script/websocket-server.rb -b ${ZAMMAD_BIND_IP} -p ${ZAMMAD_WEBSOCKET_PORT} start" +ExecStart=/bin/bash -l -c "${BUNDLE_BINARY:-bundle} exec script/websocket-server.rb -b ${ZAMMAD_BIND_IP:-127.0.0.1} -p ${ZAMMAD_WEBSOCKET_PORT:-6042} start" [Install] WantedBy=zammad.service diff --git a/script/systemd/zammad.env b/script/systemd/zammad.env new file mode 100644 index 000000000..3b1f84599 --- /dev/null +++ b/script/systemd/zammad.env @@ -0,0 +1,8 @@ +BUNDLE_BINARY=bundle +RAILS_ENV=production +ZAMMAD_BIND_IP=127.0.0.1 +ZAMMAD_GROUP=zammad +ZAMMAD_RAILS_PORT=3000 +ZAMMAD_USER=zammad +ZAMMAD_WEBSOCKET_PORT=6042 +ZAMMAD_WORKING_DIRECTORY=/opt/zammad diff --git a/script/systemd/zammad.service b/script/systemd/zammad.service index 15dfeef4b..46e4a2b8f 100644 --- a/script/systemd/zammad.service +++ b/script/systemd/zammad.service @@ -8,9 +8,9 @@ Wants=zammad-scheduler.service Wants=zammad-websocket.service [Service] -Type=simple -User=zammad -Group=zammad +EnvironmentFile=/etc/zammad/zammad.env +User=${ZAMMAD_USER:-zammad} +Group=${ZAMMAD_GROUP:-zammad} Restart=always ExecStart=/bin/sleep infinity