Skip to content

Phusion Passenger and logrotation

Hongli Lai edited this page Mar 27, 2014 · 3 revisions

This article describes how to rotate Phusion Passenger's debug logs using a simple pipe tool. The idea is that Phusion Passenger logs to a named pipe, and then another tools forwards the data to a rotated log file.

Initial setup

Save the following script as /usr/local/bin/pipetool: https://gist.github.com/FooBarWidget/7047475

Give it executable permissions:

sudo chmod +x /usr/local/bin/pipetool

Create a FIFO (named pipe) somewhere on the filesystem:

mkfifo $HOME/passenger.pipe

Run the pipetool on this pipe, and have it forward data to a log file:

nohup pipetool $HOME/passenger.log < $HOME/passenger.pipe &

Using Phusion Passenger

Apache/Nginx

Set PassengerDebugLogFile/passenger_log_file to the pipe:

# Apache
PassengerDebugLogFile /home/app/passenger.pipe

# Nginx
passenger_debug_log_file /home/app/pipe;

Standalone

Run Phusion Passenger Standalone with the pipe as log file:

passenger start --log-file $HOME/passenger.pipe

Rotating logs

You can now rotate logs by renaming $HOME/passenger.log, then sending SIGHUP to the pipetool, which tells it to reopen the log file. For example:

mv $HOME/passenger.log $HOME/passenger.log.1
killall -HUP pipetool

You can automate the renaming and sending SIGHUP by using the logrotate tool. Learn more about logrotate here. Here's an example logrotate config file:

/home/app/passenger.log {
    missingok
    notifempty
    compress
    copytruncate
    daily
    rotate 8
    create 0644 nobody nobody
    postrotate
           killall -HUP pipetool
    endscript
}