source: trunk/debathena/debathena/pyhesiodfs/debian/debathena-pyhesiodfs.init @ 24219

Revision 24219, 3.5 KB checked in by broder, 14 years ago (diff)
In pyhesiodfs: * Start PyHesiodFS with -o nonempty, in case there is anything in /mit. (Trac: #461)
Line 
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides:          debathena-pyhesiodfs
4# Required-Start:    openafs-client
5# Required-Stop:     openafs-client
6# Should-Start:      $local_fs $network
7# Default-Start:     2 3 4 5
8# Default-Stop:      0 1 6
9# Short-Description: Hesiod automounter for Athena lockers
10# Description:       Auto-create symlinks from /mit/LOCKER to AFS using Hesiod lookups.
11### END INIT INFO
12
13# Author: Evan Broder <broder@mit.edu>, Geoffrey Thomas <geofft@mit.edu>
14
15# Do NOT "set -e"
16
17# PATH should only include /usr/* if it runs after the mountnfs.sh script
18PATH=/sbin:/usr/sbin:/bin:/usr/bin
19DESC="Debathena /mit automounter"
20NAME=debathena-pyhesiodfs
21DAEMON=/usr/bin/pyhesiodfs
22pyhesiodfs_dir="/mit"
23DAEMON_ARGS="-f $pyhesiodfs_dir -o nonempty"
24PIDFILE=/var/run/$NAME.pid
25SCRIPTNAME=/etc/init.d/$NAME
26
27# Exit if the package is not installed
28[ -x "$DAEMON" ] || exit 0
29
30# Read configuration variable file if it is present
31[ -r /etc/default/$NAME ] && . /etc/default/$NAME
32
33# Load the VERBOSE setting and other rcS variables
34: ${VERBOSE:=yes}
35if [ -f /lib/init/vars.sh ]; then
36    . /lib/init/vars.sh
37elif [ -f /etc/default/rcS ]; then
38    . /etc/default/rcS
39fi
40
41# Define LSB log_* functions.
42# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
43. /lib/lsb/init-functions
44
45#
46# Function that starts the daemon/service
47#
48do_start()
49{
50    # Return
51    #   0 if daemon has been started
52    #   1 if daemon was already running
53    #   2 if daemon could not be started
54   
55    # Try to make sure fuse is setup
56    [ -e /dev/fuse ] || modprobe fuse || return 2
57   
58    if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then
59        return 1
60    fi
61   
62    mkdir -p "$pyhesiodfs_dir"
63    chown root:pyhesiodfs "$pyhesiodfs_dir"
64    chmod 770 "$pyhesiodfs_dir"
65   
66    start-stop-daemon --start --quiet --pidfile $PIDFILE \
67        --chuid pyhesiodfs:pyhesiodfs --background \
68        --make-pidfile \
69        --exec $DAEMON -- \
70        $DAEMON_ARGS \
71        || return 2
72}
73
74#
75# Function that stops the daemon/service
76#
77do_stop()
78{
79    # Return
80    #   0 if daemon has been stopped
81    #   1 if daemon was already stopped
82    #   2 if daemon could not be stopped
83    #   other if a failure occurred
84   
85    if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then
86        umount -l "$pyhesiodfs_dir" || return 2
87        # Many daemons don't delete their pidfiles when they exit.
88        rm -f "$PIDFILE"
89    else
90        return 1
91    fi
92}
93
94case "$1" in
95    start)
96        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
97        do_start
98        case "$?" in
99            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
100            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
101        esac
102        ;;
103    stop)
104        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
105        do_stop
106        case "$?" in
107            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
108            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
109        esac
110        ;;
111    restart|force-reload)
112        log_daemon_msg "Restarting $DESC" "$NAME"
113        do_stop
114        case "$?" in
115            0|1)
116                do_start
117                case "$?" in
118                    0) log_end_msg 0 ;;
119                    1) log_end_msg 1 ;; # Old process is still running
120                    *) log_end_msg 1 ;; # Failed to start
121                esac
122                ;;
123            *)
124                # Failed to stop
125                log_end_msg 1
126                ;;
127        esac
128        ;;
129    *)
130        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
131        exit 3
132        ;;
133esac
134
135:
Note: See TracBrowser for help on using the repository browser.