From 76fd3abc7e4ba2f478f7e3d823b3ab8c8946b97c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 23 Apr 2020 01:12:02 +0200 Subject: [PATCH] Fix caldance app deployment --- modules/role/manifests/caldance.pp | 83 ++++++++++++------- modules/role/templates/caldance/app.ini.erb | 3 +- modules/role/templates/caldance/manage.py.erb | 9 ++ 3 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 modules/role/templates/caldance/manage.py.erb diff --git a/modules/role/manifests/caldance.pp b/modules/role/manifests/caldance.pp index df02b07..374b251 100644 --- a/modules/role/manifests/caldance.pp +++ b/modules/role/manifests/caldance.pp @@ -27,10 +27,15 @@ class role::caldance ( ensure_packages(["python-pip", "python-virtualenv", "python-django", "uwsgi-plugin-python"]) $caldance_app = "${home}/app" + $caldance_app_old = "${home}/app_old" + $caldance_app_tmp = "${home}/app_tmp" $pg_password = generate_password(24, $password_seed, "postgres_caldance") $secret_key = generate_password(24, $password_seed, "secret_key_caldance") $socket = "/run/caldance/app.sock" + $uwsgi_path = "${home}/virtualenv/bin/uwsgi" + $python_path = "${home}/virtualenv/bin/python" + $environment = { "DB_NAME" => $pg_db, "DB_USER" => $pg_user, @@ -39,19 +44,21 @@ class role::caldance ( "DB_PORT" => $pg_port, "SECRET_KEY" => $secret_key, "DEBUG" => "False", - "LOG_FILE" => "$home/caldev_django.log", + "LOG_FILE" => "$home/caldance.log", "MEDIA_ROOT" => "$home/media", } file { $home: mode => "0755", } - file { "${home}/caldev_django.log": - mode => "0664", + + file { $caldance_app_tmp: + ensure => "directory", + mode => "0755", owner => $user, - group => "http", + group => $group, + require => User["$user:"], } - file { $caldance_app: ensure => "directory", mode => "0755", @@ -83,41 +90,40 @@ class role::caldance ( user => $user, username => lookup("base_installation::ldap_cn"), password => generate_password(24, $password_seed, "ldap"), - extract_path => $caldance_app, - require => [User["$user:"], File[$caldance_app]], + extract_path => $caldance_app_tmp, + require => [User["$user:"], File[$caldance_app_tmp]], } ~> exec { "py-requirements": - cwd => $caldance_app, + cwd => $caldance_app_tmp, user => $user, environment => ["HOME=${home}"], command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", require => User["$user:"], refreshonly => true, } ~> - exec { "py-migrate": - cwd => $caldance_app, - user => $user, - environment => ["HOME=${home}"], - command => "$caldance_app/manage migrate", - require => [User["$user:"], File["$caldance_app/manage"]], + exec { "stop uwsgi application": + command => "/usr/bin/systemctl stop caldance-app.service || /usr/bin/true", + require => [User["$user:"]], refreshonly => true, } ~> - exec { "py-static": - cwd => $caldance_app, + exec { "mv app_tmp": + cwd => $home, user => $user, environment => ["HOME=${home}"], - command => "$caldance_app/manage collectstatic --no-input", - require => [User["$user:"], File["$caldance_app/manage"]], + command => "/usr/bin/rm -rf $caldance_app_old && /usr/bin/mv $caldance_app $caldance_app_old && /usr/bin/mv $caldance_app_tmp $caldance_app && /usr/bin/mkdir $caldance_app_tmp", + require => [User["$user:"]], refreshonly => true, } ~> - exec { "restart uwsgi application": - command => "/usr/bin/systemctl restart caldance-app.service", - require => [User["$user:"], File["$caldance_app/app.ini"]], - refreshonly => true, - } - - $uwsgi_path = "${home}/virtualenv/bin/uwsgi" - $python_path = "${home}/virtualenv/bin/python" + file { "$caldance_app/manage.py": + owner => $user, + group => $group, + mode => "0755", + content => template("role/caldance/manage.py.erb"), + require => [ + User["$user:"], + Archive[ "${home}/caldance_${caldance_version}.tar.gz"], + ], + } ~> file { "$caldance_app/manage": owner => $user, group => $group, @@ -125,10 +131,10 @@ class role::caldance ( content => template("role/caldance/manage.sh.erb"), require => [ User["$user:"], + File["$caldance_app/manage.py"], Archive[ "${home}/caldance_${caldance_version}.tar.gz"], ], - } - + } ~> file { "$caldance_app/app.ini": owner => $user, group => $group, @@ -138,6 +144,27 @@ class role::caldance ( User["$user:"], Archive[ "${home}/caldance_${caldance_version}.tar.gz"], ], + } ~> + exec { "py-migrate": + cwd => $caldance_app, + user => $user, + environment => ["HOME=${home}"], + command => "$caldance_app/manage migrate", + require => [User["$user:"], File["$caldance_app/manage"]], + refreshonly => true, + } ~> + exec { "py-static": + cwd => $caldance_app, + user => $user, + environment => ["HOME=${home}"], + command => "$caldance_app/manage collectstatic --no-input", + require => [User["$user:"], File["$caldance_app/manage"]], + refreshonly => true, + } ~> + exec { "restart uwsgi application": + command => "/usr/bin/systemctl restart caldance-app.service", + require => [User["$user:"], File["$caldance_app/app.ini"]], + refreshonly => true, } profile::postgresql::master { "postgresql master for caldance": diff --git a/modules/role/templates/caldance/app.ini.erb b/modules/role/templates/caldance/app.ini.erb index df6fcb9..f7d70ed 100644 --- a/modules/role/templates/caldance/app.ini.erb +++ b/modules/role/templates/caldance/app.ini.erb @@ -4,7 +4,8 @@ wsgi-file = main_app/wsgi.py master = true processes = 10 -gevent = 1000 +#This produces failure loops +#gevent = 1000 http-websockets = true socket = <%= @socket %> diff --git a/modules/role/templates/caldance/manage.py.erb b/modules/role/templates/caldance/manage.py.erb new file mode 100644 index 0000000..03cc97a --- /dev/null +++ b/modules/role/templates/caldance/manage.py.erb @@ -0,0 +1,9 @@ +#!<%= @home %>/virtualenv/bin/python -O +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main_app.settings") + + from django.core.management import execute_from_command_line + execute_from_command_line(sys.argv) -- 2.41.0