Skip to content
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

Bug fixes: Find mime.types file location and automatically find Openresty path #90

Merged
merged 5 commits into from
Jun 21, 2024

Conversation

davidjwbbc
Copy link
Contributor

This PR includes some minor bug fixes for #83 and #89.

Find mime.types file (#83):

  • The code will now look in known locations first for the Openresty mime.types file and then for the default nginx mime.types file and use the found mime.types in the nginx configuration.
    • Currently checks /usr/local/openresty/nginx/conf/mime.types and /etc/nginx/mime.types.
    • These paths work for RedHat and Ubuntu linux flavours, if we find other distributions with different paths these can be added later.
  • The modules path for nginx is only included in the nginx configuration if it exists at the known location.
    • Currently this checks for /usr/share/nginx/modules being present (Openresty automatically includes its own modules so doesn't need this extra include in the nginx configuration).

Automatically find Openresty path (#89):

  • As the python app starts it looks for known Openresty nginx/sbin directories and if found prepends it to the PATH environment variable for the AS environment.
    • Currently checks for /usr/local/openresty/nginx/sbin.
    • This path works for RedHat and Ubuntu linux flavours, if we find other distributions with different paths these can be added later.

Fixes #83
Fixes #89

Copy link
Contributor

@rjb1000 rjb1000 left a comment

Choose a reason for hiding this comment

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

Changes look good, @davidjwbbc .

In addition, would it be possible to print out some informative lines to the console to confirm which paths have been detected for the binary and modules? This is then valuable feedback for the user to understand what's going on when there are multiple instances installed at different paths.

@davidjwbbc
Copy link
Contributor Author

Changes look good, @davidjwbbc .

In addition, would it be possible to print out some informative lines to the console to confirm which paths have been detected for the binary and modules? This is then valuable feedback for the user to understand what's going on when there are multiple instances installed at different paths.

Added log output to log INFO messages about the path and mime.types file location. For example:

INFO:rt-5gms-as:Found OpenResty path at /usr/local/openresty/nginx/sbin, will try this path first for nginx executable location
INFO:NginxWebProxy:Found mime.types file at /usr/local/openresty/nginx/conf/mime.types
[2024-06-11 11:52:21 +0100] [10512] [INFO] Running on http://127.0.0.1:7777 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:7777 (CTRL + C to quit)

@davidjwbbc davidjwbbc requested a review from rjb1000 June 11, 2024 10:58
Copy link
Contributor

@rjb1000 rjb1000 left a comment

Choose a reason for hiding this comment

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

Thanks for the extra informative lines.

@jordijoangimenez
Copy link
Contributor

Hi David, I've reinstalled from your branch and I keep getting the lua_package_path error:

fivegmag@5GMAG-NUC:~/rt-5gms-application-server$ sudo 5gms-application-server
INFO:NginxWebProxy:Found mime.types file at /etc/nginx/mime.types
[2024-06-14 11:22:04 +0200] [3394050] [INFO] Running on http://127.0.0.1:7777 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:7777 (CTRL + C to quit)
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] unknown directive "lua_package_path" in /tmp/rt_5gms_as.conf:48

INFO:rt-5gms-as:Web proxy process exited, has been restarted
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] unknown directive "lua_package_path" in /tmp/rt_5gms_as.conf:48

INFO:rt-5gms-as:Web proxy process exited, has been restarted
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] unknown directive "lua_package_path" in /tmp/rt_5gms_as.conf:48

INFO:rt-5gms-as:Web proxy process exited, has been restarted
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] unknown directive "lua_package_path" in /tmp/rt_5gms_as.conf:48

INFO:rt-5gms-as:Web proxy process exited, has been restarted
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] unknown directive "lua_package_path" in /tmp/rt_5gms_as.conf:48

INFO:rt-5gms-as:Web proxy process exited, has been restarted
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] unknown directive "lua_package_path" in /tmp/rt_5gms_as.conf:48

ERROR:rt-5gms-as:nginx web proxy restarting too quickly, aborting...
``

@jordijoangimenez
Copy link
Contributor

I believe it is useful that when doing a clean installation I make sure Openresty is installed... IGNORE the above. It works, now trying to disable nginx:

fivegmag@5GMAG-NUC:~/rt-5gms-application-server$ sudo 5gms-application-server
INFO:rt-5gms-as:Found OpenResty path at /usr/local/openresty/nginx/sbin, will try this path first for nginx executable location
INFO:NginxWebProxy:Found mime.types file at /usr/local/openresty/nginx/conf/mime.types
[2024-06-14 11:33:51 +0200] [3412561] [INFO] Running on http://127.0.0.1:7777 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:7777 (CTRL + C to quit)
INFO:NginxWebProxy:
ERROR:NginxWebProxy:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
``

@jordijoangimenez
Copy link
Contributor

@davidjwbbc, after testing, I think we are good to go. My recollection on the instructions will be that the export PATH command is no longer needed and that systemctl disable --now nginx.service openresty.service is still needed before execuding 5gms-application-server to avoid active instances

@jordijoangimenez
Copy link
Contributor

jordijoangimenez commented Jun 14, 2024

I would suggest to move the installation of Openresty upwards and make it a more explicit step. I would integrate the paragraph

Please note that the application server requires a suitable web proxy server to be installed. At present the only web proxy server that the application server can use is Openresty. This means you should install the openresty package on your distribution, instruction to do so can be found on the Openresty website for linux distributions and Microsoft Windows. The Openresty version of nginx should also be the first version on the system path.

within "Install dependencies" rather than under running (you will try to execute 5gms-application-server but the paragraph telling you to install openresty just comes next).

@davidjwbbc
Copy link
Contributor Author

Ok, I've improved the OpenResty executable finding by verifying the nginx executable found was compiled to handle LUA.

If no suitable executable is found then the following error is displayed:

ERROR:rt-5gms-as:Please install at least one of: openresty

"openresty" being the only web proxy module currently implemented (renamed from "nginx" to avoid confusion). If more web proxy modules are added and none find their executables are found then they are all listed here.

If the openresty web proxy module found a suitable nginx executable then it is reported:

INFO:OpenRestyWebProxy:Found nginx executable supporting LUA at /usr/local/openresty/nginx/sbin/nginx

Note: I'm no longer adding the known openresty path to the PATH environment variable, instead the openresty web proxy module provides the known openresty path as an extra path to try to the function which finds executables. This allows the AS to be run with an alternative OpenResty in the PATH to use that one instead.

Copy link
Contributor

@rjb1000 rjb1000 left a comment

Choose a reason for hiding this comment

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

I couldn't spot an error message when no valid OpenResty installation can be found.

Could you point it out please?

@jordijoangimenez
Copy link
Contributor

@davidjwbbc same as Richard. I cannot find the line in the app.py file of the PR. I see the correction if I go directly to your branch though. Somehow the PR is not up to date?

@jordijoangimenez
Copy link
Contributor

sorry, I see it now. Line 261 but somehow the change is not displayed by GitHub under "Files changed". I think this is good to go.

@davidjwbbc davidjwbbc merged commit 02d4745 into 5G-MAG:development Jun 21, 2024
@dsilhavy dsilhavy added this to the Version 1.2.3 milestone Jun 24, 2024
@davidjwbbc davidjwbbc deleted the bug-fix/mime-types-location branch June 28, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating PATH for launching Openresty Development branch: Missing Nginx mime.types after clean installation
4 participants