Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
By default when you install nginX on Linux a logrotate config file will be created in /etc/logrotate.d/nginx. Sometimes you may see that after a while logs inside of nginX access log is empty and it is logged into the file usually named access.log.1. This error happens when a process cannot close its file handler and has to write into access.log.1.

If you take a look at the config rotation of nginX you will see a part called postrotate that run a command, for nginx it is as below:

postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript


If you run the command between postrotate and endscript it may gives the below error:

invoke-rc.d: action rotate is unknown, but proceeding anyway.
invoke-rc.d: policy-rc.d denied execution of rotate.


Just remove a file related to i-MSCP:

rm /usr/sbin/policy-rc.d

NOTE: Or if you want to be safe rename it to something else.


Now you can run invoke-rc.d command and you should see a result like below:

[ ok ] Re-opening nginx log files: nginx.

Now every log will be directed to its file not it_file_name.log.1, and file handlers are closed safely.

#nginx #policy_rc #invoke_rc #log_rotate #rotate
Log rotatation in Linux is so handy as its name implies, it rotates log files. If you have a look at the /var/log path you can see
some compressed files some files which ends with .1

/var/log/my-app.log {
weekly
rotate 4
compress
delaycompress
missingok
notifempty
create 644 root root
}

The location of log rotation configs is in /etc/logrotate.d/. I have created a file in it with the config above.

Explanation of some parameters:
- weekly: weekly says that you want to Linux to rotate your log files weekly, you can also set daily, monthly, yearly.

- rotate 4: it says that how many rotated files should be kept, here I keep 4 rotated files (one month).

- compress: well you tell me what this parameter does.

- delaycompress: some programs do not close file handlers immediately, here we tell log rotate to delay the compression.

- missingok: don't return error if the log file is missing

OK, the list goes on. Take a look at the manual yourself and see its options.

#linux #logrotate #rotate