cvsimport
[clinton/scripts.git] / run-in-pagsh
CommitLineData
46a93550 1#!/usr/bin/pagsh.openafs
92bce8a1 2# -*- Shell-Script -*-
46a93550 3#
4# Usage:
5#
92bce8a1 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.
46a93550 11#
12# Example:
13#
92bce8a1 14# run-in-pagsh interchange ~/interchange/bin/interchange
46a93550 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
92bce8a1 21if test -z "$2"; then
22 echo "Error: not enough arguments."
23 echo "Usage: run-in-pagsh name command [arguments] ..."
46a93550 24 exit 1
5aa75225 25elif test ! -d "$HOME/.run"; then
46a93550 26 echo "Error: the ~/.run directory must exist before running this script."
27 exit 1
28fi
29
30# Use a different PID file for each program.
5aa75225 31K5PID=$HOME/.run/$1.pid
46a93550 32
33# The command to run.
92bce8a1 34shift
46a93550 35CMD="$*"
36
37# Your keytab file.
38KTAB=/etc/keytabs/user.daemon/$USER
39
40# Terminate current k5start process, if one is running.
41if test -f "$K5PID"; then
42 kill `cat -- "$K5PID"`
1e515d3d 43 /usr/bin/k5start -qtU -f "$KTAB" -- rm -f "$K5PID"
46a93550 44fi
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