As a general rule, you never need more than a single of awk, sed, grep, cut in the same pipeline. Also, xargs (on Linux) would generate a silly error-message (which cron will dutifully e-mail to you), if no matching open files were found. The improved (and less prone to race-conditions) expression for the same would be:
But, you only need lsof if you insist on sharedscripts (which is not in there in the default file installed by the upstart package).
If you do NOT add the sharedscripts-verb, you can bypass the entire lsof part, because the full path of the log being rotated will be passed to the postrotate-script as the first argument:
postrotate service=${1##*/} service=${service%.log*}
service $service restart
endscript
You can also insert special handling for some of the services easier this way, for example:
> awk | sed
As a general rule, you never need more than a single of awk, sed, grep, cut in the same pipeline. Also, xargs (on Linux) would generate a silly error-message (which cron will dutifully e-mail to you), if no matching open files were found. The improved (and less prone to race-conditions) expression for the same would be:
postrotate
$9 ~ /^\/var\ /log\/upstart\ /.*\.log. +/ {
service = gensub( "^.*/(. *).log. *", "\\1", $9);
system( "service " service " restart")
lsof | awk '
}
'
endscript
But, you only need lsof if you insist on sharedscripts (which is not in there in the default file installed by the upstart package).
If you do NOT add the sharedscripts-verb, you can bypass the entire lsof part, because the full path of the log being rotated will be passed to the postrotate-script as the first argument:
postrotate
service= ${1##*/ }
service= ${service% .log*}
service $service restart
endscript
You can also insert special handling for some of the services easier this way, for example:
case $service in
exit 0
fpm*)
;;
.....
esac