#!/usr/local/bin/perl5 -w
# 
# Copyright (c) 1998-2000 Carnegie Mellon University.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer. 
#
# 2. 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.
#
# 3. The name "Carnegie Mellon University" must not be used to
#    endorse or promote products derived from this software without
#    prior written permission. For permission or any other legal
#    details, please contact  
#      Office of Technology Transfer
#      Carnegie Mellon University
#      5000 Forbes Avenue
#      Pittsburgh, PA  15213-3890
#      (412) 268-4387, fax: (412) 268-7395
#      tech-transfer@andrew.cmu.edu
#
# 4. Redistributions of any form whatsoever must retain the following
#    acknowledgment:
#    "This product includes software developed by Computing Services
#     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
#
# CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
# FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
# Wrapper for ptclient to restart it if it dies.
#
# $Id: doptclient,v 1.3 2000/05/23 20:56:45 robeson Exp $
#
# NOTE: This script does not create a new pag for ptclient
#       so do NOT run this directly from the rc without
#       creating a new pag first (unless you want all your
#       processes to run authenticated)
#

$coredir = "/usr/tmp/ptloader-cores";

# $ptloader = '/usr/cyrus/bin/ptloader -s -f /.postman.srvtab';
$ptloader = '/usr/cyrus/bin/ptloader -f /.Password';

# $ptscache = "/var/ptclient/ptscache.db";

use Sys::Syslog;

# logging ptclient foo to a separate log level right now
# from standard cyrus (local6)
#
openlog("doptclient", 'cons,pid', "local7");

# try and keep a core file around of the last one to explode.
if (chdir($coredir)) {
  $mvcore = 1;
} else {
  syslog('warning', "couldn't chdir to '$coredir'; core files will " .
	 "be lost to the great void");
  $mvcore = 0;
}

while(1) {
  $st = system($ptloader);

  syslog('crit',
	 "ptloader exited with status $st, will restart in 5 " .
	 "seconds");

  # save the cores!
  if (-f "core") {
    $mvname = "core" . time;
    chmod(0666, "core");
    system "/bin/mv core $mvname" and
      syslog('crit',
	     "couldn't move the core file to a different name before ".
	     "starting a new one");
  }

  system "/usr/local/bin/tokens > /tmp/doptclient.log 2>&1";
  system "/usr/local/bin/klist >> /tmp/doptclient.log 2>&1";

  sleep(5);
}

# $Header: /cvs/src/cyrus/ptclient/doptclient,v 1.3 2000/05/23 20:56:45 robeson Exp $

