1 | #! /bin/sh |
---|
2 | ### BEGIN INIT INFO |
---|
3 | # Provides: tahoelafsd |
---|
4 | # Required-Start: $remote_fs |
---|
5 | # Required-Stop: $remote_fs |
---|
6 | # Default-Start: 2 3 4 5 |
---|
7 | # Default-Stop: 0 1 6 |
---|
8 | # Short-Description: Tahoe-LAFS initscript |
---|
9 | # Description: This starts Tahoe and runs it as a daemon |
---|
10 | ### END INIT INFO |
---|
11 | |
---|
12 | # Author: Jacob Appelbaum <jacob@appelbaum.net> |
---|
13 | |
---|
14 | # Do NOT "set -e" |
---|
15 | |
---|
16 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
---|
17 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
---|
18 | DESC="Tahoe-LAFS is a secure, decentralized, data store." |
---|
19 | NAME=tahoe |
---|
20 | DEFAULTS=tahoelafsd |
---|
21 | DAEMONHOME="/var/lib/tahoelafs/" |
---|
22 | DAEMON=/usr/bin/$NAME |
---|
23 | DAEMON_ARGS=" start $DAEMONHOME" |
---|
24 | PIDFILE=/var/lib/tahoelafs/twisted.pid |
---|
25 | USERNAME=tahoelafsd |
---|
26 | SCRIPTNAME=/etc/init.d/$NAME |
---|
27 | |
---|
28 | # Exit if the package is not installed |
---|
29 | [ -x "$DAEMON" ] || exit 0 |
---|
30 | |
---|
31 | # Read configuration variable file if it is present |
---|
32 | [ -r /etc/default/$DEFAULTS ] && . /etc/default/$DEFAULTS |
---|
33 | |
---|
34 | # Load the VERBOSE setting and other rcS variables |
---|
35 | . /lib/init/vars.sh |
---|
36 | |
---|
37 | # Define LSB log_* functions. |
---|
38 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
---|
39 | . /lib/lsb/init-functions |
---|
40 | |
---|
41 | # |
---|
42 | # Function that starts the daemon/service |
---|
43 | # |
---|
44 | do_start() |
---|
45 | { |
---|
46 | # Return |
---|
47 | # 2 if daemon could not be started |
---|
48 | su -c "$DAEMON $DAEMON_ARGS" $USERNAME \ |
---|
49 | || return 2 |
---|
50 | } |
---|
51 | |
---|
52 | # |
---|
53 | # Function that stops the daemon/service |
---|
54 | # |
---|
55 | do_stop() |
---|
56 | { |
---|
57 | # Return |
---|
58 | # 0 if daemon has been stopped |
---|
59 | # 1 if daemon was already stopped |
---|
60 | # 2 if daemon could not be stopped |
---|
61 | su -c "$DAEMON stop $DAEMONHOME" $USERNAME \ |
---|
62 | || return 2 |
---|
63 | RETVAL="$?" |
---|
64 | [ "$RETVAL" = 2 ] && return 2 |
---|
65 | return "$RETVAL" |
---|
66 | } |
---|
67 | |
---|
68 | # |
---|
69 | # Function that sends a SIGHUP to the daemon/service |
---|
70 | # |
---|
71 | do_reload() { |
---|
72 | # |
---|
73 | # If the daemon can reload its configuration without |
---|
74 | # restarting (for example, when it is sent a SIGHUP), |
---|
75 | # then implement that here. |
---|
76 | # |
---|
77 | echo "Tahoe does not currently support HUP by reloading its config file." |
---|
78 | return 0 |
---|
79 | } |
---|
80 | |
---|
81 | case "$1" in |
---|
82 | start) |
---|
83 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
---|
84 | do_start |
---|
85 | case "$?" in |
---|
86 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
87 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
88 | esac |
---|
89 | ;; |
---|
90 | stop) |
---|
91 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
---|
92 | do_stop |
---|
93 | case "$?" in |
---|
94 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
95 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
96 | esac |
---|
97 | ;; |
---|
98 | #reload|force-reload) |
---|
99 | # |
---|
100 | # If do_reload() is not implemented then leave this commented out |
---|
101 | # and leave 'force-reload' as an alias for 'restart'. |
---|
102 | # |
---|
103 | #log_daemon_msg "Reloading $DESC" "$NAME" |
---|
104 | #do_reload |
---|
105 | #log_end_msg $? |
---|
106 | #;; |
---|
107 | restart|force-reload) |
---|
108 | # |
---|
109 | # If the "reload" option is implemented then remove the |
---|
110 | # 'force-reload' alias |
---|
111 | # |
---|
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|reload|force-reload}" >&2 |
---|
131 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
---|
132 | exit 3 |
---|
133 | ;; |
---|
134 | esac |
---|
135 | |
---|
136 | : |
---|