When I set up the daemonised webhook system for deploying this website, I didn’t have any logging enabled. This means that the only way I can see if changes to the site had been published is to go to the page that I expect to have changed.

Here, I will show two ways to log the output of the webhook: one easy way, and one more difficult way that offers significant advantages.

Software Link to heading

  • syslog
  • daemon

Note: both are installed as standard on a FreeBSD 14.0 jail

Overall Link to heading

There are two ways to log what the webhook does. The first is to write directly to a file - the ’easy way’. This way is easy to set up because we only need to change one file but is inflexible. The second way is to utilise FreeBSD’s existing syslog infrastructure - the ‘hard way. We have to change a couple of files and restart an extra service, but this way allows for a lot more flexibility in where the log files are saved.

The easy way Link to heading

The easy way to log the output of the webhook daemon is to redirect the output from the daemon directly to a file. We can do this by:

  1. passing -verbose to the webhook command (yes, that is a single dash),
  2. create the output_file variable to use later, and
  3. passing -o ${output_file} to the daemon command.
#!/bin/sh
# PROVIDE: staticsitelistener
# REQUIRE: networking
# KEYWORD:

. /etc/rc.subr

name="staticsitelistener"
rcvar="staticsitelistener_enable"
staticsitelistener_user="root"
staticsitelistener_command="/usr/local/sbin/webhook -hooks /root/hooks.json -verbose" # 1
pidfile="/var/run/${name}.pid"
output_file="/var/log/${name}.log"                                                    # 2
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -r -o ${output_file} ${staticsitelistener_command}"       # 3

load_rc_config $name
: ${staticsitelistener_enable:=no}

run_rc_command "$1"

This creates /var/log/staticsitelistener.log and redirects all output here. The size of the logs depends on the amount of output generated by the commands in the script called by the webhook. For example, this rsync command in script.sh will tell you each file that rsync operates on:

/usr/local/bin/rsync -avr ${REPO}/public/ /usr/local/www/apache24/data/

Obviously, this generates a lot of output. You can do things like remove the -v flag, switch it for a --stats flag, whatever you like.

Easy.

As long as you only want the output to go to a single file.

The hard way Link to heading

The hard way to log the output is to let the daemon command send the output to FreeBSD’s syslogd service. To do this:

  1. keep the -verbose flag for the webhook command,
  2. pass `-S -l -s to the daemon command, and
  3. ensure that /etc/syslog.conf has an entry to match the and .
#!/bin/sh
# PROVIDE: staticsitelistener
# REQUIRE: networking
# KEYWORD:

. /etc/rc.subr

name="staticsitelistener"
rcvar="staticsitelistener_enable"
staticsitelistener_user="root"
staticsitelistener_command="/usr/local/sbin/webhook -hooks /root/hooks.json -verbose" # 1
pidfile="/var/run/${name}.pid"
command="/usr/sbin/daemon"
command_args="-S -l local0 -s info -P ${pidfile} -r ${staticsitelistener_command}"    # 2

load_rc_config $name
: ${staticsitelistener_enable:=no}

run_rc_command "$1"

Add the following line to the end of /etc/syslog.conf (and restart syslogd):

local0.info                                /var/log/staticsitelistener.log            # 3

The and gives you control over how the syslogd service handles the output of the webhook command. In the daemon command I have chosen to use local0 as the facility where I will send logs to and info as the level of logging. In the syslog.conf file I have chosen to direct the output to /var/log/staticlistener.log.

For further information: 14.5. Configuring System Logging of the FreeBSD handbook.

What is the advantage of the ‘hard way’? Link to heading

The only advantage of the ‘hard way’ that I know about at the moment is the ability to send the logs to a remote logging server. Instead of logging to a file, we can send the logs to a server, in this case named remote-logging.server.com.

For further information: 14.5.6. Configuring Remote Logging of the FreeBSD handbook.

local0.info                                @remote-logging.server.com

What have I learned? Link to heading

It is very easy to set up proper logging in FreeBSD using the existing daemon and syslog tools. While the ‘hard way’ requires a couple more steps to get up and running, the ability to use the syslog service to log to remote machines (or even log to multiple places) makes it worthwhile to learn.