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
Return an error code to the shell if an error occurs when running platform server
#8189
Conversation
When starting the server using `platform server`, errors occuring during startup are not reported in the console. The command exit with a 0 exit code (i.e. "success"), although the server failed to launch. With this change, when an error occurs while initializing the app (like a missing or invalid configuration file): - the error is printed to the console; - the command exit with a "-1" exit code. This allow shell scripts to properly detect the startup failure, and to react to it. Example of error displayed: ``` $ platform server Error: LoadConfig: Error decoding config file=config.json, err=While parsing config: invalid character ':' after top-level value, ``
Thanks @kemenaran for the pull request! Per the CONTRIBUTING.md file displayed when you created this pull request, we need to add you to the list of approved contributors for the Mattermost project. Please help complete the Mattermost contribution license agreement? This is a standard procedure for many open source projects. Your form should be processed within 24 hours and reviewers for your pull request will be able to proceed. Please let us know if you have any questions. We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team. |
Use: "server", | ||
Short: "Run the Mattermost server", | ||
RunE: runServerCmd, | ||
SilenceUsage: true, |
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.
SilentUsage: true
simply avoids the command usage to be printed below the error message when a startup error occurs.
It doesn't affect other behaviors: platform server --help
and platform server --xxx-invalid-option
still display the command usage properly.
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.
Looks good!
@ccbrown great, thanks for accepting this! |
Summary
Currently, if an error occurs when starting the server using
platform server
, the command exit with a 0 exit code (i.e. "success") – although the server failed to launch.This means it is not possible to know whether the server started successfully or not. From the shell point of view, it started successfully and existed very quickly. Additionally, no error message is printed to the console.
With this change, the
platform server
command simply reports its errors tocobra
. When an error occurs while initializing the app (like a missing or invalid configuration file, or missing locales), cobra prints the error to the console, and the shell command exits with a "-1" exit code.This allow shell scripts to properly detect the startup failure, and to react to it.
More importantly, in production, it allows the service launcher (like
init
orsystemd
) to know whether the server launched successfully, or if it needs to try again, how many times (depending on the service configuration), and so on.Ticket Link
n/a
Checklist