Created
July 18, 2015 12:04
-
-
Save wastemobile/c862b4b23731f79bba4e to your computer and use it in GitHub Desktop.
Meteor Up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
# IP or URL of the server you want to deploy to | |
APP_HOST=example.com | |
# Uncomment this if your host is an EC2 instance | |
# EC2_PEM_FILE=path/to/your/file.pem | |
# You usually don't need to change anything below this line | |
APP_NAME=meteorapp | |
ROOT_URL=http://$APP_HOST | |
PORT=80 | |
APP_DIR=/var/www/$APP_NAME | |
MONGO_URL=mongodb://localhost:27017/$APP_NAME | |
if [ -z "$EC2_PEM_FILE" ]; then | |
SSH_HOST="root@$APP_HOST" SSH_OPT="" | |
else | |
SSH_HOST="ubuntu@$APP_HOST" SSH_OPT="-i $EC2_PEM_FILE" | |
fi | |
if [ -d ".meteor/meteorite" ]; then | |
METEOR_CMD=mrt | |
else | |
METEOR_CMD=meteor | |
fi | |
case "$1" in | |
setup ) | |
echo Preparing the server... | |
echo Get some coffee, this will take a while. | |
ssh $SSH_OPT $SSH_HOST DEBIAN_FRONTEND=noninteractive 'sudo -E bash -s' > /dev/null 2>&1 <<'ENDSSH' | |
apt-get update | |
apt-get install -y python-software-properties | |
add-apt-repository ppa:chris-lea/node.js | |
apt-get update | |
apt-get install -y build-essential nodejs mongodb | |
npm install -g forever | |
ENDSSH | |
echo Done. You can now deploy your app. | |
;; | |
deploy ) | |
echo Deploying... | |
$METEOR_CMD bundle bundle.tgz > /dev/null 2>&1 && | |
scp $SSH_OPT bundle.tgz $SSH_HOST:/tmp/ > /dev/null 2>&1 && | |
rm bundle.tgz > /dev/null 2>&1 && | |
ssh $SSH_OPT $SSH_HOST PORT=$PORT MONGO_URL=$MONGO_URL ROOT_URL=$ROOT_URL APP_DIR=$APP_DIR 'sudo -E bash -s' > /dev/null 2>&1 <<'ENDSSH' | |
if [ ! -d "$APP_DIR" ]; then | |
mkdir -p $APP_DIR | |
chown -R www-data:www-data $APP_DIR | |
fi | |
pushd $APP_DIR | |
forever stop bundle/main.js | |
rm -rf bundle | |
tar xfz /tmp/bundle.tgz -C $APP_DIR | |
rm /tmp/bundle.tgz | |
pushd bundle/programs/server/node_modules | |
rm -rf fibers | |
npm install [email protected] | |
popd | |
chown -R www-data:www-data bundle | |
patch -u bundle/programs/server/packages/webapp.js <<'ENDPATCH' | |
@@ -447,6 +447,8 @@ var runWebAppServer = function () { | |
httpServer.listen(localPort, localIp, Meteor.bindEnvironment(function() { // 428 | |
if (argv.keepalive || true) // 429 | |
console.log("LISTENING"); // must match run.js // 430 | |
+ process.setgid('www-data'); | |
+ process.setuid('www-data'); | |
var port = httpServer.address().port; // 431 | |
var proxyBinding; // 432 | |
// 433 | |
ENDPATCH | |
forever start bundle/main.js | |
popd | |
ENDSSH | |
echo Your app is deployed and serving on: $ROOT_URL | |
;; | |
* ) | |
cat <<'ENDCAT' | |
./meteor.sh [action] | |
Available actions: | |
setup - Install a meteor environment on a fresh Ubuntu server | |
deploy - Deploy the app to the server | |
ENDCAT | |
;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Server authentication info | |
"servers": [ | |
{ | |
"host": "hostname", | |
"username": "user", | |
"password": "password" | |
// or pem file (ssh based authentication) | |
//"pem": "~/.ssh/id_rsa" | |
} | |
], | |
// Install MongoDB in the server, does not destroy local MongoDB on future setup | |
"setupMongo": false, | |
// WARNING: Node.js is required! Only skip if you already have Node.js installed on server. | |
"setupNode": false, | |
// WARNING: If nodeVersion omitted will setup 0.10.36 by default. Do not use v, only version number. | |
"nodeVersion": "0.10.40", | |
// Install PhantomJS in the server | |
"setupPhantom": false, | |
// Show a progress bar during the upload of the bundle to the server. | |
// Might cause an error in some rare cases if set to true, for instance in Shippable CI | |
"enableUploadProgressBar": true, | |
// Application name (No spaces) | |
"appName": "todos", | |
// Location of app (local directory) | |
"app": ".", | |
// Configure environment | |
"env": { | |
"ROOT_URL": "http://hostname", | |
"MONGO_URL": "mongodb://dbuser:dbpassword@mongolocation:port/todos" | |
}, | |
// Meteor Up checks if the app comes online just after the deployment | |
// before mup checks that, it will wait for no. of seconds configured below | |
"deployCheckWaitTime": 30 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment