Ticket #961: tahoelafsd.5

File tahoelafsd.5, 3.2 KB (added by ioerror, at 2010-03-04T08:30:05Z)

finial version of init.d script that uses defaults properly

Line 
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
17PATH=/sbin:/usr/sbin:/bin:/usr/bin
18DESC="Tahoe-LAFS is a secure, decentralized, data store."
19NAME=tahoe
20DEFAULTS=tahoelafsd
21DAEMONHOME="/var/lib/tahoelafsd/"
22DAEMON=/usr/bin/$NAME
23DAEMON_ARGS=" start $DAEMONHOME"
24PIDFILE=/var/lib/tahoelafsd/twisted.pid
25USERNAME=tahoelafsd
26SCRIPTNAME=/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# Exit if we're unconfigured
35if [ "$ENABLED" = "FALSE" ]; then
36    echo "Tahoe is disabled; please edit /etc/defaults/$DEFAULTS";
37    exit 0;
38fi
39
40# Load the VERBOSE setting and other rcS variables
41. /lib/init/vars.sh
42
43# Define LSB log_* functions.
44# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
45. /lib/lsb/init-functions
46
47#
48# Function that starts the daemon/service
49#
50do_start()
51{
52        # Return
53        #   2 if daemon could not be started
54        su -c "$DAEMON $DAEMON_ARGS" $USERNAME \
55                || return 2
56}
57
58#
59# Function that stops the daemon/service
60#
61do_stop()
62{
63        # Return
64        #   0 if daemon has been stopped
65        #   1 if daemon was already stopped
66        #   2 if daemon could not be stopped
67        su -c "$DAEMON stop $DAEMONHOME" $USERNAME \
68                || return 2
69        RETVAL="$?"
70        [ "$RETVAL" = 2 ] && return 2
71        return "$RETVAL"
72}
73
74#
75# Function that sends a SIGHUP to the daemon/service
76#
77do_reload() {
78        #
79        # If the daemon can reload its configuration without
80        # restarting (for example, when it is sent a SIGHUP),
81        # then implement that here.
82        #
83        echo "Tahoe does not currently support HUP by reloading its config file."
84        return 0
85}
86
87case "$1" in
88  start)
89        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
90        do_start
91        case "$?" in
92                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
93                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
94        esac
95        ;;
96  stop)
97        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
98        do_stop
99        case "$?" in
100                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
101                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
102        esac
103        ;;
104  #reload|force-reload)
105        #
106        # If do_reload() is not implemented then leave this commented out
107        # and leave 'force-reload' as an alias for 'restart'.
108        #
109        #log_daemon_msg "Reloading $DESC" "$NAME"
110        #do_reload
111        #log_end_msg $?
112        #;;
113  restart|force-reload)
114        #
115        # If the "reload" option is implemented then remove the
116        # 'force-reload' alias
117        #
118        log_daemon_msg "Restarting $DESC" "$NAME"
119        do_stop
120        case "$?" in
121          0|1)
122                do_start
123                case "$?" in
124                        0) log_end_msg 0 ;;
125                        1) log_end_msg 1 ;; # Old process is still running
126                        *) log_end_msg 1 ;; # Failed to start
127                esac
128                ;;
129          *)
130                # Failed to stop
131                log_end_msg 1
132                ;;
133        esac
134        ;;
135  *)
136        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
137        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
138        exit 3
139        ;;
140esac
141
142: