From 24076bd286884db72774fc60d1566e4175602503 Mon Sep 17 00:00:00 2001 From: smarcet Date: Wed, 22 Jan 2020 00:14:34 -0300 Subject: [PATCH] Updated build Updated puppet build to support new migration for user management from IDP side Change-Id: I633add5af8d96223d331a129f39956b1af4f8867 --- files/functions | 57 +++++++++++++++++++++++++++- manifests/init.pp | 38 +++++++++++++++++++ templates/openstackid.conf.erb | 4 +- templates/supervisor.conf.erb | 15 ++++++++ templates/supervisor_watchdog.sh.erb | 12 ++++++ 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 templates/supervisor.conf.erb create mode 100644 templates/supervisor_watchdog.sh.erb diff --git a/files/functions b/files/functions index 0516370..b5b6f57 100644 --- a/files/functions +++ b/files/functions @@ -80,16 +80,43 @@ function site_init { # populate application database cd $target_dir - php artisan migrate --env=$LARAVEL_ENV + + echo "running redis FLUSHDB ..."; + echo "FLUSHDB" | redis-cli -h 127.0.0.1 -p $REDIS_PORT -a "$REDIS_PASSWORD"; + echo "running redis FLUSHALL ..."; + echo "FLUSHALL" | redis-cli -h 127.0.0.1 -p $REDIS_PORT -a "$REDIS_PASSWORD"; + + echo "generating doctrine proxies"; + php artisan doctrine:generate:proxies; + echo "clearing doctrine metadata"; + php artisan doctrine:clear:metadata:cache; + echo "clearing doctrine query cache"; + php artisan doctrine:clear:query:cache; + echo "clearing doctrine result cache"; + php artisan doctrine:clear:result:cache; + echo "running db migrations"; + php artisan doctrine:migrations:migrate --connection=model --force --env=$LARAVEL_ENV; + if [[ $USE_DB_SEEDING -eq 1 ]]; then php artisan db:seed --env=$LARAVEL_ENV --force fi + echo "regenerating route cache"; + php artisan route:clear; + php artisan route:cache; + sudo npm install sudo npm run build # activate site rm -rf $SITE_ROOT/w ln -s $SITE_ROOT/slot0 $SITE_ROOT/w + + echo "Restarting laravel queue worker ..."; + php artisan queue:restart; + + echo "supervisorctl reload"; + supervisorctl reload; + } function site_status { @@ -208,12 +235,38 @@ function site_update { # populate application database cd $target_dir - php artisan migrate --env=$LARAVEL_ENV --force + echo "running redis FLUSHDB ..."; + echo "FLUSHDB" | redis-cli -h 127.0.0.1 -p $REDIS_PORT -a "$REDIS_PASSWORD"; + echo "running redis FLUSHALL ..."; + echo "FLUSHALL" | redis-cli -h 127.0.0.1 -p $REDIS_PORT -a "$REDIS_PASSWORD"; + + echo "generating doctrine proxies"; + php artisan doctrine:generate:proxies; + echo "clearing doctrine metadata"; + php artisan doctrine:clear:metadata:cache; + echo "clearing doctrine query cache"; + php artisan doctrine:clear:query:cache; + echo "clearing doctrine result cache"; + php artisan doctrine:clear:result:cache; + echo "running db migrations"; + php artisan doctrine:migrations:migrate --connection=model --force --env=$LARAVEL_ENV; + + echo "regenerating route cache"; + php artisan route:clear; + php artisan route:cache; + sudo npm install sudo npm run build + # activate site rm -rf $SITE_ROOT/w ln -s $target_dir $SITE_ROOT/w # to reset op cache /usr/sbin/service $PHP_SERVICE_NAME restart + + echo "Restarting laravel queue worker ..."; + php artisan queue:restart; + + echo "supervisorctl reload"; + supervisorctl reload; } diff --git a/manifests/init.pp b/manifests/init.pp index 981d477..aa01a36 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -142,6 +142,7 @@ class openstackid ( 'build-essential', 'software-properties-common', 'python-software-properties', + 'supervisor', ] package { $main_packages: @@ -328,6 +329,36 @@ class openstackid ( mode => '0755', } + file { '/etc/scripts': + ensure => directory, + owner => 'root', + group => 'root', + mode => '0755', + } + + file { '/etc/scripts/supervisor_watchdog.sh': + ensure => present, + content => template('openstackid/supervisor_watchdog.sh.erb'), + owner => 'root', + group => 'www-data', + mode => '0770', + require => [ + Package['supervisor'], + File['/etc/scripts'], + ] + } + + file { '/etc/supervisor/conf.d/supervisor.conf': + ensure => present, + content => template('openstackid/supervisor.conf.erb'), + owner => 'root', + group => 'www-data', + mode => '0640', + require => [ + Package['supervisor'], + ] + } + file { '/etc/openstackid/.env': ensure => present, content => template('openstackid/.env.erb'), @@ -553,4 +584,11 @@ class openstackid ( minute => '*', } + cron { 'InstallSupervisorWatchdog': + ensure => 'present', + command => '/etc/scripts/supervisor_watchdog.sh >> /var/log/supervisor_watchdog.log 2>&1', + user => 'root', + minute => '*/5', + } + } diff --git a/templates/openstackid.conf.erb b/templates/openstackid.conf.erb index 7dfbe8c..3a2b106 100644 --- a/templates/openstackid.conf.erb +++ b/templates/openstackid.conf.erb @@ -5,4 +5,6 @@ RELEASE_NAME=openstackid-<%= @openstackid_release %>.tar.gz SOURCE_ROOT=http://tarballs.openstack.org/openstackid/ USE_DB_SEEDING=<%= @use_db_seeding?1:0 %> LARAVEL_VERSION=<%= @laravel_version %> -PHP_SERVICE_NAME=<%= @php_service_name %> \ No newline at end of file +PHP_SERVICE_NAME=<%= @php_service_name %> +REDIS_PORT=<%= @redis_port %> +REDIS_PASSWORD=<%= @redis_password %> \ No newline at end of file diff --git a/templates/supervisor.conf.erb b/templates/supervisor.conf.erb new file mode 100644 index 0000000..03f5b9e --- /dev/null +++ b/templates/supervisor.conf.erb @@ -0,0 +1,15 @@ +[supervisord] +nodaemon=true +pidfile=/run/supervisord.pid +user=root + +[program:laravel-worker] +process_name=%(program_name)s_%(process_num)02d +command=php <%= @docroot %>/artisan queue:work +autostart=true +autorestart=true +numprocs=8 +user=www-data +stderr_logfile=/var/log/supervisor_laravel_worker.err.log +stdout_logfile=/var/log/supervisor_laravel_worker.out.log +logfile_maxbytes=10MB diff --git a/templates/supervisor_watchdog.sh.erb b/templates/supervisor_watchdog.sh.erb new file mode 100644 index 0000000..11ae94f --- /dev/null +++ b/templates/supervisor_watchdog.sh.erb @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +dt=`date '+%d/%m/%Y %H:%M:%S'` +output=$(supervisorctl status | grep -i ^RUNNING); + +if test -z "$output" +then + echo "[$dt] - everything running just fine"; +else + echo "[$dt] - some process has stopped, reloading supervisor"; + echo "$output" + supervisorctl reload; +fi