Sometimes your EB httpd logs just get too big

Amazon’s Elastic Beanstalk — sure, it’s cool and useful, but, man, the .ebextensions/ config files can be quite a pain. But, back on subject!

Step one, log rotation.

Amazon’s EB instances come setup with logrotate, which is handy. I decided we didn’t need so many archived apache logs, especially with our HD capacity issues, and replaced the config file with another set to only keep one previous file.

To do this, I created a file called logrotate.txt:

/var/log/httpd/*log {
    rotate 1
        /etc/init.d/httpd graceful > /dev/null 2>/dev/null || true

And added a line to the .ebextensions/ config which replaces the existing file with it.

      mv /var/app/current/http_logrotate.txt /etc/logrotate.d/httpd

I SSHed in.

Everything looked fine — but under the pressure of standardized testing, it fell apart faster than a coddled kindergartner.

[ec2-user@host]$ sudo /usr/sbin/logrotate -d -f  /etc/logrotate.d/httpd
reading config file /etc/logrotate.d/httpd
reading config info for /var/log/httpd/*log
error: /etc/logrotate.d/httpd:1 lines must begin with a keyword or a filename (possibly in double quotes)
error: /etc/logrotate.d/httpd:2 unexpected text
error: /etc/logrotate.d/httpd:3 unexpected text
error: /etc/logrotate.d/httpd:4 unexpected text
error: /etc/logrotate.d/httpd:5 unexpected text
error: /etc/logrotate.d/httpd:6 unexpected text
error: /etc/logrotate.d/httpd:7 unexpected text
error: /etc/logrotate.d/httpd:prerotate or postrotate without endscript

The problem was that there were DOS EOL characters instead of the UNIX EOL character. To fix, I ran the logrotate config through dos2unix.

[ec2-user@host]$ whereis dos2unix
dos2unix: /usr/bin/dos2unix /usr/share/man/man1/dos2unix.1.gz
[ec2-user@host]$ sudo dos2unix /etc/logrotate.d/httpd
dos2unix: converting file /etc/logrotate.d/httpd to UNIX format ...

After that I ran the test again, and it completed without error.

Long story short, if you’re replacing the logrotate config file for Elastic Beanstalk, make sure your editor is set to use the Unix EOL character.