{"id":2721,"date":"2020-12-06T10:04:43","date_gmt":"2020-12-06T18:04:43","guid":{"rendered":"https:\/\/www.cloudinsidr.com\/content\/?p=2721"},"modified":"2022-02-15T04:11:39","modified_gmt":"2022-02-15T12:11:39","slug":"set-up-logrotate-for-postfix","status":"publish","type":"post","link":"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/","title":{"rendered":"Set up logrotate for Postfix"},"content":{"rendered":"<p>Finding errors in a postfix log file is tedious work. The job gets even more complicated if you have to dig through old postfix log files which might no longer be relevant. logrotate comes to the rescue, but only if you configure it correctly.\u00a0 Here is how you can do it on Fedora.<\/p>\n<p><!--more--><\/p>\n<h1>Step 1. Create your logrotate configuration file for Postfix<\/h1>\n<p>Create a new configuration file for Postfix logs in the logrotate directory at:<\/p>\n<pre>\/etc\/logrotate.d<\/pre>\n<p>To create the file, feel free to use any text editor of your choice. We are naming the file<\/p>\n<pre>postfix<\/pre>\n<p>Make sure it contains roughly these directives (adjust as needed):<\/p>\n<pre>\/var\/log\/maillog {\r\nmonthly\r\nrotate 24\r\ncompress\r\ndelaycompress\r\nextension log\r\ncreate 0644 root root\r\n      postrotate\r\n          systemctl restart rsyslog\r\n          systemctl restart postfix\r\n      endscript\r\n}<\/pre>\n<p>Each time Postfix gets to use a new log file, rsyslog will still hang onto the old one. This is why you have to restart it an then restart Postfix using a postrotate script in the file above.<\/p>\n<p>An alternative would be to use<\/p>\n<pre>copytruncate<\/pre>\n<p>It tell logrotate to make a copy of the log file, which will be the rotated, renamed file, and then truncate the log file to a size of zero.<\/p>\n<h1>Step 2. Run logrotate manually<\/h1>\n<p>Execute logrotate on Postfix manually:<\/p>\n<pre>logrotate --force postfix<\/pre>\n<p>If you are using SElinux, this will most likely fail. To tempararily deactivate SElinux:<\/p>\n<pre>setenforce 0<\/pre>\n<h1>Step 3. Set up SElinux labels for logrotate<\/h1>\n<p>Verify permissions using the command:<\/p>\n<pre>ls- laZ<\/pre>\n<p>You will see something like this:<\/p>\n<p>-rw-r&#8211;r&#8211;. 1 root root system_u:object_r:etc_t:s0 130 Oct 14 2019 btmp<br \/>\n-rw-r&#8211;r&#8211;. 1 root root system_u:object_r:etc_t:s0 160 Oct 7 08:27 chrony<br \/>\n-rw-r&#8211;r&#8211;. 1 root root system_u:object_r:etc_t:s0 103 Nov 9 06:58 dnf<br \/>\n-rw-r&#8211;r&#8211;. 1 root root unconfined_u:object_r:etc_t:s0 128 Dec 6 08:47 postfix<\/p>\n<p>Adjust SElinux labels:<\/p>\n<pre>semanage fcontext -a -t etc_t -s system_u \"\/etc\/logrotate.d\/*\"<\/pre>\n<p>Apply new SElinux labels on the logrotate configuration file for Postfix:<\/p>\n<pre>restorecon -RFv postfix<\/pre>\n<p>Now is the time to run audit2allow.<\/p>\n<h1>Step 4. Permit logrotate in SElinux<\/h1>\n<p>With setenforce set to zero, execute logrotate:<\/p>\n<pre>logrotate --force postfix<\/pre>\n<p>and see what happens:<\/p>\n<pre>grep logrotate \/var\/log\/audit\/audit.log | audit2allow -w -a logrotate-module<\/pre>\n<p>Follow the instructions. This usually involves<\/p>\n<pre>semodule -i logrotate-module.pp<\/pre>\n<p>If there is nothing to be done, you will see:<\/p>\n<pre>&lt;no matches&gt;<\/pre>\n<p>in the command line.<\/p>\n<p>Now you should be good to go.<\/p>\n<h1>Step 5. Activate SElinux<\/h1>\n<p>Enable SElinux enforcing:<\/p>\n<pre>setenforce 1<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Finding errors in a postfix log file is tedious work. The job gets even more complicated if you have to dig through old postfix log files which might no longer be relevant. logrotate comes to the rescue, but only if you configure it correctly.\u00a0 Here is how you can do it on Fedora.<\/p>\n","protected":false},"author":1,"featured_media":2796,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[1],"tags":[23,15,70],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Set up logrotate for Postfix - CloudInsidr<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set up logrotate for Postfix - CloudInsidr\" \/>\n<meta property=\"og:description\" content=\"Finding errors in a postfix log file is tedious work. The job gets even more complicated if you have to dig through old postfix log files which might no longer be relevant. logrotate comes to the rescue, but only if you configure it correctly.\u00a0 Here is how you can do it on Fedora.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudInsidr\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-06T18:04:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-15T12:11:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2020\/12\/rawfilm-ihMzQV3lleo-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1350\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/\",\"name\":\"CloudInsidr\",\"description\":\"Cyber security, infotech\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.cloudinsidr.com\/content\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2020\/12\/rawfilm-ihMzQV3lleo-unsplash.jpg\",\"width\":2400,\"height\":1350,\"caption\":\"RawFilm\/Unsplash\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/#webpage\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/\",\"name\":\"Set up logrotate for Postfix - CloudInsidr\",\"isPartOf\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/#primaryimage\"},\"datePublished\":\"2020-12-06T18:04:43+00:00\",\"dateModified\":\"2022-02-15T12:11:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cloudinsidr.com\/content\/set-up-logrotate-for-postfix\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\",\"name\":\"Cloud Insidr\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8b2fa1415b3d573b97d818b8f8f83b7c?s=96&d=mm&r=g\",\"caption\":\"Cloud Insidr\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/2721"}],"collection":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/comments?post=2721"}],"version-history":[{"count":15,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/2721\/revisions"}],"predecessor-version":[{"id":2737,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/2721\/revisions\/2737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media\/2796"}],"wp:attachment":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media?parent=2721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/categories?post=2721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/tags?post=2721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}