Previous Next Contents

6. Syslog

6.1 Problem

Syslog is the system logging utility commonly used on UNIX systems. Syslog is a daemon that opens a special file called a FIFO. A FIFO is a special file that is like a pipe. Anything that is written to the write side will come out the read side. The syslog daemon waits for data from the read side. There are C functions that write to the write side. If you write your program with these C functions your output will go to syslog. Remember that we have used a chroot environment and the FIFO /dev/log is not in the virtual environment. That means all the virtual environments will not log to syslog. We cannot simply copy the file since the programs use /dev/log instead of the new one we would create.

Beware that certain versions of syslog use a udp socket instead of the FIFO. However, this is usually not the case.

6.2 Solution

Syslog can look to a different FIFO if you tell it on the command line so run syslog with the argument:

syslog -p /virtual/log

Then link /dev/log to /virtual/log by (Note it is a SYMLINK):

ln -sf /virtual/log /dev/log

Then link all the /dev/log copies to this file by running (Note it is a hard link and NOT a symlink):

ln /virtual/log /virtual/domain.com/dev/log 

The virtfs script above already does this. Since /virtual is one contiguous disk and the /dev/log's are linked they have the same inode number and point to the same data. The chroot cannot stop this so all your virtual /dev/log's will now function. Note that all the messages from all the environments will be logged in one place. However, you can write separate programs to filter out the data. If you do not want to write a program and require separate log files you can use a separate syslog for each virtual filesystem by running:

syslog -p /virtual/domain1.com/dev/log 
syslog -p /virtual/domain2.com/dev/log 

However that wastes process id's so I do not recommend it. This version of the syslog.init file relinks the /dev/log's each time you start it in case they have been improperly set up. Here is a modified syslog.init file:

#!/bin/sh

# Source function library.
. /etc/rc.d/init.d/functions

case "$1" in
  start)
        echo -n "Starting dev log: "
        ln -sf /virtual/log /dev/log
        echo done
        echo -n "Starting system loggers: "
        daemon syslogd -p /virtual/log
        daemon klogd
        echo
        echo -n "Starting virtual dev log: "
        for i in /virtual/*
        do
                if [ ! -d "$i" ]
                then
                        continue
                fi
                if [ "$i" = "/virtual/lost+found" ]
                then
                        continue
                fi
                ln -f /virtual/log $i/dev/log
                echo -n "."
        done
        echo " done"
        touch /var/lock/subsys/syslog
        ;;
  stop)
        echo -n "Shutting down system loggers: "
        killproc syslogd
        killproc klogd
        echo
        rm -f /var/lock/subsys/syslog
        ;;
  *)
        echo "Usage: syslog {start|stop}"
        exit 1
esac

exit 0

Note that you do not have to put all the virtual filesystems on one disk. However, you will have to run a different syslog for each partition that has virtual filesystems on it.


Previous Next Contents