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 |
---|
18 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
---|
19 | DESC="Debathena /mit automounter" |
---|
20 | NAME=debathena-pyhesiodfs |
---|
21 | DAEMON=/usr/bin/pyhesiodfs |
---|
22 | pyhesiodfs_dir="/mit" |
---|
23 | DAEMON_ARGS="-f $pyhesiodfs_dir" |
---|
24 | PIDFILE=/var/run/$NAME.pid |
---|
25 | SCRIPTNAME=/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 | . /lib/init/vars.sh |
---|
35 | |
---|
36 | # Define LSB log_* functions. |
---|
37 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
---|
38 | . /lib/lsb/init-functions |
---|
39 | |
---|
40 | # |
---|
41 | # Function that starts the daemon/service |
---|
42 | # |
---|
43 | do_start() |
---|
44 | { |
---|
45 | # Return |
---|
46 | # 0 if daemon has been started |
---|
47 | # 1 if daemon was already running |
---|
48 | # 2 if daemon could not be started |
---|
49 | |
---|
50 | # Try to make sure fuse is setup |
---|
51 | [ -e /dev/fuse ] || modprobe fuse || return 2 |
---|
52 | |
---|
53 | if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then |
---|
54 | return 1 |
---|
55 | fi |
---|
56 | |
---|
57 | mkdir -p "$pyhesiodfs_dir" |
---|
58 | chown root:pyhesiodfs "$pyhesiodfs_dir" |
---|
59 | chmod 770 "$pyhesiodfs_dir" |
---|
60 | |
---|
61 | start-stop-daemon --start --quiet --pidfile $PIDFILE \ |
---|
62 | --chuid pyhesiodfs:pyhesiodfs --background \ |
---|
63 | --make-pidfile \ |
---|
64 | --exec $DAEMON -- \ |
---|
65 | $DAEMON_ARGS \ |
---|
66 | || return 2 |
---|
67 | } |
---|
68 | |
---|
69 | # |
---|
70 | # Function that stops the daemon/service |
---|
71 | # |
---|
72 | do_stop() |
---|
73 | { |
---|
74 | # Return |
---|
75 | # 0 if daemon has been stopped |
---|
76 | # 1 if daemon was already stopped |
---|
77 | # 2 if daemon could not be stopped |
---|
78 | # other if a failure occurred |
---|
79 | |
---|
80 | if cat /proc/mounts | grep " $pyhesiodfs_dir " >/dev/null 2>&1; then |
---|
81 | umount -l "$pyhesiodfs_dir" || return 2 |
---|
82 | # Many daemons don't delete their pidfiles when they exit. |
---|
83 | rm -f "$PIDFILE" |
---|
84 | else |
---|
85 | return 1 |
---|
86 | fi |
---|
87 | } |
---|
88 | |
---|
89 | case "$1" in |
---|
90 | start) |
---|
91 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
---|
92 | do_start |
---|
93 | case "$?" in |
---|
94 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
95 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
96 | esac |
---|
97 | ;; |
---|
98 | stop) |
---|
99 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
---|
100 | do_stop |
---|
101 | case "$?" in |
---|
102 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
103 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
104 | esac |
---|
105 | ;; |
---|
106 | restart|force-reload) |
---|
107 | log_daemon_msg "Restarting $DESC" "$NAME" |
---|
108 | do_stop |
---|
109 | case "$?" in |
---|
110 | 0|1) |
---|
111 | do_start |
---|
112 | case "$?" in |
---|
113 | 0) log_end_msg 0 ;; |
---|
114 | 1) log_end_msg 1 ;; # Old process is still running |
---|
115 | *) log_end_msg 1 ;; # Failed to start |
---|
116 | esac |
---|
117 | ;; |
---|
118 | *) |
---|
119 | # Failed to stop |
---|
120 | log_end_msg 1 |
---|
121 | ;; |
---|
122 | esac |
---|
123 | ;; |
---|
124 | *) |
---|
125 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
---|
126 | exit 3 |
---|
127 | ;; |
---|
128 | esac |
---|
129 | |
---|
130 | : |
---|