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

Revision 23235, 3.6 KB checked in by broder, 16 years ago (diff)
In pyhesiodfs: [ Anders Kaseorg ] * Don't require /lib/init/vars.sh in the initscript, so it works on dapper. [ Evan Broder ] * Fixup the permission bits on /dev/fuse if they're wrong
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"
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/lsb/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    chown root:fuse /dev/fuse || return 2
58    chmod g+rw /dev/fuse || return 2
59   
60    if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then
61        return 1
62    fi
63   
64    mkdir -p "$pyhesiodfs_dir"
65    chown root:pyhesiodfs "$pyhesiodfs_dir"
66    chmod 770 "$pyhesiodfs_dir"
67   
68    start-stop-daemon --start --quiet --pidfile $PIDFILE \
69        --chuid pyhesiodfs:pyhesiodfs --background \
70        --make-pidfile \
71        --exec $DAEMON -- \
72        $DAEMON_ARGS \
73        || return 2
74}
75
76#
77# Function that stops the daemon/service
78#
79do_stop()
80{
81    # Return
82    #   0 if daemon has been stopped
83    #   1 if daemon was already stopped
84    #   2 if daemon could not be stopped
85    #   other if a failure occurred
86   
87    if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then
88        umount -l "$pyhesiodfs_dir" || return 2
89        # Many daemons don't delete their pidfiles when they exit.
90        rm -f "$PIDFILE"
91    else
92        return 1
93    fi
94}
95
96case "$1" in
97    start)
98        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
99        do_start
100        case "$?" in
101            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
102            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
103        esac
104        ;;
105    stop)
106        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
107        do_stop
108        case "$?" in
109            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
110            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
111        esac
112        ;;
113    restart|force-reload)
114        log_daemon_msg "Restarting $DESC" "$NAME"
115        do_stop
116        case "$?" in
117            0|1)
118                do_start
119                case "$?" in
120                    0) log_end_msg 0 ;;
121                    1) log_end_msg 1 ;; # Old process is still running
122                    *) log_end_msg 1 ;; # Failed to start
123                esac
124                ;;
125            *)
126                # Failed to stop
127                log_end_msg 1
128                ;;
129        esac
130        ;;
131    *)
132        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
133        exit 3
134        ;;
135esac
136
137:
Note: See TracBrowser for help on using the repository browser.