-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmeteor-bundle-and-send.sh
More file actions
executable file
·187 lines (176 loc) · 5.4 KB
/
meteor-bundle-and-send.sh
File metadata and controls
executable file
·187 lines (176 loc) · 5.4 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash -
#===============================================================================
#
# FILE: meteor-bundle-and-send.sh
#
# USAGE: meteor-bundle-and-send.sh -u user -s server [-i keyfile.pem] [-b bundle-name] [-d source-dir] [-f] [-v]
# meteor-bundle-and-send.sh --user user --server server [--key keyfile.pem] [--bundle bundle-name] [--dir source-dir] [--force] [--verbose]
#
# DESCRIPTION: This script should generally be run on your development
# machine from your application's root source directory. It
# will bundle your application into <bundle-name>.tar.gz and
# copy that file to the server along with the script to
# unbundle and deploy the app.
# The file and script will be copied to the supplied user's
# home directory and then run the script using the supplied
# bundle name as its sole parameter.
# The meteor-unbundle-and-deploy.sh script is expected to be
# in your app's /private/ directory (where this one probably
# is).
# OPTIONS:
# -b | --bundle
# Default: '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.
# -d | --dir
# Default: ./
# Location of your app's source root (ie; contains .meteor)
# If omitted, assumes that your PWD is that directory
# -i | --key
# The SSH public key file for the given user and server.
# -s | --server
# The fully qualified domain name of the remote server.
# -u | --user
# The name of the system account the host will be attributed to.
# -v | --verbose
# If passed, will show all commands executed.
# REQUIREMENTS: Node, Meteor, SSH/SCP, remote shell access
# BUGS: Keyfile issues
# NOTES: ---
# AUTHOR: Jason White (Jason@iDoAWS.com),
# ORGANIZATION: @iDoAWS
# CREATED: 04/12/2016 12:09
# 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` -u user -s server [-i keyfile.pem] [-b bundle-name] [-f] [-v]"
echo " `basename $0` --user user --server server [--key keyfile.pem] [--bundle bundle-name] [--force] [--verbose]"
echo "This should be run from your development environment."
echo "Also, meteor-unbundle-and-deploy.sh should be in the remote user's path."
exit 0
fi
# Check Node version
#NODE_VERSION=`node --version`
#if [[ ! $NODE_VERSION =~ ^v0\.10\.4 ]] ; then
# echo "You should bundle Meteor apps with Node v0.10.4x."
# echo "You are using Node $NODE_VERSION, please correct this and try again."
# echo "You may switch to the tested & installed Meteor-friendly version with 'sudo n 0.10.43' using the ec2-user account."
# read -p "Would you still like to try anyway? [y/N]" -n 1 -r REPLY
# echo ""
# if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
# echo "Exiting without action."
# exit 1
# fi
#fi
# Save PWD
ORIGIN=`pwd`
# Parse command line arguments into variables
while :
do
case ${1:-} in
-b | --bundle)
BUNDLE="$2"
shift 2
;;
-d | --dir)
SRC_DIR=$2
shift 2
;;
-f | --force)
FORCE=true
shift 1
;;
-i | --key)
KEYFILE=$2
shift 2
;;
-s | --server)
SERVER=$2
shift 2
;;
-u | --user)
REMOTEUSER="$2"
shift 2
;;
-v | --verbose)
VERBOSE=true
shift 1
;;
-*)
echo "Error: Unknown option: $1" >&2
cd $ORIGIN
exit 1
;;
*) # No more options
break
;;
esac
done
# Validate required arguments
if [ ! -v REMOTEUSER ] ; then
echo "User is required."
cd $ORIGIN
exit 1
fi
if [ ! -v SERVER ] ; then
echo "Server is required."
cd $ORIGIN
exit 1
fi
# Set defaults if required
if [ ! -v BUNDLE ] ; then
BUNDLE='bundle'
fi
if [ -v SRC_DIR ] ; then
if [ -d $SRC_DIR ] ; then
cd $SRC_DIR
else
echo "Source directory $SRC_DIR is invalid."
cd $ORIGIN
exit 1
fi
fi
if [ ! -d .meteor ] ; then
echo "You must be in, or supply, a valid Meteor app directory."
cd $ORIGIN
exit 1
fi
# Check for verbosity
if [ -v VERBOSE ] ; then
set -v
fi
# Check for keyfile
if [[ -v KEYFILE && -f $KEYFILE ]]; then
KEYARG="-i $KEYFILE"
else
KEYARG=
fi
echo "Preparing $BUNDLE.tar.gz"
meteor bundle ../$BUNDLE.tar.gz
scp $KEYARG ../$BUNDLE.tar.gz $REMOTEUSER@$SERVER:
ssh $KEYARG $REMOTEUSER@$SERVER meteor-unbundle-and-deploy.sh -b $BUNDLE
# End
cd $ORIGIN
echo "Local tasks complete."
echo ""
if [ -v FORCE ] ; then
ssh $KEYARG ec2-user@$SERVER sudo service nginx restart
else
read -p "Would you like me to restart the app's Passenger process for you? [y/N] " -n 1 -r REPLY
echo ""
if [[ $REPLY =~ "^[Yy]$" ]] ; then
ssh $KEYARG ec2-user@$SERVER sudo sudo passenger-config restart-app /var/www/$NEWUSER/
fi
read -p "Would you like me to restart Nginx for you? [y/N] " -n 1 -r REPLY
echo ""
if [[ $REPLY =~ "^[Yy]$" ]] ; then
ssh $KEYARG ec2-user@$SERVER sudo service nginx restart
fi
fi
exit 0