Switch to PM2 for dev + prod

This commit is contained in:
Ben Gotow 2016-07-07 15:25:45 -07:00
parent 822b8e54e6
commit 63f66fb7e7
9 changed files with 47 additions and 16 deletions

View file

@ -6,4 +6,4 @@ COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "run", "start-aws"]
CMD [ "./node_modules/pm2/bin/pm2", "start", "./pm2-prod-${AWS_SERVICE_NAME}.yml"]

View file

@ -1,2 +0,0 @@
web: node packages/nylas-api/app.js
worker: node packages/nylas-sync/app.js

View file

@ -1,5 +0,0 @@
redis: redis-server
api: node packages/nylas-api/app.js
sync: node packages/nylas-sync/app.js
processor: node packages/nylas-message-processor/app.js
dashboard: node packages/nylas-dashboard/app.js

View file

@ -6,6 +6,8 @@
"dependencies": {
"bluebird": "3.x.x",
"mysql": "^2.11.1",
"newrelic": "^1.28.1",
"pm2": "^1.1.3",
"redis": "2.x.x",
"rx": "4.x.x",
"sequelize": "3.x.x",
@ -23,7 +25,7 @@
"lerna": "2.0.0-beta.23"
},
"scripts": {
"start": "foreman start -f Procfile.dev",
"start": "./node_modules/pm2/bin/pm2 start ./pm2-dev.yml --no-daemon",
"start-aws": "node start-aws.js",
"postinstall": "node_modules/.bin/lerna bootstrap"
},

View file

@ -43,7 +43,7 @@ class DatabaseConnector {
});
}
return Sequelize(dbname, '', '', {
return new Sequelize(dbname, '', '', {
storage: path.join(STORAGE_DIR, `${dbname}.sqlite`),
dialect: "sqlite",
logging: false,

24
pm2-dev.yml Normal file
View file

@ -0,0 +1,24 @@
apps:
- script : packages/nylas-api/app.js
name : api
env :
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"
GMAIL_CLIENT_ID : "271342407743-nibas08fua1itr1utq9qjladbkv3esdm.apps.googleusercontent.com"
GMAIL_CLIENT_SECRET : "WhmxErj-ei6vJXLocNhBbfBF"
GMAIL_REDIRECT_URL : "http://localhost:5100/auth/gmail/oauthcallback"
- script : packages/nylas-sync/app.js
name : sync
env :
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"
- script : packages/nylas-dashboard/app.js
name : dashboard
env :
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"
- script : packages/nylas-message-processor/app.js
name : processor
env :
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"

9
pm2-prod-api.yml Normal file
View file

@ -0,0 +1,9 @@
apps:
- script : packages/nylas-api/app.js
name : api
instances: 0
exec_mode: cluster
- script : packages/nylas-dashboard/app.js
name : dashboard
instances: 1
exec_mode: cluster

9
pm2-prod-sync.yml Normal file
View file

@ -0,0 +1,9 @@
apps:
- script : packages/nylas-sync/app.js
name : sync
instances: 0
exec_mode: fork
- script : packages/nylas-message-processor/app.js
name : processor
instances: 0
exec_mode: fork

View file

@ -1,6 +0,0 @@
const proc = require('child_process');
// TODO: Swtich on env variables
proc.spawn('node', ['packages/nylas-api/app.js'], {
stdio: 'inherit'
})