[23151] | 1 | #! /bin/sh |
---|
[23080] | 2 | ### BEGIN INIT INFO |
---|
[23151] | 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. |
---|
[23080] | 11 | ### END INIT INFO |
---|
| 12 | |
---|
[23151] | 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 |
---|
| 18 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
---|
| 19 | DESC="Debathena /mit automounter" |
---|
[23080] | 20 | NAME=debathena-pyhesiodfs |
---|
[23151] | 21 | DAEMON=/usr/bin/pyhesiodfs |
---|
[23080] | 22 | pyhesiodfs_dir="/mit" |
---|
[23151] | 23 | DAEMON_ARGS="-f $pyhesiodfs_dir" |
---|
| 24 | PIDFILE=/var/run/$NAME.pid |
---|
| 25 | SCRIPTNAME=/etc/init.d/$NAME |
---|
[23080] | 26 | |
---|
[23151] | 27 | # Exit if the package is not installed |
---|
| 28 | [ -x "$DAEMON" ] || exit 0 |
---|
[23080] | 29 | |
---|
[23151] | 30 | # Read configuration variable file if it is present |
---|
| 31 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
---|
[23080] | 32 | |
---|
[23151] | 33 | # Load the VERBOSE setting and other rcS variables |
---|
[23235] | 34 | : ${VERBOSE:=yes} |
---|
[23237] | 35 | if [ -f /lib/init/vars.sh ]; then |
---|
[23235] | 36 | . /lib/init/vars.sh |
---|
| 37 | elif [ -f /etc/default/rcS ]; then |
---|
| 38 | . /etc/default/rcS |
---|
| 39 | fi |
---|
[23151] | 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 | # |
---|
| 48 | do_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 | # |
---|
| 77 | do_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 | |
---|
[23080] | 94 | case "$1" in |
---|
[23151] | 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 | ;; |
---|
[23080] | 133 | esac |
---|
| 134 | |
---|
[23151] | 135 | : |
---|