You are looking at historical revision 6952 of this page. It may differ significantly from its current revision.

Introduction

Collection of utility functions for implementing daemons with chicken. At the moment it provides an interface to openlog(3) and syslog(3) and a daemonize function to put the current process in the background.

Examples

Daemonize

To put the process in the background (fork, detach from the controlling terminal, create a new session, etc.) just invoke:

(daemon:ize)

Logging to syslog

You can optionally call daemon:openlog to set the process name and various options. See the openlog(3) manpage for details.

(daemon:openlog "my-daemon" daemon:LOG-PID daemon:LOG-USER)

To write a log message use:

(daemon:syslog daemon:LOG-WARNING "this is the ~a warning" "last")

Authors

Hans Bulfone <jsb@nil.at>

License

Copyright (c) 2007  Hans Bulfone <jsb@nil.at>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of his contributors may
      be used to endorse or promote products derived from this software
      without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Requirements

This egg doesn't depend on other eggs.

Daemonize

(daemon:ize)

This changes the current working directory to /, redirects stdin, stdout and stderr to /dev/null, fork()s and creates a new session.

Setting syslog options

(daemon:openlog ident option facility)

Calls openlog(3) with the given ident (a string identifying the process or #f), option and facility. See openlog(3) for details.

The following constants are available for option: daemon:LOG_CONS, daemon:LOG_NDELAY, daemon:LOG_NOWAIT, daemon:LOG_ODELAY, daemon:LOG_PID. They can be combined using bitwise-ior.

The following constants are available for facility: daemon:LOG_AUTHPRIV, daemon:LOG_CRON, daemon:LOG_DAEMON, daemon:LOG_KERN, daemon:LOG_LOCAL0, daemon:LOG_LOCAL1, daemon:LOG_LOCAL2, daemon:LOG_LOCAL3, daemon:LOG_LOCAL4, daemon:LOG_LOCAL5, daemon:LOG_LOCAL6, daemon:LOG_LOCAL7, daemon:LOG_LPR, daemon:LOG_MAIL, daemon:LOG_NEWS, daemon:LOG_SYSLOG, daemon:LOG_USER, daemon:LOG_UUCP.

As stated by openlog(3), the use of daemon:openlog is optional.

Logging messages to syslog

(daemon:syslog priority message args...)

Calls syslog(3) with the given priority and message (formatted using sprintf, so you can use ~a and ~s in message.

The following constants are available for priority: daemon:LOG_EMERG, daemon:LOG_ALERT, daemon:LOG_CRIT, daemon:LOG_ERR, daemon:LOG_WARNING, daemon:LOG_NOTICE, daemon:LOG_INFO, daemon:LOG_DEBUG.

Version history

1.0