diff --git a/Dockerfile b/Dockerfile index be4deaf43..831aafc2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Procfile b/Procfile deleted file mode 100644 index bc443adf9..000000000 --- a/Procfile +++ /dev/null @@ -1,2 +0,0 @@ -web: node packages/nylas-api/app.js -worker: node packages/nylas-sync/app.js diff --git a/Procfile.dev b/Procfile.dev deleted file mode 100644 index 03ec16455..000000000 --- a/Procfile.dev +++ /dev/null @@ -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 diff --git a/package.json b/package.json index 4b3ab2a8b..ad44dd6d0 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/packages/nylas-core/database-connector.js b/packages/nylas-core/database-connector.js index d7459458a..b37fe81cf 100644 --- a/packages/nylas-core/database-connector.js +++ b/packages/nylas-core/database-connector.js @@ -43,7 +43,7 @@ class DatabaseConnector { }); } - return Sequelize(dbname, '', '', { + return new Sequelize(dbname, '', '', { storage: path.join(STORAGE_DIR, `${dbname}.sqlite`), dialect: "sqlite", logging: false, diff --git a/pm2-dev.yml b/pm2-dev.yml new file mode 100644 index 000000000..9c3d520ce --- /dev/null +++ b/pm2-dev.yml @@ -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" diff --git a/pm2-prod-api.yml b/pm2-prod-api.yml new file mode 100644 index 000000000..d9bc01862 --- /dev/null +++ b/pm2-prod-api.yml @@ -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 diff --git a/pm2-prod-sync.yml b/pm2-prod-sync.yml new file mode 100644 index 000000000..1bcb4cfb4 --- /dev/null +++ b/pm2-prod-sync.yml @@ -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 diff --git a/start-aws.js b/start-aws.js deleted file mode 100644 index b08e1d0f0..000000000 --- a/start-aws.js +++ /dev/null @@ -1,6 +0,0 @@ -const proc = require('child_process'); - -// TODO: Swtich on env variables -proc.spawn('node', ['packages/nylas-api/app.js'], { - stdio: 'inherit' -})