Eyck has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for some strightforward example of perl-based server. This would include - init-scripts, logfiles, syslog, possibly monitoring etc...

As I am mostly debian-based, debian source package in some 'goodbye-world' fassion would be best.

There exist Net::Server:: family of modules, but they don't account for starting/stoping/monitoring, there's no logrotate integration, and theye're Net::Server-centered, and noone said server has to be net-based, deamons like cron don't use net.

This is basically Best-Practices question, all the pieces I can easily gather/create myself, but what do people recommend ( for example, it's dead simple to log to syslog, and let the system rotate it's logs, but I think i'd prefer to log to /var/log/daemon/something.log. But then I have to think about logfiles growing, rotating them.. I can do it myself, but is it the best solution?. Another example - /etc/init.d/daemon stop/start. How should one mark that the daemon is running? Pidfile? Should I create it myself, or let some tool like start-stop-daemon manage it?)

  • Comment on Perl-based server integration. Looking for example.

Replies are listed 'Best First'.
Re: Perl-based server integration. Looking for example.
by theorbtwo (Prior) on Apr 02, 2004 at 09:21 UTC

    start-stop-daemon will gladly manage a pidfile for you. Similarly, logrotate will gladly rotate your logs for you. Both are standard, and IIRC required, parts of a debian system. The only thing using them will require on your part is that you install a $SIG{HUP} handler that reopens your logfile. (Otherwise you will continue writing to the old log file after it's been mv'd away.)

      In search of solution I re-stumbled on daemon-tools from djb. It apears they do all the dirty work - starting, stoping, logging and monitoring of services under their control. ( I used to think they are only for starting/stopping ). This would be great solution, but they are aggressively non-free. I think that re-implementation in perl would be short and effective.
Re: Perl-based server integration. Looking for example.
by Abigail-II (Bishop) on Apr 02, 2004 at 09:50 UTC
    for example, it's dead simple to log to syslog, and let the system rotate it's logs, but I think i'd prefer to log to /var/log/daemon/something.log.
    You sound if you think that by using syslog, you can't log to /var/log/daemon/something.log. You can.

    Abigail

      You've got only 'facility' and 'priority' to tell where you're logfiles go. I can use some hand-rolled pattern-matching syslog replacement, maybe syslog-ng to emulate needed behaviour, but I don't think it's a good general solution. In fact, I think it's not.
        There are 7 local facilities, which for most systems is more than enough. Sure, if you intend to run 52 services, who all need to log to a different file, this scheme isn't going to work (although you can always log to a named pipe that does further sorting).

        Abigail

        There is also the ident string that is prepended to every message. Some syslog daemon can filter on that.

        The huge advantage of syslog is that it is standard interface. People can configure logging without worrying about special. The other big advantage is that it does privledge separation and synchronization for logs. Two processes can write to the same log files without worrying about locking or synchronization. A process does not need to have permission to write to the log file since it is isolated by the syslog daemon. Akso, syslog has builtin facilities for remote logging.

        I have heard good things about Log4Perl as a general framework.