ND(1)

NAME
nd - Create simple network daemons

SYNOPSIS
nd [-h] -p port [-a addr] [-v] [-d] [-i] [-l logfile] [-x pidfile] [-u user |-U user] [-k] command...

DESCRIPTION
nd is used to create simple network daemons. nd binds to the specified port and address (default is 0.0.0.0) and listens for incoming connections. When a connection comes in, the specified command is executed in a separate process with stdin and stdout redirected to the connection. The stderr is sent to the stderr of the nd parent process.

OPTIONS

-h  Display help

-p port
    Bind to the specified port (required)

-a addr
    Bind on the specified address (default is 0.0.0.0)

-v  Be verbose, specify multiple times for more verbosity

-d  Daemonize process, nd will continue running after the terminal is closed

-i  Block SIGPIPE for child processes

-l logfile
    Redirect stderr (from server and child processes) to logfile

-x pidfile
    Write PID to pidfile after startup

-u user
    Run child processes as user

-U user
    Run server and child processes as user, server switches users after opening logfile, writing pidfile, and binding to port.

-k  Do not kill child processes when server receives SIGINT or SIGTERM.

command...
    The command to execute (required). Do not quote the entire command, all arguments after the last option become the argv[] for the new command.

EXAMPLES
A simple daemon can be created like this:
$ nd -p 4000 echo hi

With this running, whenever a client connects they will see the string 'hi' printed, and then the connection will close.

  Daemonizing
The following shows how to run nd as a daemon:
$ nd -p 4000 -l log -x pid -d -v echo hi

This will tell nd to daemonize itself. The pid of the daemon will be written to pid and the logging will be redirected to log. The -v parameter increases the verbosity slightly. With one -v parameter, the server startup sequence is logged and an additional log line is written when the server stops.

  Stopping nd
nd can be stopped by sending either SIGINT or SIGTERM to the process. SIGINT is usually ^C at a terminal, whereas SIGTERM is the default sent by kill. Note that these will also stop any running child processes unless -k was passed to nd at startup.

ENVIRONMENT
The following environment variables are set for child processes.

ND_PORT
    The remote port of the client

ND_ADDR
    The remote address of the client

ND_LISTEN_PORT
    The port nd is bound to

ND_LISTEN_ADDR
    The address nd is bound to

ND_VERBOSITY
    The number of -v parameters passed to nd

BUGS
nd does not currently have IPv6 support.

AUTHOR
Andrew Madigan
amadigan@gmail.com