I have a service manifest on Solaris (Smart OS actually) and I would like to periodically clean its log files either automatically or manually without shutting down the server.
My log is here:
/var/svc/log/site-myapp-joyent-smartos-node-service-manifest-1:default.log
Is there a way to either clean this, limit its size, or move it?
Answer
I would use logadm to rotate the logs for you. On the latest base image (13.1.0) there is a default logadm entry for rotating SMF logs (check the /etc/logadm.conf file):
smf_logs -C 3 -c -s 1m /var/svc/log/*.log
That entry will rotate the SMF service logs whenever they hit 1m in size (-s 1m), only keep 3 versions after each rotation (-C 3) and rotate the log by copying the original log file then truncating it to zero (-c). The nice thing about the above is that it’s a pattern based logadm definition, so you can run it manually with:
logadm smf_logs
There is a crontab entry (under the root user) on the base 13.1.0 image to run logadm once per hour.
10 * * * * /usr/sbin/logadm
An hourly cron is good for size based rotation and helps keep things in check if some logs tend to grow pretty quickly.
Attribution
Source : Link , Question Author : Justin Cloud , Answer Author : chorrell