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

[MacOS] FPM crashes with: unknown entry 'systemd_interval' #16

Closed
kevinpapst opened this issue Aug 25, 2020 · 12 comments
Closed

[MacOS] FPM crashes with: unknown entry 'systemd_interval' #16

kevinpapst opened this issue Aug 25, 2020 · 12 comments

Comments

@kevinpapst
Copy link
Contributor

kevinpapst commented Aug 25, 2020

Starting for the first time without changing anything manually:

~/Downloads/rymfony.macOS-latest server:start
INFO - Starting PHP...
INFO - Using php-fpm
INFO - Running php-fpm with PID 62448
[25-Aug-2020 18:53:50] ERROR: [/Users/kevin/.rymfony/fpm-conf.ini:12] unknown entry 'systemd_interval'
[25-Aug-2020 18:53:50] ERROR: failed to load configuration file '/Users/kevin/.rymfony/fpm-conf.ini'
[25-Aug-2020 18:53:50] ERROR: FPM initialization failed
thread 'main' panicked at 'PHP server exited with exit code: 78', src/php/php_server.rs:56:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

cat /Users/kevin/.rymfony/fpm-conf.ini

[global]
log_level = notice

; Output to stderr
error_log = /dev/fd/2

; This should be managed by Rymfony.
; This gives the advantage of keeping control over the process,
; and possibly retrieve logs too (since logs can be piped with fpm's stderr with current config)
daemonize = no
systemd_interval = 0

[www]
; Only works if launched as a root user
; TODO: check if this can be usable anyway
;user = 502
;group = 20

listen = 127.0.0.1:65535
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /_fpm-status

; Output to stderr
php_admin_value[error_log] = /dev/fd/2
php_admin_flag[log_errors] = on

; Redirect stdout and stderr to main error log instead of /dev/null (default config for fastcgi)
catch_workers_output = yes

; This allows injecting custom env vars like with "APP_ENV=dev rymfony serve"
clear_env = no

And:

~/Downloads/rymfony.macOS-latest php:list
┌─────────────────────────┐
| Binary path             |
├─────────────────────────┤
| /usr/local/bin/php      |
| /usr/local/sbin/php-fpm |
| /usr/local/bin/php      |
| /usr/bin/php            |
| /usr/sbin/php-fpm       |
└─────────────────────────┘

As https://www.php.net/manual/en/install.fpm.configuration.php says:

When FPM is build with systemd integration, specify the interval, in second, between health report notification to systemd. Set to 0 to disable. Default value: 10.

So it seems my FPM is not compiled with support for systemd. The config line is not simply ignored but FPM crashes.
Also mentioned here.

Unfortunately I cannot change the auto generated fpm config, because it will be overwritten upon the next start.
When changing the config and removing write permissions rymfony crashes, as it can't write the config.

My complete Dev setup is installed via Brew, so I assume this error will happen to most users with a current PHP 7.4.8 setup on macOS Catalina 10.15.6 (19G2021).

Anything I can do to help debugging/fixing this issue?
All I could find to check for systemd support is the compile flag --with-fpm-systemd that activates it.
Therefor php -i|grep with-fpm-systemd shows nothing here.

@kevinpapst
Copy link
Contributor Author

A self-compiled version of the 'php-versions' branch starts the server without problems:

~/Development/rymfony/target/release/rymfony server:start
INFO - Starting PHP...
INFO - Running native PHP server with PID 65263
[Tue Aug 25 19:32:22 2020] PHP 7.4.8 Development Server (http://127.0.0.1:65535) started
INFO - PHP server is ready
INFO - PHP started with module CLI
INFO - Starting HTTP server...
INFO - Configured document root: /Users/kevin/public/
INFO - PHP entrypoint file: /Users/kevin/public/index.php
INFO - Server listening to http://127.0.0.1:8000

But as soon as I open a URL I run into #11

I don't know if that is intended, but the php-versions branch doesn't create the /Users/kevin/.rymfony/fpm-conf.ini file at all. I removed it and it doesn't reappear.

@Pierstoval
Copy link
Member

Thanks for reporting this issue! Once the php-versions branch is complete, I will dig into all the remaining issues with the server, and I'll change the strategy used to generate the fpm-conf.ini file.

My goal with this is to create the file if it doesn't exist, and if it does, just let it as-is, so the user can freely update it in case of errors.

Something that might also be interesting to add is a check of the unknown entry 'systemd_interval' error, like removing the entry in the fpm config file and retrying to start the server, or maybe just an informational message to the user, not sure yet 😃

@kevinpapst
Copy link
Contributor Author

If you work on that, give me a ping and I will happily join the testing crew.

Maybe it is simpler to add a platform check around the systemd_interval line and only activate it for platforms that are likely to support it and for others only add it commented ;systemd_interval = 0.

MacOS for example has AFAIK no support for it, as it uses launchd and not systemd.

@Pierstoval
Copy link
Member

Maybe it is simpler to add a platform check around the systemd_interval line and only activate it for platforms that are likely to support it and for others only add it commented ;systemd_interval = 0.

Yep, I don't know how to make such check for now, but this is indeed a good solution 👍

@kevinpapst
Copy link
Contributor Author

kevinpapst commented Aug 26, 2020

My naive idea was harcoding it, so something like

const FPM_DEFAULT_CONFIG: &str = "
[global]
...snip...
daemonize = no
{{ systemd_interval }}

[www]
...snip...

and then defining this replacer with (pseudo code, as I am not sure if that is the correct way to express it in Rust)

#[cfg(target_os = "windows")]
const FPM_SYSTEMD_SUPPORT:  &str = "; systemd_interval = 0";
#[cfg(target_os = "linux")]
const FPM_SYSTEMD_SUPPORT:  &str = "systemd_interval = 0";
#[cfg(target_os = "macos")]
const FPM_SYSTEMD_SUPPORT:  &str = "; systemd_interval = 0";

and finally

let config = FPM_DEFAULT_CONFIG
        .replace("{{ uid }}", uid_str.as_str())
        .replace("{{ gid }}", gid_str.as_str())
        .replace("{{ port }}", port.as_str())
        .replace("{{ log_level }}", FPM_DEFAULT_LOG_LEVEL)
        .replace("{{ systemd }}", FPM_SYSTEMD_SUPPORT)
;

@Pierstoval
Copy link
Member

That's a good idea, however I'm not sure every linux distribution has systemd support either 😕

@kevinpapst
Copy link
Contributor Author

Well, improving step-by-step then ... at least Mac would be fixed with that 🙈

Do you want me to give it a try in a PR ?

@Pierstoval
Copy link
Member

Seems like it's fixed, isn't it? 😉

@kevinpapst
Copy link
Contributor Author

Not really, none of the PRs was about that one. The systemd_interval code is still in server_fpm.rs, so I think we should somehow take care of it.

It doesn't happen currently on my local machine due to the fact that CLI is always used, which I believe is because of https://github.com/Pierstoval/rymfony/pull/14/files#diff-530e580854f8084c7a22088c99e74e7eR24

$ target/release/rymfony server:start

INFO - Starting PHP...
INFO - Running native PHP server with PID 31627
[Thu Aug 27 14:55:36 2020] PHP 7.4.9 Development Server (http://127.0.0.1:65535) started
INFO - PHP server is ready
INFO - PHP started with module CLI
INFO - Starting HTTP server...
INFO - Configured document root: /Users/kevin/Development/rymfony
INFO - PHP entrypoint file: /Users/kevin/Development/rymfony/index.php
INFO - Server listening to http://127.0.0.1:8000

While it should use FPM:

$ symfony serve --port=8010

[Web Server/PHP ] Aug 27 15:21:23 |INFO | PHP    listening path="/usr/local/Cellar/php/7.4.9/sbin/php-fpm" php="7.4.9" port=54142
[Web Server/PHP ] Aug 27 15:21:23 |DEBUG| PHP    started
[Web Server/PHP ] Aug 27 15:21:23 |INFO | PHP    fpm is running, pid 32164
[Web Server/PHP ] Aug 27 15:21:23 |INFO | PHP    ready to handle connections

So if you help me tackle that one, then I would look into systemd_interval issue.

@Pierstoval
Copy link
Member

Oh, yeah, I didn't read the initial message, I just read your last one about submitting a PR 🤣

Sorry, I'll dig into this later, unless you want to try it out 😄

As said above, we should first try to find a good way to determine whether systemd_interval is available or not before launching the server. Maybe with some INI-based command, like php -r "echo ini_get(...);" ? I never tried such check 😕

@kevinpapst
Copy link
Contributor Author

unless you want to try it out

Done: #20 and #21

@kevinpapst
Copy link
Contributor Author

Fixed, closing

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

No branches or pull requests

2 participants