Skip to content

Sam/Deployment Fixes - #29

Draft
samholmes wants to merge 6 commits into
masterfrom
sam/deployment-fixes
Draft

Sam/Deployment Fixes#29
samholmes wants to merge 6 commits into
masterfrom
sam/deployment-fixes

Conversation

@samholmes

@samholmes samholmes commented May 20, 2021

Copy link
Copy Markdown
Contributor

This is a draft until successfully testing on a new test droplet

@samholmes
samholmes marked this pull request as draft May 20, 2021 05:49
@samholmes
samholmes force-pushed the sam/deployment-fixes branch from 6817af3 to 5660cf8 Compare May 21, 2021 21:10
samholmes added 2 commits June 1, 2021 15:35
Remove unused config fields and parameterize config with optional ENV.
@samholmes
samholmes force-pushed the sam/deployment-fixes branch from 5660cf8 to b2c00d2 Compare June 1, 2021 22:37
samholmes added 2 commits June 2, 2021 14:49
Errors caught from main that are not handled should be logged and the
process should be exited.
Use pino and pino-pretty for fast and simple logging. Use an appropriate
log level for exceptions.
Comment thread src/config.ts
if (!/^\d+(?:.\d+)$/.test(numStr)) {
throw TypeError('Expected number string')
}
return numStr

@swansontec swansontec Jun 8, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do it as:

const clean = Number(asString(raw))
if (isNaN(clean)) throw new TypeError('Expected number string')
return clean

That way the result is a proper number. When I added @types/express to the repo, this string turned into a type error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From our discussion: no need for the change because type transformation is handled outside of the cleaner in this context (line 39 for httpPort)

Comment thread src/config.ts
Comment on lines +33 to +42
// Couch
couchDbFullpath: asOptional(
asString,
`http://${env.COUCH_USERNAME}:${env.COUCH_PASSWORD}@${env.COUCH_HOSTNAME}:${env.COUCH_PORT}`
),
// App Server
httpPort: asOptional(asNumber, parseInt(env.HTTP_PORT)),
// Info Server
infoServerAddress: asOptional(asString, env.INFO_SERVER_ADDRESS),
infoServerApiKey: asOptional(asString, env.INFO_SERVER_API_KEY),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole section will become a merge conflict when you rebase your PR - I already cleaned this section up.

Comment thread pm2.json
Comment on lines +1 to +10
{
"apps": [
{
"name": "server",
"script": "lib/indexApi.js",
"error_file": "logs/server/error.log",
"out_file": "logs/server/out.log"
}
]
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server should have a real name, and the output should continue going to /var/log:

{
  "apps": [
    {
      "name": "logsServer",
      "script": "./lib/indexApi.js",
      "out_file": "/var/log/logsServer.log"
    }
  ]
}

@swansontec swansontec Jun 8, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on the production box it's /var/log/logsApi.log, but I think logsServer is a better name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we should add this to the readme:

Manage server using pm2

First, install pm2 to run at startup:

yarn global add pm2
pm2 startup # Then do what it says

Next, tell pm2 how to run the server script:

# install:
pm2 start pm2.json
pm2 save

# check status:
pm2 monit
tail -f /var/log/logsServer.log

# manage:
pm2 restart logsServer
pm2 reload logsServer
pm2 stop logsServer

Comment thread .gitignore Outdated
.vscode/

# Logs:
logs/ No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary if the output goes to /var/log

@paullinator
paullinator force-pushed the master branch 2 times, most recently from fa42ba8 to 4e951b7 Compare February 24, 2023 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants