#!/bin/sh -u
#
# locksetup - set up a server for running p4 monitor show against,
# which is used by locks.pl
#
# Dan Bloch - dbloch@google.com
# Copyright (C) 2006 Google Inc.
#
#
# Directory where main server is running.
#
P4_MAIN_ROOT=/p4/root
#
# Directory where p4-monitor-show server will run (will be created)
#
P4_MON_ROOT=/p4/mon-root
#
# p4d executable. Default is to search $PATH
#
P4D=`type -p p4d`
#----------------------------------------------------------------------
monitor_db=$P4_MAIN_ROOT/db.monitor
if [ ! -r $monitor_db ]
then
echo "file not found: $monitor_db"
exit 1
fi
if [ -z "$P4D" ]
then
echo "p4d not on path or specified in script"
exit 1
fi
mkdir -p $P4_MON_ROOT
cd $P4_MON_ROOT
cat > README <<END
This directory is to run a p4d server which shares db.monitor with the
real server, but has all the other db files separate (and empty).
This is so that "p4 monitor show" will always work on this server, even
when the main server is hung.
"p4d" is called "p_4_d" so pgrep, etc. don't match it.
END
cp $P4D p_4_d
ln -s $monitor_db .
echo ./p_4_d -d -q -L errorlog -v server=1 -p 1999 > start
echo pkill p_4_d > stop
chmod +x start stop
unset P4PORT P4CONFIG
./start
export P4PORT=localhost:1999
p4 counter -f monitor 1
./stop
./start
# Set protections so no one on other machines can do anything except
# p4 monitor show, and on this machine you can do anything (mainly
# p4 monitor show -l). The third lets you refer to the server as
# localhost:1666
ip_addr=$(hostname -i)
cat <<END | p4 protect -i
Protections:
list user p4 * //...
super user p4 $ip_addr //...
super user p4 127.0.0.1 //...
END
echo "server created for 'p4 monitor show'. To use:
p4 -u p4 -p localhost:1999 monitor show
"
exit 0