├── .gitignore ├── example ├── settings.json └── yamup.json ├── .eslintrc.js ├── templates └── linux │ ├── mongodb.conf │ ├── start.sh │ ├── stud.init.conf │ ├── meteor.systemd.conf │ ├── env.sh │ ├── meteor.upstart.conf │ ├── deploy.sh │ └── stud.conf ├── scripts └── linux │ ├── start.sh │ ├── stop.sh │ ├── upstartORsystemd.sh │ ├── restart.sh │ ├── wrap-up.sh │ ├── setup-env.sh │ ├── install-stud.sh │ ├── install-phantomjs.sh │ ├── install-mongodb.sh │ └── install-node.sh ├── lib ├── taskLists │ ├── index.js │ └── linux.js ├── helpers.js ├── build.js ├── config.js └── actions.js ├── package.json ├── LICENSE ├── bin └── yamup └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /example/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "public": { } 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "extends": "airbnb-base" 3 | }; -------------------------------------------------------------------------------- /templates/linux/mongodb.conf: -------------------------------------------------------------------------------- 1 | bind_ip = 127.0.0.1 2 | dbpath=/var/lib/mongodb/ 3 | logpath=/var/log/mongodb/mongodb.log 4 | logappend=true -------------------------------------------------------------------------------- /scripts/linux/start.sh: -------------------------------------------------------------------------------- 1 | if test -f /etc/os-release; then 2 | sudo service <%= appName %> start 3 | else 4 | sudo start <%= appName %> || : 5 | fi 6 | -------------------------------------------------------------------------------- /scripts/linux/stop.sh: -------------------------------------------------------------------------------- 1 | if test -f /etc/os-release; then 2 | sudo service <%= appName %> stop 3 | else 4 | sudo stop <%= appName %> || : 5 | fi 6 | -------------------------------------------------------------------------------- /scripts/linux/upstartORsystemd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -f /etc/os-release; then 4 | echo 'systemd' 5 | else 6 | echo 'upstart' 7 | fi 8 | -------------------------------------------------------------------------------- /scripts/linux/restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -f /etc/os-release; then 4 | sudo service <%= appName %> restart 5 | else 6 | sudo stop <%= appName %> || : 7 | sudo start <%= appName %> || : 8 | fi 9 | -------------------------------------------------------------------------------- /templates/linux/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . /opt/<%= appName %>/config/env.sh 4 | 5 | export NODE_ENV=production 6 | export PWD=/opt/<%= appName %>/app 7 | 8 | cd $PWD 9 | /usr/bin/node main.js 10 | -------------------------------------------------------------------------------- /lib/taskLists/index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | /* eslint-disable global-require */ 3 | /* eslint-disable import/no-dynamic-require */ 4 | module.exports = function (os) { 5 | return require(`./${os}`); 6 | }; 7 | -------------------------------------------------------------------------------- /templates/linux/stud.init.conf: -------------------------------------------------------------------------------- 1 | #!upstart 2 | description "starting stud" 3 | author "comet" 4 | 5 | start on runlevel [2345] 6 | stop on runlevel [06] 7 | 8 | respawn 9 | limit nofile 65536 65536 10 | 11 | script 12 | stud --config=/opt/stud/stud.conf 13 | end script -------------------------------------------------------------------------------- /templates/linux/meteor.systemd.conf: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=<%= appName %> 3 | 4 | [Service] 5 | ExecStart=/opt/<%= appName %>/start.sh 6 | Restart=always 7 | 8 | StandardOutput=syslog 9 | StandardError=syslog 10 | SyslogIdentifier=<%= appName %> 11 | 12 | [Install] 13 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /scripts/linux/wrap-up.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -f /etc/os-release; then 4 | sudo chown root /etc/ 5 | sudo chown root /etc/systemd 6 | sudo chown root /etc/systemd/system 7 | sudo systemctl daemon-reload 8 | sudo systemctl enable <%= appName %> 9 | else 10 | sudo chown root /etc/ 11 | sudo chown root /etc/init 12 | fi 13 | -------------------------------------------------------------------------------- /templates/linux/env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export PORT=80 3 | export MONGO_URL=mongodb://127.0.0.1/<%= appName %> 4 | export ROOT_URL=http://localhost 5 | 6 | #it is possible to override above env-vars from the user-provided values 7 | <% for(var key in env) { %> 8 | export <%- key %>=<%- ("" + env[key]).replace(/./ig, '\\$&') %> 9 | <% } %> 10 | -------------------------------------------------------------------------------- /scripts/linux/setup-env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo mkdir -p /opt/<%= appName %>/ 4 | sudo mkdir -p /opt/<%= appName %>/config 5 | sudo mkdir -p /opt/<%= appName %>/tmp 6 | 7 | sudo chown ${USER} /opt/<%= appName %> -R 8 | 9 | if test -f /etc/os-release; then 10 | sudo chown ${USER} /etc/ 11 | sudo chown ${USER} /etc/systemd 12 | sudo chown ${USER} /etc/systemd/system 13 | sudo npm install -g wait-for-mongodb node-gyp 14 | else 15 | sudo chown ${USER} /etc/ 16 | sudo chown ${USER} /etc/init 17 | sudo npm install -g forever userdown wait-for-mongodb node-gyp 18 | fi 19 | 20 | # Creating a non-privileged user 21 | sudo useradd meteoruser || : 22 | -------------------------------------------------------------------------------- /scripts/linux/install-stud.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #remove the lock 4 | set +e 5 | sudo rm /var/lib/dpkg/lock > /dev/null 6 | sudo rm /var/cache/apt/archives/lock > /dev/null 7 | sudo dpkg --configure -a 8 | set -e 9 | 10 | sudo apt-get update -y 11 | sudo apt-get -y install libev4 libev-dev gcc make libssl-dev git 12 | cd /tmp 13 | sudo rm -rf stud 14 | sudo git clone https://github.com/bumptech/stud.git stud 15 | cd stud 16 | sudo make install 17 | cd .. 18 | sudo rm -rf stud 19 | 20 | #make sure comet folder exists 21 | sudo mkdir -p /opt/stud 22 | 23 | #initial permission 24 | sudo chown -R $USER /etc/init 25 | sudo chown -R $USER /opt/stud 26 | 27 | #create non-privileged user 28 | sudo useradd stud || : -------------------------------------------------------------------------------- /lib/helpers.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | exports.printHelp = function printHelp() { 3 | console.error('\nValid Actions'); 4 | console.error('-------------'); 5 | console.error('init - Initialize a yamup project'); 6 | console.error('setup - Setup the server'); 7 | console.error(''); 8 | console.error('deploy - Deploy app to server'); 9 | console.error('reconfig - Reconfigure the server and restart'); 10 | console.error(''); 11 | console.error('logs [-f -n] - Access logs'); 12 | console.error(''); 13 | console.error('start - Start your app instances'); 14 | console.error('stop - Stop your app instances'); 15 | console.error('restart - Restart your app instances'); 16 | }; 17 | -------------------------------------------------------------------------------- /templates/linux/meteor.upstart.conf: -------------------------------------------------------------------------------- 1 | #!upstart 2 | description "Yet Another Meteor UP - <%= appName %>" 3 | author "João Bordalo, " 4 | 5 | start on runlevel [2345] 6 | stop on runlevel [06] 7 | 8 | respawn 9 | 10 | limit nofile 65536 65536 11 | 12 | script 13 | 14 | cd /opt/<%= appName %> 15 | 16 | ##add userdown config 17 | export USERDOWN_UID=meteoruser USERDOWN_GID=meteoruser 18 | 19 | ##add custom enviromntal variables 20 | if [ -f config/env.sh ]; then 21 | . config/env.sh 22 | fi 23 | 24 | if [ -z $UPSTART_UID ]; then 25 | ##start the app using userdown 26 | forever -c userdown --minUptime 2000 --spinSleepTime 1000 app/main.js 27 | else 28 | ##start the app as UPSTART_UID 29 | exec su -s /bin/sh -c 'exec "$0" "$@"' $UPSTART_UID -- forever --minUptime 2000 --spinSleepTime 1000 app/main.js 30 | fi 31 | 32 | end script 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yamup", 3 | "version": "0.8.4", 4 | "description": "Yet Another Meteor UP", 5 | "bin": { 6 | "yamup": "./bin/yamup" 7 | }, 8 | "dependencies": { 9 | "archiver": "^2.1.1", 10 | "async": "^3.2.2", 11 | "cjson": "0.3.x", 12 | "colors": "0.6.x", 13 | "debug": "^4.1.1", 14 | "nodemiral": "^1.1.1", 15 | "rimraf": "2.x.x", 16 | "underscore": "1.12.1", 17 | "uuid": "1.4.x" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: no test specified\" && exit 1" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/bordalix/yamup.git" 25 | }, 26 | "keywords": [ 27 | "meteor", 28 | "deployment" 29 | ], 30 | "author": "joao.bordalo@gmail.com", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/bordalix/yamup/issues" 34 | }, 35 | "homepage": "https://github.com/bordalix/yamup#readme", 36 | "devDependencies": { 37 | "eslint": "^6.3.0", 38 | "eslint-config-airbnb-base": "^14.0.0", 39 | "eslint-plugin-import": "^2.18.2" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /scripts/linux/install-phantomjs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Remove the lock 4 | set +e 5 | sudo rm /var/lib/dpkg/lock > /dev/null 6 | sudo rm /var/cache/apt/archives/lock > /dev/null 7 | sudo dpkg --configure -a 8 | set -e 9 | 10 | # Install PhantomJS 11 | sudo apt-get -y install libfreetype6 libfreetype6-dev fontconfig > /dev/null 12 | ARCH=`uname -m` 13 | PHANTOMJS_VERSION=2.1.1 14 | 15 | cd /usr/local/share/ 16 | # sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2 > /dev/null 17 | sudo curl -L -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2 > /dev/null 18 | sudo tar xjf phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2 > /dev/null 19 | sudo ln -s -f /usr/local/share/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}/bin/phantomjs /usr/local/share/phantomjs 20 | sudo ln -s -f /usr/local/share/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}/bin/phantomjs /usr/local/bin/phantomjs 21 | sudo ln -s -f /usr/local/share/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}/bin/phantomjs /usr/bin/phantomjs 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /bin/yamup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint-disable no-console */ 3 | 4 | const path = require('path'); 5 | const Config = require('../lib/config'); 6 | const ActionsRegistry = require('../lib/actions'); 7 | const helpers = require('../lib/helpers'); 8 | require('colors'); 9 | 10 | console.log('\nYet Another Meteor UP: Production Quality Meteor Deployments'.bold.blue); 11 | console.log('------------------------------------------------\n'.bold.blue); 12 | 13 | const action = process.argv[2]; 14 | 15 | function runActions(config, cwd) { 16 | const actionsRegistry = new ActionsRegistry(config, cwd); 17 | if (actionsRegistry[action]) { 18 | actionsRegistry[action](); 19 | } else { 20 | if (typeof action !== 'undefined') { 21 | const errorMessage = `No Such Action Exists: ${action}`; 22 | console.error(errorMessage.bold.red); 23 | } 24 | helpers.printHelp(); 25 | } 26 | } 27 | 28 | if (action === 'init') { 29 | // special setup for init 30 | ActionsRegistry.init(); 31 | } else { 32 | const cwd = path.resolve('.'); 33 | // read config and validate it 34 | const config = Config.read(); 35 | runActions(config, cwd); 36 | } 37 | -------------------------------------------------------------------------------- /scripts/linux/install-mongodb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Remove the lock 4 | set +e 5 | sudo rm /var/lib/dpkg/lock > /dev/null 6 | sudo rm /var/cache/apt/archives/lock > /dev/null 7 | sudo dpkg --configure -a 8 | set -e 9 | 10 | #sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 11 | #echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list 12 | sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 13 | if test -f /etc/os-release; then 14 | sudo rm -f /etc/init/mongod.conf 15 | echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list 16 | else 17 | echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list 18 | fi 19 | 20 | sudo apt-get update -y 21 | sudo apt-get install mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-tools -y 22 | 23 | # Restart mongodb 24 | if test -f /etc/os-release; then 25 | sudo service mongod restart 26 | else 27 | if test -f /etc/os-release; then 28 | sudo systemctl stop mongod.service 29 | sudo systemctl start mongod.service 30 | sudo systemctl enable mongod.service 31 | else 32 | sudo stop mongod || : 33 | sudo start mongod 34 | fi 35 | fi 36 | -------------------------------------------------------------------------------- /scripts/linux/install-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Remove the lock 4 | set +e 5 | sudo rm /var/lib/dpkg/lock > /dev/null 6 | sudo rm /var/cache/apt/archives/lock > /dev/null 7 | sudo dpkg --configure -a 8 | set -e 9 | 10 | # Required to update system 11 | sudo apt-get update 12 | 13 | # Install Node.js - either nodeVersion or which works with latest Meteor release 14 | # For Meteor 1.5, node version should be a 4.8.4, and for Meteor 1.6, node version should be 8.9.1 15 | <% if (nodeVersion) { %> 16 | NODE_VERSION=<%= nodeVersion %> 17 | <% } else {%> 18 | NODE_VERSION=8.9.1 19 | <% } %> 20 | 21 | ARCH=$(uname -p) 22 | if [[ ${ARCH} == 'x86_64' ]]; then 23 | NODE_ARCH=x64 24 | else 25 | NODE_ARCH=x86 26 | fi 27 | 28 | sudo apt-get -y install build-essential libssl-dev git curl 29 | 30 | NODE_DIST=node-v${NODE_VERSION}-linux-${NODE_ARCH} 31 | 32 | cd /tmp 33 | wget http://nodejs.org/dist/v${NODE_VERSION}/${NODE_DIST}.tar.gz 34 | tar xvzf ${NODE_DIST}.tar.gz 35 | sudo rm -rf /opt/nodejs 36 | sudo mv ${NODE_DIST} /opt/nodejs 37 | 38 | sudo ln -sf /opt/nodejs/bin/node /usr/bin/node 39 | sudo ln -sf /opt/nodejs/bin/npm /usr/bin/npm 40 | 41 | sudo rm -rf /usr/local/bin/wait-for-mongo 42 | sudo ln -s /opt/nodejs/bin/wait-for-mongo /usr/local/bin/wait-for-mongo 43 | sudo rm -rf /usr/local/bin/forever 44 | sudo ln -s /opt/nodejs/bin/forever /usr/local/bin/forever 45 | sudo rm -rf /usr/local/bin/userdown 46 | sudo ln -s /opt/nodejs/bin/userdown /usr/local/bin/userdown 47 | 48 | # Install node-gyp and remove old files if necessary 49 | sudo npm install -g node-gyp 50 | sudo rm -rf ~/.node-gyp* 51 | -------------------------------------------------------------------------------- /templates/linux/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # utilities 4 | 5 | restart_app (){ 6 | if test -f /etc/os-release; then 7 | chmod +x /opt/<%= appName %>/start.sh 8 | sudo service <%= appName %> restart 9 | else 10 | sudo stop <%= appName %> || : 11 | sudo start <%= appName %> || : 12 | fi 13 | } 14 | 15 | revert_app (){ 16 | if [[ -d old_app ]]; then 17 | sudo rm -rf app 18 | sudo mv old_app app 19 | restart_app 20 | 21 | echo "Latest deployment failed! Reverted back to the previous version." 1>&2 22 | exit 1 23 | else 24 | echo "App did not pick up! Please check app logs." 1>&2 25 | exit 1 26 | fi 27 | } 28 | 29 | 30 | # logic 31 | set -e 32 | 33 | TMP_DIR=/opt/<%= appName %>/tmp 34 | BUNDLE_DIR=${TMP_DIR}/bundle 35 | 36 | cd ${TMP_DIR} 37 | sudo rm -rf bundle 38 | sudo tar xvzf bundle.tar.gz > /dev/null 39 | sudo chmod -R +x * 40 | sudo chown -R ${USER} ${BUNDLE_DIR} 41 | 42 | # rebuilding fibers 43 | cd ${BUNDLE_DIR}/programs/server 44 | 45 | if [ -f package.json ]; then 46 | if [ -f npm-shrinkwrap.json ]; then 47 | chmod 644 npm-shrinkwrap.json 48 | fi 49 | npm install 50 | fi 51 | 52 | cd /opt/<%= appName %>/ 53 | 54 | # remove old app, if it exists 55 | if [ -d old_app ]; then 56 | sudo rm -rf old_app 57 | fi 58 | 59 | ## backup current version 60 | if [[ -d app ]]; then 61 | sudo mv app old_app 62 | fi 63 | 64 | sudo mv tmp/bundle app 65 | 66 | #wait and check 67 | echo "Waiting for MongoDB to initialize. (5 minutes)" 68 | . /opt/<%= appName %>/config/env.sh 69 | wait-for-mongo ${MONGO_URL} 300000 70 | 71 | # restart app 72 | restart_app 73 | 74 | echo "Waiting for <%= deployCheckWaitTime %> seconds while app is booting up" 75 | sleep <%= deployCheckWaitTime %> 76 | 77 | echo "Checking is app booted or not?" 78 | curl localhost:${PORT} || revert_app 79 | 80 | # chown to support dumping heapdump and etc 81 | sudo chown -R meteoruser app 82 | -------------------------------------------------------------------------------- /lib/build.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | const { spawn } = require('child_process'); 3 | const archiver = require('archiver'); 4 | const fs = require('fs'); 5 | const pathResolve = require('path').resolve; 6 | const _ = require('underscore'); 7 | 8 | function buildMeteorApp(appPath, meteorBinary, buildLocaltion, callback) { 9 | let executable = meteorBinary; 10 | let args = [ 11 | 'build', '--directory', buildLocaltion, 12 | '--architecture', 'os.linux.x86_64', 13 | '--server', 'http://localhost:3000', 14 | ]; 15 | const isWin = /^win/.test(process.platform); 16 | if (isWin) { 17 | // Sometimes cmd.exe not available in the path 18 | // See: http://goo.gl/ADmzoD 19 | executable = process.env.comspec || 'cmd.exe'; 20 | args = ['/c', 'meteor'].concat(args); 21 | } 22 | 23 | const options = { cwd: appPath }; 24 | const meteor = spawn(executable, args, options); 25 | 26 | meteor.stdout.pipe(process.stdout, { end: false }); 27 | meteor.stderr.pipe(process.stderr, { end: false }); 28 | 29 | meteor.on('close', callback); 30 | } 31 | 32 | function archiveIt(buildLocaltion, callback) { 33 | const callbck = _.once(callback); 34 | const bundlePath = pathResolve(buildLocaltion, 'bundle.tar.gz'); 35 | const sourceDir = pathResolve(buildLocaltion, 'bundle'); 36 | 37 | const output = fs.createWriteStream(bundlePath); 38 | const archive = archiver('tar', { 39 | gzip: true, 40 | gzipOptions: { level: 6 }, 41 | }); 42 | 43 | archive.pipe(output); 44 | output.once('close', callbck); 45 | 46 | archive.once('error', (err) => { 47 | console.log('=> Archiving failed:', err.message); 48 | callbck(err); 49 | }); 50 | 51 | archive.directory(sourceDir, 'bundle').finalize(); 52 | } 53 | 54 | function buildApp(appPath, meteorBinary, buildLocaltion, callback) { 55 | buildMeteorApp(appPath, meteorBinary, buildLocaltion, (code) => { 56 | if (code === 0) { 57 | archiveIt(buildLocaltion, callback); 58 | } else { 59 | console.log('\n=> Build Error. Check the logs printed above.'); 60 | callback(new Error('build-error')); 61 | } 62 | }); 63 | } 64 | 65 | module.exports = buildApp; 66 | -------------------------------------------------------------------------------- /example/yamup.json: -------------------------------------------------------------------------------- 1 | { 2 | // Server authentication info 3 | "servers": [ 4 | { 5 | "host": "hostname", 6 | "username": "root", 7 | //"password": "password", 8 | // or pem file (ssh based authentication) 9 | "pem": "~/.ssh/id_rsa" 10 | // Also, for non-standard ssh port use this 11 | //"sshOptions": { "port" : 49154 }, 12 | // server specific environment variables 13 | //"env": {} 14 | } 15 | ], 16 | 17 | // Install MongoDB on the server. Does not destroy the local MongoDB on future setups 18 | "setupMongo": true, 19 | 20 | // WARNING: Node.js is required! Only skip if you already have Node.js installed on server. 21 | "setupNode": true, 22 | 23 | // WARNING: nodeVersion defaults to 8.9.1 if omitted. Do not use v, just the version number. 24 | // For Meteor 1.5.*, use 4.8.4 25 | "nodeVersion": "8.9.1", 26 | 27 | // Install PhantomJS on the server 28 | "setupPhantom": true, 29 | 30 | // Show a progress bar during the upload of the bundle to the server. 31 | // Might cause an error in some rare cases if set to true, for instance in Shippable CI 32 | "enableUploadProgressBar": true, 33 | 34 | // Application name (no spaces). 35 | "appName": "meteor", 36 | 37 | // Location of app (local directory). This can reference '~' as the users home directory. 38 | // i.e., "app": "~/Meteor/my-app", 39 | // This is the same as the line below. 40 | //"app": "/Users/bordalix/Meteor/my-app", 41 | "app": ".", 42 | 43 | // Configure environment 44 | // ROOT_URL must be set to https://YOURDOMAIN.com when using the spiderable package & force SSL 45 | // your NGINX proxy or Cloudflare. When using just Meteor on SSL without spiderable this is not necessary 46 | "env": { 47 | "PORT": 8282, 48 | "ROOT_URL": "http://localhost" 49 | //"MONGO_URL": "mongodb://bordalix:fd8dsjsfh7@hanso.mongohq.com:10023/MyApp", 50 | //"MAIL_URL": "smtp://postmaster%40myapp.mailgun.org:adj87sjhd7s@smtp.mailgun.org:587/" 51 | }, 52 | 53 | // Yamup checks if the app comes online just after the deployment. 54 | // Before yamup checks that, it will wait for the number of seconds configured below. 55 | "deployCheckWaitTime": 15 56 | } 57 | -------------------------------------------------------------------------------- /templates/linux/stud.conf: -------------------------------------------------------------------------------- 1 | # 2 | # stud(8), The Scalable TLS Unwrapping Daemon's configuration 3 | # 4 | 5 | # NOTE: all config file parameters can be overriden 6 | # from command line! 7 | 8 | # Listening address. REQUIRED. 9 | # 10 | # type: string 11 | # syntax: [HOST]:PORT 12 | frontend = "[*]:443" 13 | 14 | # Upstream server address. REQUIRED. 15 | # 16 | # type: string 17 | # syntax: [HOST]:PORT. 18 | backend = "<%= backend %>" 19 | 20 | # SSL x509 certificate file. REQUIRED. 21 | # List multiple certs to use SNI. Certs are used in the order they 22 | # are listed; the last cert listed will be used if none of the others match 23 | # 24 | # type: string 25 | 26 | # since docker can see config folder as /config we need to set ssl accordingly. 27 | # actual location will be /opt/comet/stud.conf 28 | pem-file = "/opt/stud/ssl.pem" 29 | 30 | # SSL protocol. 31 | # 32 | # tls = on 33 | # ssl = off 34 | 35 | # List of allowed SSL ciphers. 36 | # 37 | # Run openssl ciphers for list of available ciphers. 38 | # type: string 39 | ciphers = "" 40 | 41 | # Enforce server cipher list order 42 | # 43 | # type: boolean 44 | prefer-server-ciphers = off 45 | 46 | # Use specified SSL engine 47 | # 48 | # type: string 49 | ssl-engine = "" 50 | 51 | # Number of worker processes 52 | # 53 | # type: integer 54 | workers = 1 55 | 56 | # Listen backlog size 57 | # 58 | # type: integer 59 | backlog = 100 60 | 61 | # TCP socket keepalive interval in seconds 62 | # 63 | # type: integer 64 | keepalive = 3600 65 | 66 | # Chroot directory 67 | # 68 | # type: string 69 | chroot = "" 70 | 71 | # Set uid after binding a socket 72 | # 73 | # type: string 74 | user = "stud" 75 | 76 | # Set gid after binding a socket 77 | # 78 | # type: string 79 | group = "stud" 80 | 81 | # Quiet execution, report only error messages 82 | # 83 | # type: boolean 84 | quiet = on 85 | 86 | # Use syslog for logging 87 | # 88 | # type: boolean 89 | syslog = off 90 | 91 | # Syslog facility to use 92 | # 93 | # type: string 94 | syslog-facility = "daemon" 95 | 96 | # Run as daemon 97 | # 98 | # type: boolean 99 | daemon = off 100 | 101 | # Report client address by writing IP before sending data 102 | # 103 | # NOTE: This option is mutually exclusive with option write-proxy and proxy-proxy. 104 | # 105 | # type: boolean 106 | write-ip = off 107 | 108 | # Report client address using SENDPROXY protocol, see 109 | # http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt 110 | # for details. 111 | # 112 | # NOTE: This option is mutually exclusive with option write-ip and proxy-proxy. 113 | # 114 | # type: boolean 115 | write-proxy = off 116 | 117 | # Proxy an existing SENDPROXY protocol header through this request. 118 | # 119 | # NOTE: This option is mutually exclusive with option write-ip and write-proxy. 120 | # 121 | # type: boolean 122 | proxy-proxy = off 123 | 124 | # EOF -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | /* eslint-disable no-param-reassign */ 3 | const cjson = require('cjson'); 4 | const path = require('path'); 5 | const fs = require('fs'); 6 | const { format } = require('util'); 7 | const helpers = require('./helpers'); 8 | 9 | require('colors'); 10 | 11 | function mupErrorLog(message) { 12 | const errorMessage = `Invalid yamup.json file: ${message}`; 13 | console.error(errorMessage.red.bold); 14 | process.exit(1); 15 | } 16 | 17 | function rewriteHome(location) { 18 | if (/^win/.test(process.platform)) { 19 | return location.replace('~', process.env.USERPROFILE); 20 | } 21 | return location.replace('~', process.env.HOME); 22 | } 23 | 24 | function getCanonicalPath(location) { 25 | const localDir = path.resolve(__dirname, location); 26 | if (fs.existsSync(localDir)) { 27 | return localDir; 28 | } 29 | return path.resolve(rewriteHome(location)); 30 | } 31 | 32 | // eslint-disable-next-line consistent-return 33 | exports.read = function read() { 34 | const mupJsonPath = path.resolve('yamup.json'); 35 | if (fs.existsSync(mupJsonPath)) { 36 | const mupJson = cjson.load(mupJsonPath); 37 | 38 | // initialize options 39 | mupJson.env = mupJson.env || {}; 40 | 41 | if (typeof mupJson.setupNode === 'undefined') { 42 | mupJson.setupNode = true; 43 | } 44 | if (typeof mupJson.setupPhantom === 'undefined') { 45 | mupJson.setupPhantom = true; 46 | } 47 | mupJson.meteorBinary = (mupJson.meteorBinary) ? getCanonicalPath(mupJson.meteorBinary) : 'meteor'; 48 | if (typeof mupJson.appName === 'undefined') { 49 | mupJson.appName = 'meteor'; 50 | } 51 | if (typeof mupJson.enableUploadProgressBar === 'undefined') { 52 | mupJson.enableUploadProgressBar = true; 53 | } 54 | 55 | // validating servers 56 | if (!mupJson.servers || mupJson.servers.length === 0) { 57 | mupErrorLog('Server information does not exist'); 58 | } else { 59 | mupJson.servers.forEach((server) => { 60 | let sshAgentExists = false; 61 | const sshAgent = process.env.SSH_AUTH_SOCK; 62 | if (sshAgent) { 63 | sshAgentExists = fs.existsSync(sshAgent); 64 | server.sshOptions = server.sshOptions || {}; 65 | server.sshOptions.agent = sshAgent; 66 | } 67 | 68 | if (!server.host) { 69 | mupErrorLog('Server host does not exist'); 70 | } else if (!server.username) { 71 | mupErrorLog('Server username does not exist'); 72 | } else if (!server.password && !server.pem && !sshAgentExists) { 73 | mupErrorLog('Server password, pem or a ssh agent does not exist'); 74 | } else if (!mupJson.app) { 75 | mupErrorLog('Path to app does not exist'); 76 | } 77 | 78 | server.os = server.os || 'linux'; 79 | 80 | if (server.pem) { 81 | server.pem = rewriteHome(server.pem); 82 | } 83 | 84 | server.env = server.env || {}; 85 | const defaultEndpointUrl = format('http://%s:%s', server.host, mupJson.env.PORT || 80); 86 | server.env.CLUSTER_ENDPOINT_URL = server.env.CLUSTER_ENDPOINT_URL || defaultEndpointUrl; 87 | }); 88 | } 89 | 90 | // rewrite ~ with $HOME 91 | mupJson.app = rewriteHome(mupJson.app); 92 | 93 | if (mupJson.ssl) { 94 | mupJson.ssl.backendPort = mupJson.ssl.backendPort || 80; 95 | mupJson.ssl.pem = path.resolve(rewriteHome(mupJson.ssl.pem)); 96 | if (!fs.existsSync(mupJson.ssl.pem)) { 97 | mupErrorLog('SSL pem file does not exist'); 98 | } 99 | } 100 | 101 | return mupJson; 102 | } 103 | console.error('yamup.json file does not exist!'.red.bold); 104 | helpers.printHelp(); 105 | process.exit(1); 106 | }; 107 | -------------------------------------------------------------------------------- /lib/taskLists/linux.js: -------------------------------------------------------------------------------- 1 | const nodemiral = require('nodemiral'); 2 | const path = require('path'); 3 | const util = require('util'); 4 | 5 | const SCRIPT_DIR = path.resolve(__dirname, '../../scripts/linux'); 6 | const TEMPLATES_DIR = path.resolve(__dirname, '../../templates/linux'); 7 | 8 | function installStud(taskList) { 9 | taskList.executeScript('Installing Stud', { 10 | script: path.resolve(SCRIPT_DIR, 'install-stud.sh'), 11 | }); 12 | } 13 | 14 | function configureStud(taskList, pemFilePath, port) { 15 | const backend = { host: '127.0.0.1', port }; 16 | 17 | taskList.copy('Configuring Stud for Upstart', { 18 | src: path.resolve(TEMPLATES_DIR, 'stud.init.conf'), 19 | dest: '/etc/init/stud.conf', 20 | }); 21 | 22 | taskList.copy('Configuring SSL', { 23 | src: pemFilePath, 24 | dest: '/opt/stud/ssl.pem', 25 | }); 26 | 27 | 28 | taskList.copy('Configuring Stud', { 29 | src: path.resolve(TEMPLATES_DIR, 'stud.conf'), 30 | dest: '/opt/stud/stud.conf', 31 | vars: { 32 | backend: util.format('[%s]:%d', backend.host, backend.port), 33 | }, 34 | }); 35 | 36 | taskList.execute('Verifying SSL Configurations (ssl.pem)', { 37 | command: 'stud --test --config=/opt/stud/stud.conf', 38 | }); 39 | 40 | // restart stud 41 | taskList.execute('Starting Stud', { 42 | command: '(sudo stop stud || :) && (sudo start stud || :)', 43 | }); 44 | } 45 | 46 | exports.setup = function setup(config) { 47 | const taskList = nodemiral.taskList('Setup (linux)'); 48 | 49 | // Installation 50 | if (config.setupNode) { 51 | taskList.executeScript('Installing Node.js', { 52 | script: path.resolve(SCRIPT_DIR, 'install-node.sh'), 53 | vars: { 54 | nodeVersion: config.nodeVersion, 55 | }, 56 | }); 57 | } 58 | 59 | if (config.setupPhantom) { 60 | taskList.executeScript('Installing PhantomJS', { 61 | script: path.resolve(SCRIPT_DIR, 'install-phantomjs.sh'), 62 | }); 63 | } 64 | 65 | taskList.executeScript('Setting up Environment', { 66 | script: path.resolve(SCRIPT_DIR, 'setup-env.sh'), 67 | vars: { 68 | appName: config.appName, 69 | }, 70 | }); 71 | 72 | if (config.setupMongo) { 73 | taskList.copy('Copying MongoDB configuration', { 74 | src: path.resolve(TEMPLATES_DIR, 'mongodb.conf'), 75 | dest: '/etc/mongodb.conf', 76 | }); 77 | 78 | taskList.executeScript('Installing MongoDB', { 79 | script: path.resolve(SCRIPT_DIR, 'install-mongodb.sh'), 80 | }); 81 | } 82 | 83 | if (config.ssl) { 84 | installStud(taskList); 85 | configureStud(taskList, config.ssl.pem, config.ssl.backendPort); 86 | } 87 | 88 | // configurations 89 | taskList.executeScript('Verifying upstart or systemd', { 90 | script: path.resolve(SCRIPT_DIR, 'upstartORsystemd.sh'), 91 | }, (val) => { 92 | if (val === 'upstart') { 93 | taskList.copy('Configuring upstart', { 94 | src: path.resolve(TEMPLATES_DIR, 'meteor.upstart.conf'), 95 | dest: `/etc/init/${config.appName}.conf`, 96 | vars: { appName: config.appName }, 97 | }, 98 | () => { 99 | taskList.executeScript('Wrapping all up', { 100 | script: path.resolve(SCRIPT_DIR, 'wrap-up.sh'), 101 | vars: { appName: config.appName }, 102 | }); 103 | }); 104 | } else { 105 | taskList.copy('Configuring systemd', { 106 | src: path.resolve(TEMPLATES_DIR, 'meteor.systemd.conf'), 107 | dest: `/etc/systemd/system/${config.appName}.service`, 108 | vars: { appName: config.appName }, 109 | }, () => { 110 | taskList.executeScript('Wrapping all up', { 111 | script: path.resolve(SCRIPT_DIR, 'wrap-up.sh'), 112 | vars: { appName: config.appName }, 113 | }); 114 | }); 115 | } 116 | }); 117 | 118 | return taskList; 119 | }; 120 | 121 | exports.deploy = function deploy(bundlePath, env, waitTime, appName, progressBar) { 122 | const taskList = nodemiral.taskList(`Deploy app ${appName} (linux)`); 123 | 124 | taskList.copy('Uploading bundle', { 125 | src: bundlePath, 126 | dest: `/opt/${appName}/tmp/bundle.tar.gz`, 127 | progressBar, 128 | }); 129 | 130 | taskList.copy('Setting up Environment Variables', { 131 | src: path.resolve(TEMPLATES_DIR, 'env.sh'), 132 | dest: `/opt/${appName}/config/env.sh`, 133 | vars: { 134 | env: env || {}, 135 | appName, 136 | }, 137 | }); 138 | 139 | taskList.copy('Setting up start script for systemd', { 140 | src: path.resolve(TEMPLATES_DIR, 'start.sh'), 141 | dest: `/opt/${appName}/start.sh`, 142 | vars: { 143 | env: env || {}, 144 | appName, 145 | }, 146 | }); 147 | 148 | // deploying 149 | taskList.executeScript('Invoking deployment process', { 150 | script: path.resolve(TEMPLATES_DIR, 'deploy.sh'), 151 | vars: { 152 | deployCheckWaitTime: waitTime || 10, 153 | appName, 154 | }, 155 | }); 156 | 157 | return taskList; 158 | }; 159 | 160 | exports.reconfig = function reconfig(env, appName) { 161 | const taskList = nodemiral.taskList('Updating configurations (linux)'); 162 | 163 | taskList.copy('Setting up Environment Variables', { 164 | src: path.resolve(TEMPLATES_DIR, 'env.sh'), 165 | dest: `/opt/${appName}/config/env.sh`, 166 | vars: { 167 | env: env || {}, 168 | appName, 169 | }, 170 | }); 171 | 172 | taskList.copy('Setting up start script for systemd', { 173 | src: path.resolve(TEMPLATES_DIR, 'start.sh'), 174 | dest: `/opt/${appName}/start.sh`, 175 | vars: { 176 | env: env || {}, 177 | appName, 178 | }, 179 | }); 180 | 181 | // restarting 182 | taskList.executeScript('Restarting app', { 183 | script: path.resolve(SCRIPT_DIR, 'restart.sh'), 184 | vars: { appName }, 185 | }); 186 | 187 | return taskList; 188 | }; 189 | 190 | exports.restart = function restart(appName) { 191 | const taskList = nodemiral.taskList('Restarting Application (linux)'); 192 | 193 | // restarting 194 | taskList.executeScript('Restarting app', { 195 | script: path.resolve(SCRIPT_DIR, 'restart.sh'), 196 | vars: { appName }, 197 | }); 198 | 199 | return taskList; 200 | }; 201 | 202 | exports.stop = function stop(appName) { 203 | const taskList = nodemiral.taskList('Stopping Application (linux)'); 204 | 205 | // stopping 206 | taskList.executeScript('Stopping app', { 207 | script: path.resolve(SCRIPT_DIR, 'stop.sh'), 208 | vars: { appName }, 209 | }); 210 | 211 | return taskList; 212 | }; 213 | 214 | exports.start = function start(appName) { 215 | const taskList = nodemiral.taskList('Starting Application (linux)'); 216 | 217 | // starting 218 | taskList.executeScript('Starting app', { 219 | script: path.resolve(SCRIPT_DIR, 'start.sh'), 220 | vars: { appName }, 221 | }); 222 | 223 | return taskList; 224 | }; 225 | -------------------------------------------------------------------------------- /lib/actions.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable global-require */ 2 | /* eslint-disable import/no-dynamic-require */ 3 | /* eslint-disable prefer-spread */ 4 | /* eslint-disable no-param-reassign */ 5 | /* eslint-disable no-console */ 6 | /* eslint-disable no-underscore-dangle */ 7 | const nodemiral = require('nodemiral'); 8 | const path = require('path'); 9 | const fs = require('fs'); 10 | const rimraf = require('rimraf'); 11 | const uuid = require('uuid'); 12 | const _ = require('underscore'); 13 | const async = require('async'); 14 | const os = require('os'); 15 | const buildApp = require('./build.js'); 16 | require('colors'); 17 | 18 | function hasSummaryMapErrors(summaryMap) { 19 | return _.some(summaryMap, (summary) => summary.error); 20 | } 21 | 22 | function haveSummaryMapsErrors(summaryMaps) { 23 | return _.some(summaryMaps, hasSummaryMapErrors); 24 | } 25 | 26 | function whenAfterCompleted(error, summaryMaps) { 27 | const errorCode = error || haveSummaryMapsErrors(summaryMaps) ? 1 : 0; 28 | process.exit(errorCode); 29 | } 30 | 31 | function whenAfterDeployed(buildLocation) { 32 | // eslint-disable-next-line func-names 33 | return function (error, summaryMaps) { 34 | rimraf.sync(buildLocation); 35 | whenAfterCompleted(error, summaryMaps); 36 | }; 37 | } 38 | 39 | function Actions(config, cwd) { 40 | this.cwd = cwd; 41 | this.config = config; 42 | this.sessionsMap = this._createSessionsMap(config); 43 | 44 | // get settings.json into env 45 | const setttingsJsonPath = path.resolve(this.cwd, 'settings.json'); 46 | if (fs.existsSync(setttingsJsonPath)) { 47 | this.config.env.METEOR_SETTINGS = JSON.stringify(require(setttingsJsonPath)); 48 | } 49 | } 50 | 51 | module.exports = Actions; 52 | 53 | Actions.prototype._createSessionsMap = function _createSessionsMap(config) { 54 | const sessionsMap = {}; 55 | 56 | config.servers.forEach((server) => { 57 | const { host } = server; 58 | const auth = { username: server.username }; 59 | 60 | if (server.pem) { 61 | auth.pem = fs.readFileSync(path.resolve(server.pem), 'utf8'); 62 | } else { 63 | auth.password = server.password; 64 | } 65 | 66 | const nodemiralOptions = { 67 | ssh: server.sshOptions, 68 | keepAlive: true, 69 | }; 70 | 71 | if (!sessionsMap[server.os]) { 72 | sessionsMap[server.os] = { 73 | sessions: [], 74 | taskListsBuilder: require('./taskLists')(server.os), 75 | }; 76 | } 77 | 78 | const session = nodemiral.session(host, auth, nodemiralOptions); 79 | session._serverConfig = server; 80 | sessionsMap[server.os].sessions.push(session); 81 | }); 82 | 83 | return sessionsMap; 84 | }; 85 | 86 | Actions.prototype._executePararell = function _executePararell(actionName, args) { 87 | const self = this; 88 | const sessionInfoList = _.values(self.sessionsMap); 89 | async.map( 90 | sessionInfoList, 91 | (sessionsInfo, callback) => { 92 | const taskList = sessionsInfo.taskListsBuilder[actionName] 93 | .apply(sessionsInfo.taskListsBuilder, args); 94 | taskList.run(sessionsInfo.sessions, (summaryMap) => { 95 | callback(null, summaryMap); 96 | }); 97 | }, 98 | whenAfterCompleted, 99 | ); 100 | }; 101 | 102 | Actions.prototype.setup = function setup() { 103 | this._executePararell('setup', [this.config]); 104 | }; 105 | 106 | Actions.prototype.deploy = function deploy() { 107 | const self = this; 108 | 109 | const buildLocation = path.resolve(os.tmpdir(), uuid.v4()); 110 | const bundlePath = path.resolve(buildLocation, 'bundle.tar.gz'); 111 | 112 | // spawn inherits env vars from process.env 113 | // so we can simply set them like this 114 | process.env.BUILD_LOCATION = buildLocation; 115 | 116 | const { deployCheckWaitTime } = this.config; 117 | const { appName } = this.config; 118 | const appPath = this.config.app; 119 | const { enableUploadProgressBar } = this.config; 120 | const { meteorBinary } = this.config; 121 | 122 | console.log(`Building Started: ${this.config.app}`); 123 | buildApp(appPath, meteorBinary, buildLocation, (err) => { 124 | if (err) { 125 | process.exit(1); 126 | } else { 127 | const sessionsData = []; 128 | _.forEach(self.sessionsMap, (sessionsInfo) => { 129 | const { taskListsBuilder } = sessionsInfo; 130 | _.forEach(sessionsInfo.sessions, (session) => { 131 | sessionsData.push({ taskListsBuilder, session }); 132 | }); 133 | }); 134 | 135 | async.mapSeries( 136 | sessionsData, 137 | (sessionData, callback) => { 138 | const { session } = sessionData; 139 | const { taskListsBuilder } = sessionData; 140 | const env = _.extend({}, self.config.env, session._serverConfig.env); 141 | const taskList = taskListsBuilder.deploy( 142 | bundlePath, env, 143 | deployCheckWaitTime, appName, enableUploadProgressBar, 144 | ); 145 | taskList.run(session, (summaryMap) => { 146 | callback(null, summaryMap); 147 | }); 148 | }, 149 | whenAfterDeployed(buildLocation), 150 | ); 151 | } 152 | }); 153 | }; 154 | 155 | Actions.prototype.reconfig = function reconfig() { 156 | const self = this; 157 | const sessionInfoList = []; 158 | Object.keys(self.sessionsMap).forEach((ops) => { 159 | const sessionsInfo = self.sessionsMap[ops]; 160 | sessionsInfo.sessions.forEach((session) => { 161 | const env = _.extend({}, self.config.env, session._serverConfig.env); 162 | const taskList = sessionsInfo.taskListsBuilder.reconfig(env, self.config.appName); 163 | sessionInfoList.push({ taskList, session }); 164 | }); 165 | }); 166 | 167 | async.mapSeries( 168 | sessionInfoList, 169 | (sessionInfo, callback) => { 170 | sessionInfo.taskList.run(sessionInfo.session, (summaryMap) => { 171 | callback(null, summaryMap); 172 | }); 173 | }, 174 | whenAfterCompleted, 175 | ); 176 | }; 177 | 178 | Actions.prototype.restart = function restart() { 179 | this._executePararell('restart', [this.config.appName]); 180 | }; 181 | 182 | Actions.prototype.stop = function stop() { 183 | this._executePararell('stop', [this.config.appName]); 184 | }; 185 | 186 | Actions.prototype.start = function start() { 187 | this._executePararell('start', [this.config.appName]); 188 | }; 189 | 190 | Actions.prototype.logs = function logs() { 191 | const self = this; 192 | const tailOptions = process.argv.slice(3).join(' '); 193 | 194 | Object.keys(self.sessionsMap).forEach((ops) => { 195 | const sessionsInfo = self.sessionsMap[ops]; 196 | sessionsInfo.sessions.forEach((session) => { 197 | const hostPrefix = `[${session._host}] `; 198 | const options = { 199 | onStdout: (data) => { 200 | process.stdout.write(hostPrefix + data.toString()); 201 | }, 202 | onStderr: (data) => { 203 | process.stderr.write(hostPrefix + data.toString()); 204 | }, 205 | }; 206 | session.execute('cat /etc/os-release 2> /dev/null', {}, (erro, code, loggs) => { 207 | if (/Ubuntu/.test(loggs.stdout)) { 208 | const command = `sudo tail ${tailOptions} /var/log/syslog | grep ${self.config.appName}`; 209 | session.execute(command, options); 210 | } else { 211 | const command = `sudo tail ${tailOptions} /var/log/upstart/${self.config.appName}.log`; 212 | session.execute(command, options); 213 | } 214 | }); 215 | }); 216 | }); 217 | }; 218 | 219 | Actions.init = function init() { 220 | const destMupJson = path.resolve('yamup.json'); 221 | const destSettingsJson = path.resolve('settings.json'); 222 | 223 | if (fs.existsSync(destMupJson) || fs.existsSync(destSettingsJson)) { 224 | console.error('A Project Already Exists'.bold.red); 225 | process.exit(1); 226 | } 227 | 228 | const exampleMupJson = path.resolve(__dirname, '../example/yamup.json'); 229 | const exampleSettingsJson = path.resolve(__dirname, '../example/settings.json'); 230 | 231 | function copyFile(src, dest) { 232 | const content = fs.readFileSync(src, 'utf8'); 233 | fs.writeFileSync(dest, content); 234 | } 235 | 236 | copyFile(exampleMupJson, destMupJson); 237 | copyFile(exampleSettingsJson, destSettingsJson); 238 | 239 | console.log('Empty Project Initialized!'.bold.green); 240 | }; 241 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yet Another Meteor UP 2 | 3 | 4 | #### Production Quality Meteor Deployments 5 | 6 | Yet Another Meteor UP (yamup for short) is a command line tool that allows you to deploy any [Meteor](http://meteor.com) app to your own server. It supports only Debian/Ubuntu flavours. (PRs are welcome) 7 | 8 | You can install and use yamup from Linux, Mac. 9 | 10 | Yet Another Meteor UP (yamup) does not use docker containers like all the rest MUP forks, it's based on the original MUP, but updated for modern Meteor times. 11 | 12 | **Note:** I Can confirm this branch works with Meteor 1.5 Node 4.8.4 and MongoDB 3.2 and an Ubuntu 14 EC2 instance. 13 | 14 | **Note:** I Can confirm this branch works with Meteor 1.6 Node 8.9.1 and MongoDB 3.2 and an Ubuntu 14/16/18 EC2 instance. 15 | 16 | > Screencast: [How to deploy a Meteor app with Meteor Up (by Sacha Greif)](https://www.youtube.com/watch?v=WLGdXtZMmiI) 17 | 18 | **Table of Contents** 19 | 20 | - [Features](#features) 21 | - [Server Configuration](#server-configuration) 22 | - [SSH-key-based authentication (with passphrase)](#ssh-keys-with-passphrase-or-ssh-agent-support) 23 | - [Installation](#installation) 24 | - [Creating a yamup Project](#creating-a-yamup-project) 25 | - [Example File](#example-file) 26 | - [Setting Up a Server](#setting-up-a-server) 27 | - [Deploying an App](#deploying-an-app) 28 | - [Additional Setup/Deploy Information](#additional-setupdeploy-information) 29 | - [Server Setup Details](#server-setup-details) 30 | - [Deploy Wait Time](#deploy-wait-time) 31 | - [Multiple Deployment Targets](#multiple-deployment-targets) 32 | - [Access Logs](#access-logs) 33 | - [Reconfiguring & Restarting](#reconfiguring--restarting) 34 | - [Accessing the Database](#accessing-the-database) 35 | - [Multiple Deployments](#multiple-deployments) 36 | - [Server Specific Environment Variables](#server-specific-environment-variables) 37 | - [SSL Support](#ssl-support) 38 | - [Via nginx and let's encrypt](#via-nginx-and-lets-encrypt) 39 | - [Via stud](#via-stud) 40 | - [Updating](#updating) 41 | - [Troubleshooting](#troubleshooting) 42 | - [Additional Resources](#additional-resources) 43 | 44 | ### Features 45 | 46 | * Single command server setup 47 | * Single command deployment 48 | * Multi server deployment 49 | * Environmental Variables management 50 | * Support for [`settings.json`](http://docs.meteor.com/#meteor_settings) 51 | * Password or Private Key(pem) based server authentication 52 | * Access, logs from the terminal (supports log tailing) 53 | * Support for multiple meteor deployments (experimental) 54 | 55 | ### Server Configuration 56 | 57 | * Auto-Restart if the app crashed (using forever) 58 | * Auto-Start after the server reboot (using upstart/systemd) 59 | * Stepdown User Privileges 60 | * Revert to the previous version, if the deployment failed 61 | * Secured MongoDB Installation (Optional) 62 | * Pre-Installed PhantomJS (Optional) 63 | 64 | ### Installation 65 | 66 | Npm install 67 | 68 | sudo npm install -g yamup 69 | 70 | Git clone 71 | 72 | sudo npm remove -g yamup # Only if you already installed yamup before 73 | git clone https://github.com/bordalix/yamup.git 74 | cd yamup 75 | sudo npm install -g 76 | 77 | ### Creating a yamup Project 78 | 79 | mkdir ~/my-meteor-deployment 80 | cd ~/my-meteor-deployment 81 | yamup init 82 | 83 | This will create two files in your Meteor Up project directory: 84 | 85 | * yamup.json - yamup configuration file 86 | * settings.json - Settings for Meteor's [settings API](http://docs.meteor.com/#meteor_settings) 87 | 88 | `yamup.json` is commented and easy to follow (it supports JavaScript comments). 89 | 90 | ### Example File 91 | 92 | ```js 93 | { 94 | // Server authentication info 95 | "servers": [ 96 | { 97 | "host": "hostname", 98 | "username": "root", 99 | "password": "password", 100 | // or pem file (ssh based authentication) 101 | //"pem": "~/.ssh/id_rsa", 102 | // Also, for non-standard ssh port use this 103 | //"sshOptions": { "port" : 49154 }, 104 | // server specific environment variables 105 | "env": {} 106 | } 107 | ], 108 | 109 | // Install MongoDB on the server. Does not destroy the local MongoDB on future setups 110 | "setupMongo": true, 111 | 112 | // WARNING: Node.js is required! Only skip if you already have Node.js installed on server. 113 | "setupNode": true, 114 | 115 | // WARNING: nodeVersion defaults to 8.9.1 if omitted. Do not use v, just the version number. 116 | // For Meteor 1.5.*, use 4.8.4 117 | "nodeVersion": "8.9.1", 118 | 119 | // Install PhantomJS on the server 120 | "setupPhantom": true, 121 | 122 | // Show a progress bar during the upload of the bundle to the server. 123 | // Might cause an error in some rare cases if set to true, for instance in Shippable CI 124 | "enableUploadProgressBar": true, 125 | 126 | // Application name (no spaces). 127 | "appName": "meteor", 128 | 129 | // Location of app (local directory). This can reference '~' as the users home directory. 130 | // i.e., "app": "~/Meteor/my-app", 131 | // This is the same as the line below. 132 | "app": "/Users/bordalix/Meteor/my-app", 133 | 134 | // Configure environment 135 | // ROOT_URL must be set to https://YOURDOMAIN.com when using the spiderable package & force SSL 136 | // your NGINX proxy or Cloudflare. When using just Meteor on SSL without spiderable this is not necessary 137 | "env": { 138 | "PORT": 80, 139 | "ROOT_URL": "http://myapp.com", 140 | "MONGO_URL": "mongodb://bordalix:fd8dsjsfh7@hanso.mongohq.com:10023/MyApp", 141 | "MAIL_URL": "smtp://postmaster%40myapp.mailgun.org:adj87sjhd7s@smtp.mailgun.org:587/" 142 | }, 143 | 144 | // yamup checks if the app comes online just after the deployment. 145 | // Before yamup checks that, it will wait for the number of seconds configured below. 146 | "deployCheckWaitTime": 15 147 | } 148 | ``` 149 | 150 | ### Setting Up a Server 151 | 152 | yamup setup 153 | 154 | This will setup the server for the `yamup` deployments. It will take around 2-5 minutes depending on the server's performance and network availability. 155 | 156 | ### Deploying an App 157 | 158 | yamup deploy 159 | 160 | This will bundle the Meteor project and deploy it to the server. 161 | 162 | ### Additional Setup/Deploy Information 163 | 164 | #### Deploy Wait Time 165 | 166 | yamup checks if the deployment is successful or not just after the deployment. By default, it will wait 10 seconds before the check. You can configure the wait time with the `deployCheckWaitTime` option in the `yamup.json` 167 | 168 | #### SSH keys with passphrase (or ssh-agent support) 169 | 170 | > This only tested with Mac/Linux 171 | 172 | With the help of `ssh-agent`, `` can use SSH keys encrypted with a 173 | passphrase. 174 | 175 | Here's the process: 176 | 177 | * First remove your `pem` field from the `yamup.json`. So, your `yamup.json` only has the username and host only. 178 | * Then start a ssh agent with `eval $(ssh-agent)` 179 | * Then add your ssh key with `ssh-add ` 180 | * Then you'll asked to enter the passphrase to the key 181 | * After that simply invoke `yamup` commands and they'll just work 182 | * Once you've deployed your app kill the ssh agent with `ssh-agent -k` 183 | 184 | #### Ssh based authentication with `sudo` 185 | 186 | **If your username is `root`, you don't need to follow these steps** 187 | 188 | Please ensure your key file (pem) is not protected by a passphrase. Also the setup process will require NOPASSWD access to sudo. (Since Meteor needs port 80, sudo access is required.) 189 | 190 | Make sure you also add your ssh key to the ```/YOUR_USERNAME/.ssh/authorized_keys``` list 191 | 192 | You can add your user to the sudo group: 193 | 194 | sudo adduser *username* sudo 195 | 196 | And you also need to add NOPASSWD to the sudoers file: 197 | 198 | sudo visudo 199 | 200 | # replace this line 201 | %sudo ALL=(ALL) ALL 202 | 203 | # by this line 204 | %sudo ALL=(ALL) NOPASSWD:ALL 205 | 206 | When this process is not working you might encounter the following error: 207 | 208 | 'sudo: no tty present and no askpass program specified' 209 | 210 | #### Server Setup Details 211 | 212 | This is how yamup will configure the server for you based on the given `appName` or using "meteor" as default appName. This information will help you customize the server for your needs. 213 | 214 | * your app lives at `/opt//app` 215 | * MongoDB installed and bound to the local interface (cannot access from the outside) 216 | * the database is named `` 217 | * yamup uses `upstart` or `systemd` depending on your Ubuntu version: 218 | 219 | ##### upstart 220 | * yamup uses `upstart` with a config file at `/etc/init/.conf` 221 | * you can start and stop the app with `sudo start ` and `sudo stop ` 222 | * logs are located at: `/var/log/upstart/.log` 223 | 224 | ##### systemd 225 | * yamup uses `systemd` with a config file at `/etc/systemd/system/.service` 226 | * you can start and stop the app with `sudo service start` and `sudo service stop` 227 | * logs are located at: `/var/log/syslog | grep ` 228 | 229 | For more information see [`lib/taskLists.js`](https://github.com/bordalix/yamup/blob/master/lib/taskLists.js). 230 | 231 | #### Multiple Deployment Targets 232 | 233 | You can use an array to deploy to multiple servers at once. 234 | 235 | To deploy to *different* environments (e.g. staging, production, etc.), use separate yamup configurations in separate directories, with each directory containing separate `yamup.json` and `settings.json` files, and the `yamup.json` files' `app` field pointing back to your app's local directory. 236 | 237 | #### Custom Meteor Binary 238 | 239 | Sometimes, you might be using `mrt`, or Meteor from a git checkout. By default, yamup uses `meteor`. You can ask yamup to use the correct binary with the `meteorBinary` option. 240 | 241 | ~~~js 242 | { 243 | ... 244 | "meteorBinary": "~/bin/meteor/meteor" 245 | ... 246 | } 247 | ~~~ 248 | 249 | ### Access Logs 250 | 251 | yamup logs -f 252 | 253 | Mupc can tail logs from the server and supports all the options of `tail`. 254 | 255 | ### Reconfiguring & Restarting 256 | 257 | After you've edit environmental variables or `settings.json`, you can reconfigure the app without deploying again. Use the following command to do update the settings and restart the app. 258 | 259 | yamup reconfig 260 | 261 | If you want to stop, start or restart your app for any reason, you can use the following commands to manage it. 262 | 263 | yamup stop 264 | yamup start 265 | yamup restart 266 | 267 | ### Accessing the Database 268 | 269 | You can't access the MongoDB from the outside the server. To access the MongoDB shell you need to log into your server via SSH first and then run the following command: 270 | 271 | mongo appName 272 | 273 | ### Server Specific Environment Variables 274 | 275 | It is possible to provide server specific environment variables. Add the `env` object along with the server details in the `yamup.json`. Here's an example: 276 | 277 | ~~~js 278 | { 279 | "servers": [ 280 | { 281 | "host": "hostname", 282 | "username": "root", 283 | "password": "password", 284 | "env": { 285 | "SOME_ENV": "the-value" 286 | } 287 | } 288 | 289 | ... 290 | } 291 | ~~~ 292 | 293 | By default, yamup adds `CLUSTER_ENDPOINT_URL` to make [cluster](https://github.com/meteorhacks/cluster) deployment simple. But you can override it by defining it yourself. 294 | 295 | ### Multiple Deployments 296 | 297 | yamup supports multiple deployments to a single server. yamup only does the deployment; if you need to configure subdomains, you need to manually setup a reverse proxy yourself. 298 | 299 | Let's assume, we need to deploy production and staging versions of the app to the same server. The production app runs on port 80 and the staging app runs on port 8000. 300 | 301 | We need to have two separate yamup projects. For that, create two directories and initialize yamup and add the necessary configurations. 302 | 303 | In the staging `yamup.json`, add a field called `appName` with the value `staging`. You can add any name you prefer instead of `staging`. Since we are running our staging app on port 8000, add an environment variable called `PORT` with the value 8000. 304 | 305 | Now setup both projects and deploy as you need. 306 | 307 | ### SSL Support 308 | 309 | You can enable SSL in two different ways, via [stud](https://github.com/bumptech/stud) (deprecated) or using nginx and let's encrypt (prefered method). 310 | 311 | #### Via nginx and let's encrypt 312 | 313 | **1 -** Configure a nginx site with a proxy_pass: 314 | 315 | file: /etc/nginx/sites-available/example.com 316 | 317 | ``` 318 | server { 319 | listen 80; 320 | server_name example.com www.example.com; 321 | } 322 | 323 | server { 324 | listen 443 ssl http2; 325 | listen [::]:443 ssl http2; 326 | charset UTF-8; 327 | server_name example.com www.example.com; 328 | 329 | # meteor app 330 | location / { 331 | proxy_pass http://localhost:3001; 332 | proxy_http_version 1.1; 333 | proxy_set_header Upgrade $http_upgrade; 334 | proxy_set_header Connection "upgrade"; 335 | proxy_set_header Host $host; 336 | proxy_cache_bypass $http_upgrade; 337 | } 338 | } 339 | ``` 340 | 341 | **2 -** Check your nginx configuration sintax: 342 | 343 | `sudo nginx -t` 344 | 345 | **3 -** Install certbot: 346 | 347 | ``` 348 | sudo apt-get update 349 | sudo apt-get install software-properties-common 350 | sudo add-apt-repository universe 351 | sudo add-apt-repository ppa:certbot/certbot 352 | sudo apt-get update 353 | sudo apt-get install certbot python-certbot-nginx 354 | ``` 355 | 356 | **4 -** Generate the certificates 357 | 358 | `sudo certbot --nginx -d example.com -d www.example.com` 359 | 360 | It should append this 2 lines to the file /etc/nginx/sites-available/example.com: 361 | 362 | ``` 363 | ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot 364 | ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot 365 | ``` 366 | 367 | **5 -** Reload nginx: 368 | 369 | `sudo nginx -s reload` 370 | 371 | **6 -** Configure yamup without SSL, and on port 3001. 372 | 373 | file: yamup.json 374 | 375 | ``` 376 | { 377 | // Server authentication info 378 | "servers": [ 379 | { 380 | "host": "example.com", 381 | "username": "aws_username", 382 | "pem": "aws_pem_file.pem" 383 | } 384 | ], 385 | 386 | // Install MongoDB in the server, does not destroy local MongoDB on future setup 387 | "setupMongo": true, 388 | 389 | // WARNING: Node.js is required! Only skip if you already have Node.js installed on server. 390 | "setupNode": false, 391 | 392 | // WARNING: If nodeVersion omitted will setup 0.10.36 by default. Do not use v, only version number. 393 | "nodeVersion": "8.9.1", 394 | 395 | // Install PhantomJS in the server 396 | "setupPhantom": false, 397 | 398 | // Show a progress bar during the upload of the bundle to the server. 399 | // Might cause an error in some rare cases if set to true, for instance in Shippable CI 400 | "enableUploadProgressBar": true, 401 | 402 | // Application name (No spaces) 403 | "appName": "example", 404 | 405 | // Location of app (local directory) 406 | "app": "./", 407 | 408 | // Configure environment 409 | "env": { 410 | "PORT": 3001, 411 | "ROOT_URL": "https://example.com", 412 | "MONGO_URL": "mongodb://127.0.0.1/example" 413 | }, 414 | 415 | // Meteor Up checks if the app comes online just after the deployment 416 | // before mup checks that, it will wait for no. of seconds configured below 417 | "deployCheckWaitTime": 15 418 | } 419 | ``` 420 | 421 | **7 -** Deploy it with `yamup deploy` or `yamup reconfig` and you should have your site running with SSL via Let's Encrypt. 422 | 423 | **8 -** To renew your certificates, just run on the server (you can put it on a cronjob also): 424 | 425 | `sudo certbot --nginx renew` 426 | 427 | **9 -** If you put the certificate renewal as a cronjob, you don't need to worry any more with SSL and certificates, and you can use yamup to simply build and deploy your Meteor app. Due to this, I don't plan to add support to Let's Encrypt directly. 428 | 429 | More info on [this gist](https://gist.github.com/cecilemuller/a26737699a7e70a7093d4dc115915de8). 430 | 431 | #### Via stud 432 | 433 | **Note:** deprecated method. 434 | 435 | yamup has built in SSL support. It uses [stud](https://github.com/bumptech/stud) SSL terminator for that. First you need to get a SSL certificate from some provider. This is how to do that: 436 | 437 | * [First you need to generate a CSR file and the private key](http://www.rackspace.com/knowledge_center/article/generate-a-csr-with-openssl) 438 | * Then purchase a SSL certificate. 439 | * Then generate a SSL certificate from your SSL providers UI. 440 | * Then that'll ask to provide the CSR file. Upload the CSR file we've generated. 441 | * When asked to select your SSL server type, select it as nginx. 442 | * Then you'll get a set of files (your domain certificate and CA files). 443 | 444 | Now you need combine SSL certificate(s) with the private key and save it in the mup config directory as `ssl.pem`. Check this [guide](http://alexnj.com/blog/configuring-a-positivessl-certificate-with-stud) to do that. 445 | 446 | Then add following configuration to your `yamup.json` file. 447 | 448 | ~~~js 449 | { 450 | ... 451 | 452 | "ssl": { 453 | "pem": "./ssl.pem", 454 | //"backendPort": 80 455 | } 456 | 457 | ... 458 | } 459 | ~~~ 460 | 461 | Now, simply do `yamup setup` and now you've the SSL support. 462 | 463 | > * By default, it'll think your Meteor app is running on port 80. If it's not, change it with the `backendPort` configuration field. 464 | > * SSL terminator will run on the default SSL port `443` 465 | > * If you are using multiple servers, SSL terminators will run on the each server (This is made to work with [cluster](https://github.com/meteorhacks/cluster)) 466 | > * Right now, you can't have multiple SSL terminators running inside a single server 467 | 468 | ### Updating 469 | 470 | To update `yamup` to the latest version, just type: 471 | 472 | npm update yamup -g 473 | 474 | You should try and keep `yamup` up to date in order to keep up with the latest Meteor changes. But note that if you need to update your Node version, you'll have to run `yamup setup` again before deploying. 475 | 476 | ### Troubleshooting 477 | 478 | #### Check Access 479 | 480 | Your issue might not always be related to yamup. So make sure you can connect to your instance first, and that your credentials are working properly. 481 | 482 | #### Check Logs 483 | If you suddenly can't deploy your app anymore, first use the `yamup logs -f` command to check the logs for error messages. 484 | 485 | One of the most common problems is your Node version getting out of date. In that case, see “Updating” section above. 486 | 487 | #### Verbose Output 488 | If you need to see the output of `` (to see more precisely where it's failing or hanging, for example), run it like so: 489 | 490 | DEBUG=* yamup 491 | 492 | where `` is one of the `yamup` commands such as `setup`, `deploy`, etc. 493 | 494 | #### Errors with bcrypt 495 | 496 | Don't use bcrypt (`meteor npm uninstall bcrypt`) if after deployment your app crashes and outputs this type of errors ([more info](https://github.com/bordalix/yamup/issues/5#issuecomment-528758181)): 497 | ``` 498 | systemd[1]: Started testapp. 499 | testapp[15111]: /usr/bin/node: symbol lookup error: /opt/testapp/app/programs/server/npm/node_modules/bcrypt/lib/binding/bcrypt_lib.node: undefined symbol: _ZN4node19GetCurrentEventLoopEPN2v87IsolateE 500 | systemd[1]: testapp.service: Main process exited, code=exited, status=127/n/a 501 | systemd[1]: testapp.service: Unit entered failed state. 502 | systemd[1]: testapp.service: Failed with result 'exit-code'. 503 | systemd[1]: testapp.service: Service hold-off time over, scheduling restart. 504 | systemd[1]: Stopped testapp. 505 | ``` 506 | 507 | ### Additional Resources 508 | 509 | * [Using yamup with Nitrous.io](https://github.com/arunoda/meteor-up/wiki/Using-Meteor-Up-with-Nitrous.io) 510 | * [Change Ownership of Additional Directories](https://github.com/arunoda/meteor-up/wiki/Change-Ownership-of-Additional-Directories) 511 | * [Using yamup with NginX vhosts](https://github.com/arunoda/meteor-up/wiki/Using-Meteor-Up-with-NginX-vhosts) 512 | --------------------------------------------------------------------------------