From f7e83dfa6bc91d382ce65ae7f6d99a01dc1bcf0a Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Wed, 26 Apr 2017 21:07:36 +0100 Subject: [PATCH] add a quick script to handle auto upgrading --- bin/postal | 4 ++++ script/auto_upgrade.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 script/auto_upgrade.rb diff --git a/bin/postal b/bin/postal index 8560bf7..8802e33 100755 --- a/bin/postal +++ b/bin/postal @@ -76,6 +76,10 @@ case "$1" in run "bundle exec ruby script/register_lets_encrypt.rb $2" ;; + auto-upgrade) + run "ruby script/auto_upgrade.rb" + ;; + bundle) if [ -n "$2" ]; then run "bundle install --path=$2 --without=development --jobs=4 --clean" diff --git a/script/auto_upgrade.rb b/script/auto_upgrade.rb new file mode 100644 index 0000000..956c1eb --- /dev/null +++ b/script/auto_upgrade.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby + +# This script will attempt to upgrade a Postal installation automatically. +# It is always recommended to upgrade Postal manaually and this script should only +# be used for development or for pro-users. +# +# It can be run as any user that has access to /opt/postal and that can run +# commands as postal. + +def run(command, options = {}) + if system(command) + # Good. + else + puts "Failed to run: #{command}" + exit 128 unless options[:exit_on_failure] == false + end +end + +puts "Stopping current MyOps instance" +run "postal stop", :exit_on_failure => false + +puts "Getting latest version of repository" +run "cd /opt/postal/app && git pull" + +puts "Installing dependencies" +run "postal bundle /opt/postal/app/vendor/bundle" + +puts "Upgrading database & assets" +run "postal upgrade" + +puts "Starting Postal" +run "postal start" + +puts "\e[32mUpgrade complete\e[0m"