unit icon indicating copy to clipboard operation
unit copied to clipboard

application logging to files not working for php wordpress

Open yosefy opened this issue 2 years ago • 15 comments

even though we setup as in doc: https://unit.nginx.org/news/2023/unit-1.30.0-released/#application-logging

still php error log goes to main unit.log file

"testsite": {
		"stderr": "/tmp/unit_app.log",
		"stdout": "/tmp/unit_app_error.log",
		"user": "unit",
		"type": "php 7.4",
		"targets": {
			"direct": {
				"root": "/sites/site/"
			},

			"index": {
				"root": "/sites/site/",
				"script": "index.php"
			}
		}
	}

thanks

# unitd --version
unit version: 1.30.0
configured as ./configure --prefix=/usr --statedir=/var/lib/unit --control=unix:/var/run/unit/control.sock --pid=/var/run/unit/unit.pid --log=/var/log/unit/unit.log --tmpdir=/var/tmp --user=unit --group=unit --tests --openssl --njs --modulesdir=/usr/lib64/unit/modules --libdir=/usr/lib64 --cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

yosefy avatar Aug 02 '23 04:08 yosefy

Couple of quick questions

  1. Is Unit running as a daemon? I.e without the --no-daemon command line argument.
  2. Does the unit user have write access to those log files?

ac000 avatar Aug 02 '23 10:08 ac000

[Service] Type=simple Environment="UNITD_OPTIONS=--log /var/log/unit/unit.log --pid /var/run/unit/unit.pid " ExecStart=/usr/sbin/unitd $UNITD_OPTIONS --no-daemon ExecReload= RuntimeDirectory=unit RuntimeDirectoryMode=0755

i have set it to /tmp/files.log so yep it has rights

On Wed, Aug 2, 2023 at 1:40 PM Andrew Clayton @.***> wrote:

Couple of quick questions

  1. Is Unit running as a daemon? I.e without the --no-daemon command line argument.
  2. Does the unit user have write access to those log files?

— Reply to this email directly, view it on GitHub https://github.com/nginx/unit/issues/915#issuecomment-1661974742, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCXF3NKIDAASTZ4CH2CXH3XTIVA7ANCNFSM6AAAAAA3AVLU6E . You are receiving this because you authored the thread.Message ID: @.***>

yosefy avatar Aug 02 '23 10:08 yosefy

Please remove the --no-daemon option.

The stdout/stderr options only take effect when running as a daemon. (~Yes, our documentation is wrong!~ now fixed).

ac000 avatar Aug 02 '23 10:08 ac000

Closing as NOTABUG. Feel free to re-open if you're still having issues.

ac000 avatar Aug 11 '23 15:08 ac000

it wouldn't work with systemd without --no-daemon option do you have some advice on it may be?

On Fri, Aug 11, 2023 at 6:11 PM Andrew Clayton @.***> wrote:

Closing as NOTABUG. Feel free to re-open if you're still having issues.

— Reply to this email directly, view it on GitHub https://github.com/nginx/unit/issues/915#issuecomment-1674947751, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCXF3IO5KZUPLRZGAXO3QDXUZDSXANCNFSM6AAAAAA3AVLU6E . You are receiving this because you authored the thread.Message ID: @.***>

yosefy avatar Aug 11 '23 15:08 yosefy

Also change the Type from simple to forking

That works for me on Fedora...

(NOTE: You should probably copy /usr/lib/systemd/system/unit.service into /etc/systemd/system/ and edit that one instead which will override the one from the package.)

@thresheek

Any reason not to use a systemd service 'Type' of forking and run unit as a daemon by default?

Otherwise users can't make use of per application logging...

ac000 avatar Aug 11 '23 17:08 ac000

See https://github.com/nginx/unit/pull/212 and https://github.com/nginx/unit/issues/213 for some comments on why we're not using forking. The commit that changed that is https://github.com/nginx/unit/commit/b78ed44f396cbfde7d8353cbc3faaf35c0f4dddf

thresheek avatar Aug 11 '23 18:08 thresheek

clear. but how to split the logs now?

On Fri, Aug 11, 2023 at 9:14 PM Konstantin Pavlov @.***> wrote:

See #212 https://github.com/nginx/unit/pull/212 and #213 https://github.com/nginx/unit/issues/213 for some comments on why we're not using forking. The commit that changed that is b78ed44 https://github.com/nginx/unit/commit/b78ed44f396cbfde7d8353cbc3faaf35c0f4dddf

— Reply to this email directly, view it on GitHub https://github.com/nginx/unit/issues/915#issuecomment-1675185698, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCXF3PYOSXGKFOWXFXS5HLXUZZB3ANCNFSM6AAAAAA3AVLU6E . You are receiving this because you authored the thread.Message ID: @.***>

yosefy avatar Aug 11 '23 19:08 yosefy

@yosefy

I currently see no reason why we shouldn't switch back to forking.

However in the meantime, create the file /etc/systemd/system/unit.service with the following contents

[Unit]
Description=NGINX Unit
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
Environment="UNITD_OPTIONS=--log /var/log/unit/unit.log --pid /var/run/unit/unit.pid"
ExecStart=/usr/sbin/unitd $UNITD_OPTIONS
ExecReload=
RuntimeDirectory=unit
RuntimeDirectoryMode=0755
PIDFile=/var/run/unit/unit.pid

[Install]
WantedBy=multi-user.target

(This will take precedence over the service file from the unit package)

Then do a systemctl restart unit

ac000 avatar Aug 17 '23 12:08 ac000

Re-opening to raise visibility...

ac000 avatar Oct 20 '23 21:10 ac000

Hi guys.

It seems like per application logging obviously doesn't work for dockerized application due to the fact that --no-daemon mode is used.

Does anybody aware of any hack or workaround?

sidz avatar Feb 11 '24 20:02 sidz

Are you able to run Unit as a daemon(7)? I.e without the --no-daemon option. If not, is there some fundamental reason why?

ac000 avatar Feb 12 '24 16:02 ac000

That's how Docker works, Andrew :)

https://github.com/nginx/unit/blob/master/pkg/docker/template.Dockerfile#L89

We expect people to use container logging conventions, but sounds like in this case real log files are required.

@sidz This topic should really be moved to a separate discussion.

lcrilly avatar Feb 12 '24 16:02 lcrilly

I'm okay to open a new issue.

Should I @ac000 ?

sidz avatar Feb 12 '24 17:02 sidz

@sidz yes please do. I am happy to link it to this issue but we should open another one to work on the per application logging OR better to say application logging in Docker using Unit.

There are some fundamental differences between the no-daemon and daemon mode. Will use the new issue to elaborate on those and share potential work arounds and solutions

tippexs avatar Feb 12 '24 18:02 tippexs