3d4f6cbbbdc81427fc938eb30777ab0d3f8a69de
[clinton/scripts.git] / run-in-pagsh
1 #!/usr/bin/pagsh.openafs
2 # -*- Shell-Script -*-
3 #
4 # Usage:
5 #
6 # run-in-pagsh name command [arguments] ...
7 #
8 # The first argument, `name', is a short description of the program to
9 # call, without any spaces. It is used for making a PID file, which
10 # ensures that only one instance of your command is running.
11 #
12 # Example:
13 #
14 # run-in-pagsh interchange ~/interchange/bin/interchange
15 #
16 # Make sure that the ~/.run directory exists and is writable.
17 # See http://wiki2.hcoop.net/MemberManual/RunningUnattendedCommands
18 # for instructions on how to accomplish this.
19
20 # Sanity checks
21 if test -z "$2"; then
22 echo "Error: not enough arguments."
23 echo "Usage: run-in-pagsh name command [arguments] ..."
24 exit 1
25 elif test ! -d "$HOME/.run"; then
26 echo "Error: the ~/.run directory must exist before running this script."
27 exit 1
28 fi
29
30 # Use a different PID file for each program.
31 K5PID=$HOME/.run/$1.pid
32
33 # The command to run.
34 shift
35 CMD="$*"
36
37 # Your keytab file.
38 KTAB=/etc/keytabs/user.daemon/$USER
39
40 # Terminate current k5start process, if one is running.
41 if test -f "$K5PID"; then
42 kill `cat -- "$K5PID"`
43 /usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"
44 fi
45
46 # Start fresh k5start daemon which will be refreshing tickets every 540 min
47 /usr/bin/k5start -U -b -K 540 -t -p "$K5PID" -f "$KTAB"
48
49 # Run actual service with arguments as provided on command line
50 $CMD