20after4 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370622 )

Change subject: PHAB: deployment scripts to be called by scap
......................................................................

PHAB: deployment scripts to be called by scap

These hooks will be called at various stages during a scap deployment.

* Promote stops phd and disables puppet
* Finalize applies database migrations, runs puppet and reloads phd + apache
* Rollback runs puppet, restarts apache, restarts  phd

Change-Id: I3ecdcf2a88e499e44d17bc3009ecab845a93c5c3
---
M modules/phabricator/manifests/init.pp
A modules/phabricator/templates/deployment/phab_deploy_finalize.erb
A modules/phabricator/templates/deployment/phab_deploy_promote.erb
A modules/phabricator/templates/deployment/phab_deploy_rollback.erb
4 files changed, 74 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/22/370622/1

diff --git a/modules/phabricator/manifests/init.pp 
b/modules/phabricator/manifests/init.pp
index d4f1e80..f6814f2 100644
--- a/modules/phabricator/manifests/init.pp
+++ b/modules/phabricator/manifests/init.pp
@@ -197,9 +197,11 @@
     scap::target { $deploy_target:
         deploy_user => $deploy_user,
         key_name    => 'phabricator',
+        require     => File['/usr/local/sbin/phab_deploy_finalize'],
         sudo_rules  => [
-            'ALL=(root) NOPASSWD: /usr/sbin/service phd *',
-            'ALL=(root) NOPASSWD: /usr/sbin/service apache2 *',
+            'ALL=(root) NOPASSWD: /usr/local/sbin/phab_deploy_promote',
+            'ALL=(root) NOPASSWD: /usr/local/sbin/phab_deploy_rollback',
+            'ALL=(root) NOPASSWD: /usr/local/sbin/phab_deploy_finalize',
         ],
     }
 
@@ -244,6 +246,28 @@
         mode    => '0644',
     }
 
+    file { '/usr/local/sbin/phab_deploy_promote':
+        content => template('phabricator/deployment/phab_deploy_promote.erb')
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0700',
+    }
+
+    file { '/usr/local/sbin/phab_deploy_finalize':
+        content => template('phabricator/deployment/phab_deploy_finalize.erb')
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0700',
+    }
+
+    file { '/usr/local/sbin/phab_deploy_rollback':
+        content => template('phabricator/deployment/phab_deploy_rollback.erb')
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0700',
+    }
+
+
     if !empty($conf_files) {
         create_resources(phabricator::conf_env, $conf_files)
     }
diff --git a/modules/phabricator/templates/deployment/phab_deploy_finalize.erb 
b/modules/phabricator/templates/deployment/phab_deploy_finalize.erb
new file mode 100644
index 0000000..a0d4291
--- /dev/null
+++ b/modules/phabricator/templates/deployment/phab_deploy_finalize.erb
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+git=$(which git)
+logger=$(which logger)
+puppet=$(which puppet)
+service=$(which service)
+
+function log() {
+  echo -e "\n${green}   ->${1}${CLEAR}"
+  $logger "${1}"
+}
+
+function error() {
+  echo ""
+  $logger --stderr "${1}"
+}
+
+log "Running puppet..."
+$puppet agent --test
+
+log "Applying storage migrations"
+<%= @phabdir %>/phabricator/bin/storage upgrade --force -u <%= @storage_user 
%> -p <%= @storage_pass %>
+
+log "Restarting PHD"
+$service phd start
+
+log "Reloading apache"
+$service apache2 reload
+
+log "Enabling puppet agent"
+$puppet agent --enable
+
+log "Verifying database status"
+<%= @phabdir %>/phabricator/bin/storage status &>/dev/null
+retcode=$?
+if [ "$retcode" != "0" ]; then
+    error ">>>ERROR: Phabricator storage is in a bad state."
+    exit 1
+fi
\ No newline at end of file
diff --git a/modules/phabricator/templates/deployment/phab_deploy_promote.erb 
b/modules/phabricator/templates/deployment/phab_deploy_promote.erb
new file mode 100644
index 0000000..0967b5b
--- /dev/null
+++ b/modules/phabricator/templates/deployment/phab_deploy_promote.erb
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+service phd stop
+puppet agent --disable
diff --git a/modules/phabricator/templates/deployment/phab_deploy_rollback.erb 
b/modules/phabricator/templates/deployment/phab_deploy_rollback.erb
new file mode 100644
index 0000000..162208a
--- /dev/null
+++ b/modules/phabricator/templates/deployment/phab_deploy_rollback.erb
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+puppet agent --enable
+service apache2 reload
+service phd start
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/370622
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ecdcf2a88e499e44d17bc3009ecab845a93c5c3
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: 20after4 <mmod...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to