#!/bin/csh

#ifndef _BLURB_
#define _BLURB_
#/*
#
#            Coda: an Experimental Distributed File System
#                             Release 3.1
#
#          Copyright (c) 1987-1995 Carnegie Mellon University
#                         All Rights Reserved
#
#Permission  to  use, copy, modify and distribute this software and its
#documentation is hereby granted,  provided  that  both  the  copyright
#notice  and  this  permission  notice  appear  in  all  copies  of the
#software, derivative works or  modified  versions,  and  any  portions
#thereof, and that both notices appear in supporting documentation, and
#that credit is given to Carnegie Mellon University  in  all  documents
#and publicity pertaining to direct or indirect use of this code or its
#derivatives.
#
#CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
#SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
#FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
#DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
#RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
#ANY DERIVATIVE WORK.
#
#Carnegie  Mellon  encourages  users  of  this  software  to return any
#improvements or extensions that  they  make,  and  to  grant  Carnegie
#Mellon the rights to redistribute these changes without encumbrance.
#*/
#
#static char *rcsid = "$Header: restartserver,v 3.2.1.1 95/10/11 10:18:47 raiff Exp $";
#endif /*_BLURB_*/


# Script to restart servers and reboot every so often (3 days)

echo "BEFORE USE EDIT ME TO SET UP DIFFERENTLY FOR EACH SERVER"
exit

# Give the server a chance to shutdown cleanly, then waste it!
# May not want to waste the server since you might lose state...
@ i = 0
while ( -f /vice/srv/pid && $i < 10 )
	/vice/bin/volutil shutdown
	sleep 40
	@ i++
end

if ( -f /vice/srv/pid ) then
	kill -9 `cat /vice/srv/pid`
	rm /vice/srv/pid
endif

# if 3 days have elapsed since last reboot, reboot
set tmp = `date`
set day = $tmp[3]
@ i = $day % 3

# We have 3 primary servers, and set the compare below such that
# only one server reboots each day. (e.g. one server has $i == 0,
# another has $i == 1, and the third has $i == 2.)
if ( $i == 0 ) then
     echo >/vice/srv/STARTFROMBOOT
     /etc/reboot
endif

# restart the fileserver
/vice/bin/startserver &

