1. daemon-tools
    1. Introduction
    2. Examples
      1. Daemonize
      2. Logging to syslog
    3. Authors
    4. License
    5. Requirements
    6. Daemonize
    7. Setting syslog options
    8. Logging messages to syslog
    9. Version history
      1. 1.0

daemon-tools

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