HCoop
/
clinton
/
scripts.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
run-in-pagsh: Figure out what user we're running as
[clinton/scripts.git]
/
run-in-pagsh
diff --git
a/run-in-pagsh
b/run-in-pagsh
index
5a54629
..
5ef0e24
100755
(executable)
--- a/
run-in-pagsh
+++ b/
run-in-pagsh
@@
-3,48
+3,88
@@
#
# Usage:
#
#
# Usage:
#
-# run-in-pagsh
name command [arguments] ...
+# run-in-pagsh
[--fg] name command [argument ...]
#
#
-# The
first argument, `name', is a short description of the program to
-#
call, without any spaces. It is used for making a PID file, which
-#
ensures
that only one instance of your command is running.
+# The
argument `name' is a short description of the program to call,
+#
without any spaces. It is used for making a PID file, which ensures
+# that only one instance of your command is running.
#
#
-# Example:
+# The arguments that come afterward specify the command to run and its
+# arguments, if any.
+#
+# If the command will run in the foreground, then you should use the
+# `--fg' argument, making sure that it is the very first argument to
+# run-in-pagsh.
+#
+# Examples:
#
# run-in-pagsh interchange ~/interchange/bin/interchange
#
#
# run-in-pagsh interchange ~/interchange/bin/interchange
#
+# run-in-pagsh --fg clean-mail ~/scripts/clean-mail
+#
# Make sure that the ~/.run directory exists and is writable.
# See http://wiki2.hcoop.net/MemberManual/RunningUnattendedCommands
# for instructions on how to accomplish this.
# Make sure that the ~/.run directory exists and is writable.
# See http://wiki2.hcoop.net/MemberManual/RunningUnattendedCommands
# for instructions on how to accomplish this.
-# Sanity checks
+# Allow user to specify "--fg" argument.
+if test "$1" = "--fg"; then
+ shift
+ BGFLAG=
+else
+ BGFLAG=-b
+fi
+
+# Sanity checks.
if test -z "$2"; then
echo "Error: not enough arguments."
if test -z "$2"; then
echo "Error: not enough arguments."
- echo "Usage: run-in-pagsh name
command [arguments] ...
"
+ echo "Usage: run-in-pagsh name
[--fg] command [argument ...]
"
exit 1
exit 1
-elif test ! -d "
~
/.run"; then
+elif test ! -d "
$HOME
/.run"; then
echo "Error: the ~/.run directory must exist before running this script."
exit 1
fi
# Use a different PID file for each program.
echo "Error: the ~/.run directory must exist before running this script."
exit 1
fi
# Use a different PID file for each program.
-K5PID=
~
/.run/$1.pid
+K5PID=
$HOME
/.run/$1.pid
# The command to run.
shift
CMD="$*"
# The command to run.
shift
CMD="$*"
+# Try to deduce the user we're running as.
+if test -z "$USER"; then
+ if test -n "$LOGNAME"; then
+ USER=$LOGNAME
+ elif test -n "$HOME"; then
+ USER=$(basename "$HOME")
+ else
+ echo "Error: cannot deduce your username"
+ exit 1
+ fi
+fi
+
# Your keytab file.
KTAB=/etc/keytabs/user.daemon/$USER
# Terminate current k5start process, if one is running.
if test -f "$K5PID"; then
# Your keytab file.
KTAB=/etc/keytabs/user.daemon/$USER
# Terminate current k5start process, if one is running.
if test -f "$K5PID"; then
- kill `cat -- "$K5PID"`
+ kill `cat -- "$K5PID"`
2>/dev/null
/usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"
fi
/usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"
fi
-# Start fresh k5start daemon which will be refreshing tickets every 540 min
-/usr/bin/k5start -U -b -K 540 -t -p "$K5PID" -f "$KTAB"
+if test -n "$BGFLAG"; then
+
+ # Start fresh k5start daemon which will be refreshing tickets
+ # every 540 min.
+ /usr/bin/k5start -U -b -K 540 -t -p "$K5PID" -f "$KTAB"
+
+ # Run actual service with arguments as provided on command line.
+ $CMD
-# Run actual service with arguments as provided on command line
-$CMD
+else
+
+ # Run the command once, in the foreground, cleaning up its PID
+ # file when done.
+ /usr/bin/k5start -U -K 540 -t -p "$K5PID" -f "$KTAB" -- $CMD
+ /usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"
+fi