-
Notifications
You must be signed in to change notification settings - Fork 3
/
meteor-unbundle-and-deploy.sh
executable file
·131 lines (118 loc) · 3.37 KB
/
meteor-unbundle-and-deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash -
#===============================================================================
#
# FILE: meteor-unbundle-and-deploy.sh
#
# USAGE: meteor-unbundle-and-deploy.sh -b bundle-name [-v]
# meteor-unbundle-and-deploy.sh --bundle bundle-name [--verbose]
#
# DESCRIPTION: This script untars a tarball bundled by Meteor to a temporary
# location, runs node install & prune, and then replaces an
# existing bundle with the new one.
# Once this is complete, the script will restart the app's
# Passenger process and remove's the temporary directory.
# It is left to the user to remove the replaced bundle, which
# will be renamed bundle.old.
# This script will generally be run automatically by the remote
# developer's meteor-bundle-and-send script.
# OPTIONS:
# -b | --bundle
# The name of your bundle, <bundle-name>.tar.gz.
# I recommend making them descriptive and versioned, so
# that you can easily switch versions in emergencies.
# -v | --verbose
# If passed, will show all commands executed.
# REQUIREMENTS: Node 0.10.43, Passenger
# BUGS: ---
# NOTES: ---
# AUTHOR: Jason White ([email protected]),
# ORGANIZATION: @iDoAWS
# CREATED: 04/12/2016 12:08
# REVISION: 001
#===============================================================================
# Strict mode
set -euo pipefail
IFS=$'\n\t'
# Check for arguments or provide help
if [ $# -eq 0 ] ; then
echo "Usage:"
echo " `basename $0` -b bundle-name [-v]"
echo " `basename $0` --bundle bundle-name [--verbose]"
echo "This should be run on your staging or production server."
exit 0
fi
cd ~/www
APP_DIR=`pwd`
ME=`whoami`
# Parse command line arguments into variables
while :
do
case ${1:-} in
-b | --bundle)
BUNDLE="$2"
shift 2
;;
-v | --verbose)
VERBOSE=true
shift 1
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
# Validate required arguments
if [ ! -v BUNDLE ] ; then
echo 'Bundle name is required.'
exit 1
fi
# Check for verbosity
if [ -v VERBOSE ] ; then
set -v
fi
# Extract newly uploaded package
if [ -d ./tmp ] ; then
rm -rf ./tmp
fi
mkdir tmp
cd tmp
tar xzf ~/$BUNDLE.tar.gz
rm ~/$BUNDLE.tar.gz
# Install dependencies
cd bundle/programs/server
meteor npm install --production
meteor npm prune --production
# Copy over persistent files for standalone mode, jic
if [ -f $APP_DIR/bundle/Passengerfile.json ]; then
cp $APP_DIR/bundle/Passengerfile.json $APP_DIR/tmp/bundle/
fi
# Switch directories, restart app
cd $APP_DIR
if [[ -d tmp && -d bundle ]] ; then
if [ -d bundle.old ] ; then
rm -rf bundle.old
fi
mv bundle bundle.old
PRE_EXIST=true
fi
mv tmp/bundle bundle
rm -rf tmp
cd
# End
if [ -v PRE_EXIST ] ; then
echo ""
echo ""
echo "This appears to be an upgrade, run 'sudo passenger-config restart-app /var/www/$ME'."
echo "After manually confirming the app is running, then remove ~/www/bundle.old."
else
echo ""
echo ""
echo "This appears to be the first app deployment, restart Nginx for changes to take affect."
fi
echo "Remote tasks complete. App has been deployed."
echo ""
exit 0