916bccc8 |
1 | #!/usr/bin/pagsh.openafs |
a49e47df |
2 | # -*- Shell-Script -*- |
916bccc8 |
3 | # |
4 | # Usage: |
5 | # |
a49e47df |
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. |
916bccc8 |
11 | # |
12 | # Example: |
13 | # |
a49e47df |
14 | # run-in-pagsh interchange ~/interchange/bin/interchange |
916bccc8 |
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 |
a49e47df |
21 | if test -z "$2"; then |
22 | echo "Error: not enough arguments." |
23 | echo "Usage: run-in-pagsh name command [arguments] ..." |
916bccc8 |
24 | exit 1 |
25 | elif test ! -d "~/.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. |
a49e47df |
31 | K5PID=~/.run/$1.pid |
916bccc8 |
32 | |
33 | # The command to run. |
a49e47df |
34 | shift |
916bccc8 |
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"` |
69044a36 |
43 | /usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID" |
916bccc8 |
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 |