0

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?

quanta
  • 50,327
  • 19
  • 152
  • 213
Justin Cloud
  • 103
  • 4

3 Answers3

2

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.

chorrell
  • 86
  • 4
  • Thanks! Awesome detail. This is exactly what I needed :) Can you clarify the "10 * * * * /usr/sbin/logadm" How do I check what the cronjob is set at (frequency) and how do I change it? – Justin Cloud May 16 '13 at 06:10
  • That will run the /usr/sbin/logadm command every hour, at 10 minutes past the hour. `man crontab` and `man cron` – chorrell May 18 '13 at 00:25
0

You can do this by writing a script then create a cron job to run the script periodically.

meda
  • 103
  • 5
-2

any open file can be zeroised with >file.name

deleteing the open file will not free the filestore