I have a problem with logging. With my configuration below, I have to perform rsyslog restart if I want to have my application log file in /var/log. Also, I have to restart rsyslog it in case of log rotate. What is the proper configuration of rsyslog and systemd service to avoid rsyslog restart?
My configuration: /etc/rsyslog.d/myapp.conf
if $programname == 'myapp' then {
/var/log/myapp/myapp.log
stop
}
/etc/systemd/system/myapp.service
[Unit]
Description=myapp
[Service]
User=myapp
ExecStart=/usr/bin/myapp
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=myapp
[Install]
WantedBy=multi-user.target
/etc/logrotate.d/myapp.conf
/var/log/myapp/myapp.log {
rotate 7
daily
size 100MB
compress
missingok
notifempty
postrotate
sudo systemctl restart rsyslog.service
endscript
}
copytruncate
in logrotate unit configuration and/orcreate
to create an empty file after rotation?