From 2da305fb5f4fff081a8c3fa8a6c9c47fb86d353c Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Wed, 4 Mar 2020 00:49:58 +0100 Subject: [PATCH] Update salt state for gvaweb This commit improves the gvaweb celery worker setup based on the work that has been done for gvaldap before. Old files have been removed and the setup uses the macros from gnuviechadmin/gvaapp_macros.sls. --- pillar/gnuviechadmin/gvaweb.sls | 4 ++++ states/gnuviechadmin/gvaapp_macros.sls | 4 ---- states/gnuviechadmin/gvaldap.sls | 4 ++++ states/gnuviechadmin/gvaweb.sls | 15 +++++++++------ states/gnuviechadmin/gvaweb/celery-worker.env | 6 ++++++ states/gnuviechadmin/gvaweb/run_celery.sh | 12 ------------ states/gnuviechadmin/gvaweb/settings.sh | 8 -------- states/gnuviechadmin/gvaweb/sudoers | 2 +- 8 files changed, 24 insertions(+), 31 deletions(-) create mode 100644 states/gnuviechadmin/gvaweb/celery-worker.env delete mode 100644 states/gnuviechadmin/gvaweb/run_celery.sh delete mode 100644 states/gnuviechadmin/gvaweb/settings.sh diff --git a/pillar/gnuviechadmin/gvaweb.sls b/pillar/gnuviechadmin/gvaweb.sls index cb7f085..0174010 100644 --- a/pillar/gnuviechadmin/gvaweb.sls +++ b/pillar/gnuviechadmin/gvaweb.sls @@ -7,3 +7,7 @@ gnuviechadmin: component: name: gvaweb amqp_user: web + gvaweb: + git_url: https://git.dittberner.info/gnuviech/gvaweb.git + git_branch: master + celery_module: webtasks diff --git a/states/gnuviechadmin/gvaapp_macros.sls b/states/gnuviechadmin/gvaapp_macros.sls index 69d8a71..a4a15e4 100644 --- a/states/gnuviechadmin/gvaapp_macros.sls +++ b/states/gnuviechadmin/gvaapp_macros.sls @@ -1,8 +1,4 @@ {% macro gvaapp_base(gvaappname, servicename) -%} -include: -- python.pipenv -- python.virtualenv - {% set app_home = salt['grains.get']('gnuviechadmin:home', '/home/{}'.format(gvaappname)) %} {% set app_user = salt['grains.get']('gnuviechadmin:user', gvaappname) %} {% set app_group = salt['grains.get']('gnuviechadmin:group', gvaappname) %} diff --git a/states/gnuviechadmin/gvaldap.sls b/states/gnuviechadmin/gvaldap.sls index 7b27170..563a32b 100644 --- a/states/gnuviechadmin/gvaldap.sls +++ b/states/gnuviechadmin/gvaldap.sls @@ -1,6 +1,10 @@ {% set gvaappname = salt['grains.get']('gnuviechadmin:appname') %} {% set purpose = "for LDAP data management" %} {% from 'gnuviechadmin/gvaapp_macros.sls' import create_celery_worker with context %} +include: +- python.pipenv +- python.virtualenv + {{ create_celery_worker(gvaappname, purpose) }} {{ gvaappname }}-dependencies: diff --git a/states/gnuviechadmin/gvaweb.sls b/states/gnuviechadmin/gvaweb.sls index 4910ce0..cbcf1fd 100644 --- a/states/gnuviechadmin/gvaweb.sls +++ b/states/gnuviechadmin/gvaweb.sls @@ -1,14 +1,17 @@ +{% set gvaappname = salt['grains.get']('gnuviechadmin:appname') %} +{% set purpose = "for website configuration management" %} +{% from 'gnuviechadmin/gvaapp_macros.sls' import create_celery_worker with context %} include: - - gnuviechadmin.base - - gnuviechadmin.celery +- base +- python.pipenv +- python.virtualenv -sudo: - pkg.installed +{{ create_celery_worker(gvaappname, purpose) }} -/etc/sudoers.d/gvaweb: +/etc/sudoers.d/{{ gvaappname }}: file.managed: - user: root - group: root - - source: salt://gnuviechadmin/gvaweb/sudoers + - source: salt://gnuviechadmin/{{ gvaappname }}/sudoers - require: - pkg: sudo diff --git a/states/gnuviechadmin/gvaweb/celery-worker.env b/states/gnuviechadmin/gvaweb/celery-worker.env new file mode 100644 index 0000000..a7ab606 --- /dev/null +++ b/states/gnuviechadmin/gvaweb/celery-worker.env @@ -0,0 +1,6 @@ +GVAWEB_BROKER_URL="{{ broker_url }}" +GVAWEB_RESULTS_REDIS_URL="{{ 'redis://:{}@{}/0'.format(salt['pillar.get']('gnviechadmin:redis_password'), salt['pillar.get']('gnuviechadmin:redis_host')) }}" +GVAWEB_NGINX_SITES_AVAILABLE="{{ salt['pillar.get']('gnuviechadmin-gvaweb:nginx_sites_available', '/etc/nginx/sites-available') }}" +GVAWEB_NGINX_SITES_ENABLED="{{ salt['pillar.get']('gnuviechadmin-gvaweb:nginx_sites_enabled', '/etc/nginx/sites-enabled') }}" +GVAWEB_PHPFPM_POOL="{{ salt['pillar.get']('gnuviechadmin-gvaweb:phpfpm_pool', '/etc/php5/fpm/pool.d') }}" +GVAWEB_WWWUSER_MOUNT="{{ salt['pillar.get']('gnuviechadmin-gvaweb:wwwuser_mount', '/srv/wwwfiles') }}" diff --git a/states/gnuviechadmin/gvaweb/run_celery.sh b/states/gnuviechadmin/gvaweb/run_celery.sh deleted file mode 100644 index 085dd5c..0000000 --- a/states/gnuviechadmin/gvaweb/run_celery.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -ex - -. {{ home }}/gvasettings.sh - -unset LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ - LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT \ - LC_IDENTIFICATION LC_ALL - -cd {{ appdir }} -{{ virtualenv }}/bin/celery worker -A gvaweb -Q web --loglevel=INFO diff --git a/states/gnuviechadmin/gvaweb/settings.sh b/states/gnuviechadmin/gvaweb/settings.sh deleted file mode 100644 index 9b90cc9..0000000 --- a/states/gnuviechadmin/gvaweb/settings.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -export GVAWEB_BROKER_URL='{{ broker_url }}' -export GVAWEB_RESULTS_REDIS_URL="redis://:{{ salt['pillar.get']('gnuviechadmin:redis_password') }}@{{ salt['pillar.get']('gnuviechadmin:redis_host') }}/0" -export GVAWEB_NGINX_SITES_AVAILABLE="{{ salt['pillar.get']('gnuviechadmin:nginx_sites_available', '/etc/nginx/sites-available') }}" -export GVAWEB_NGINX_SITES_ENABLED="{{ salt['pillar.get']('gnuviechadmin:nginx_sites_enabled', '/etc/nginx/sites-enabled') }}" -export GVAWEB_PHPFPM_POOL="{{ salt['pillar.get']('gnuviechadmin:phpfpm_pool', '/etc/php5/fpm/pool.d') }}" -export GVAWEB_WWWUSER_MOUNT="{{ salt['pillar.get']('gnuviechadmin:wwwuser_mount', '/srv/wwwfiles') }}" diff --git a/states/gnuviechadmin/gvaweb/sudoers b/states/gnuviechadmin/gvaweb/sudoers index d0adbb6..8db5048 100644 --- a/states/gnuviechadmin/gvaweb/sudoers +++ b/states/gnuviechadmin/gvaweb/sudoers @@ -1,3 +1,3 @@ -Cmnd_Alias GVAWEB_CMDS = /usr/bin/install, /bin/rm, /bin/ln, /usr/sbin/service +Cmnd_Alias GVAWEB_CMDS = /usr/bin/install, /bin/rm, /bin/ln, /bin/systemctl gvaweb ALL = (root) NOPASSWD: GVAWEB_CMDS