1 #!/usr/bin/pagsh.openafs
6 # run-in-pagsh [--fg] name command [argument ...]
8 # The argument `name' is a short description of the program to call,
9 # without any spaces. It is used for making a PID file, which ensures
10 # that only one instance of your command is running.
12 # The arguments that come afterward specify the command to run and its
15 # If the command will run in the foreground, then you should use the
16 # `--fg' argument, making sure that it is the very first argument to
21 # run-in-pagsh interchange ~/interchange/bin/interchange
23 # run-in-pagsh --fg clean-mail ~/scripts/clean-mail
25 # Make sure that the ~/.run directory exists and is writable.
26 # See http://wiki2.hcoop.net/MemberManual/RunningUnattendedCommands
27 # for instructions on how to accomplish this.
29 # Allow user to specify "--fg" argument.
30 if test "$1" = "--fg"; then
39 echo "Error: not enough arguments."
40 echo "Usage: run-in-pagsh name [--fg] command [argument ...]"
42 elif test ! -d "$HOME/.run"; then
43 echo "Error: the ~/.run directory must exist before running this script."
47 # Use a different PID file for each program.
48 K5PID=$HOME/.run/$1.pid
55 KTAB=/etc/keytabs/user.daemon/$USER
57 # Terminate current k5start process, if one is running.
58 if test -f "$K5PID"; then
59 kill `cat -- "$K5PID"` 2>/dev/null
60 /usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"
63 if test -n "$BGFLAG"; then
65 # Start fresh k5start daemon which will be refreshing tickets
67 /usr/bin/k5start -U -b -K 540 -t -p "$K5PID" -f "$KTAB"
69 # Run actual service with arguments as provided on command line.
74 # Run the command once, in the foreground, cleaning up its PID
76 /usr/bin/k5start -U -K 540 -t -p "$K5PID" -f "$KTAB" -- $CMD
77 /usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"