Skip to content

Commit

Permalink
Add cron running and start script
Browse files Browse the repository at this point in the history
This commit adds a new property to the instance config which allows a
cron schedule to be specified for the script.

It also moves the encryption key under which user emails are stored into
something that is pasted in when the app starts.

- Add cron_restart property to ecosystem.config.js.template
- Remove KEY property from app environment in
ecosystem.config.js.template
- Create start.sh, a script that accepts arguments containing the
instance name and environment, then prompts the user to paste the
encryption key, then starts the app, passing the key into the app's
environment.
  • Loading branch information
Andrew Isherwood committed Nov 4, 2020
1 parent 74aeb12 commit 907812b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ecosystem.config.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module.exports = {
name: '<instance_name>-email',
script: 'index.js',
instances: 1,
autorestart: true,
watch: true,
autorestart: false,
watch: false,
cron_restart: "*/15 * * * *",
max_memory_restart: '1G',
env: {
NODE_ENV: 'development',
PGUSER: '<db_user>',
PGPASSWORD: '<db_password>',
SCHEMA: '<db_user>',
KEY: '<encryption_key_must_match_ems-api>',
BASE_URL: '<base_url_of_frontend>'
EMAIL_FROM: '<email_from_address>',
// See https://nodemailer.com/smtp/ for all options
Expand All @@ -26,7 +26,6 @@ module.exports = {
PGUSER: '<db_user>',
PGPASSWORD: '<db_password>',
SCHEMA: '<db_user>',
KEY: '<encryption_key_must_match_ems-api>',
BASE_URL: '<base_url_of_frontend>'
EMAIL_FROM: '<email_from_address>',
// See https://nodemailer.com/smtp/ for all options
Expand Down
35 changes: 35 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

while getopts ":i:e:" opt; do
case $opt in
i) instance="$OPTARG"
;;
e) env="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
exit
;;
esac
done

INST_LEN=$(echo -n $instance | wc -m)
ENV_LEN=$(echo -n $env | wc -m)

if [[ $INST_LEN == 0 || $ENV_LEN == 0 ]]
then
echo "Invalid parameters passed, must pass -i <instance_name> -e <environment>"
exit
fi

echo Paste key, then press enter

read key

KEY_LEN=$(echo -n $key | wc -m)

if [[ $KEY_LEN = 0 ]]
then
echo "Invalid key passed"
fi

KEY=$key pm2 start --only $instance --env $env

0 comments on commit 907812b

Please sign in to comment.