Created
May 23, 2013 16:52
-
-
Save Pent/5637550 to your computer and use it in GitHub Desktop.
modified deploy script
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 | |
| # IP or URL of the server you want to deploy to | |
| export APP_HOST=IP_ADDRESS_HERE | |
| export APP_ROOT=root | |
| export APP_NAME=YOUR_APP_NAME | |
| export APP_PORT=3000 | |
| export ROOT_URL=http://$APP_HOST:$APP_PORT | |
| export APP_DIR=/srv/www/$APP_HOST/$APP_NAME | |
| export MONGO_URL=mongodb://localhost:27017/$APP_NAME | |
| export SSH_HOST="$APP_ROOT@$APP_HOST" | |
| if [ -d ".meteor/meteorite" ]; then | |
| export METEOR_CMD=mrt | |
| else | |
| export METEOR_CMD=meteor | |
| fi | |
| case "$1" in | |
| setup ) | |
| echo Preparing the server... | |
| echo Get some coffee, this will take a while. | |
| ssh $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-legacy | |
| apt-get update | |
| apt-get install -y build-essential nodejs npm 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 bundle.tgz $SSH_HOST:/tmp/ > /dev/null 2>&1 && | |
| rm bundle.tgz > /dev/null 2>&1 && | |
| ssh $SSH_HOST 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 $APP_ROOT:$APP_ROOT $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/server/node_modules | |
| rm -rf fibers | |
| npm install [email protected] | |
| popd | |
| chown -R $APP_ROOT:$APP_ROOT bundle | |
| patch -u bundle/server/server.js <<'ENDPATCH' | |
| @@ -323,6 +323,8 @@ | |
| app.listen(port, function() { | |
| if (argv.keepalive) | |
| console.log("LISTENING"); // must match run.js | |
| + process.setgid('$APP_ROOT'); | |
| + process.setuid('$APP_ROOT'); | |
| }); | |
| }).run(); | |
| ENDPATCH | |
| export MONGO_URL=$MONGO_URL | |
| export ROOT_URL=$ROOT_URL | |
| export APP_DIR=$APP_DIR | |
| export PORT=$APP_PORT | |
| forever start bundle/main.js | |
| popd | |
| ENDSSH | |
| echo Your app is deployed and serving on: $ROOT_URL | |
| ;; | |
| * ) | |
| cat <<'ENDCAT' | |
| ./deploy.sh [action] | |
| Available actions: | |
| setup - Install a meteor environment on a fresh Ubuntu server | |
| deploy - Deploy the app to the server | |
| ENDCAT | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment