-
Notifications
You must be signed in to change notification settings - Fork 152
Shell app: log via ws.logger and add username, hostname and pty-term … #4628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…PID in front - When logging inside the Shell app, include the username, the target host and the pty-term PID number in each message, to see which connection is causing the message. Prior to this, it was impossible to see which terminal connected to which host (since there could be multiple simultaneous terminals), and which terminal was causing potential error messages.
apps/shell/app.js
Outdated
setpid: (newpid) => { | ||
msgPrefix = `[User = ${username}; Host = ${host}; PID = ${newpid}]`; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to do this in a more functional style so we don't have msgPrefix
as a variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The challenge is that the PID isn't known when the logger is initialized. The PID will be known once the code gets to this line:
term = pty.spawn(cmd, args, {
//...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One solution is to log the Web socket connection established from user
message with a normal console.log()
, and initialize the ws.logger
once the pty-term
PID is known. I'll push an update.
- Do not initialize the ws.logger until the pty-term PID is known. - Add a few comments.
const host_path_rx = '/ssh/([^\\/\\?]+)([^\\?]+)?(\\?.*)?$'; | ||
const helpers = require('./utils/helpers'); | ||
|
||
const username = os.userInfo().username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder if we need the username at all. Can't it be extracted from the filename?
Not a deal breaker for me, just wondering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't it be extracted from the filename?
I don't know which filename you're referring to?
This is at least a certain way of getting the correct name, i.e., the username which is running the NodeJS process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output file is /var/log/ondemand-nginx/$USER/error.log
- $USER is a variable here that's the username.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's right. We're not using the defaults, so all of our log streams are sent on via a named pipe (FIFO), so we don't have the file names attached to user logs. That is, we override passenger_log_file
.
One might argue that we should solve it via the FIFO, but that would be a lot of work compared to this change. The essential information to get is which username is tied to which Passenger App $PID output
lines. If you wish, we could remove the username logging from the msgPrefix
, and only log it in the server.listen()
callback.
…PID in front
Fixes #4626