]> andersk Git - test.git/blob - debian/shellinabox.init
Fixed an error in the init script's status function.
[test.git] / debian / shellinabox.init
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          shellinabox
4 # Required-Start:    $network $remote_fs
5 # Required-Stop:     $network $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Shell In A Box Daemon
9 # Description:       Daemon for publishing a login shell at
10 #                    http://localhost:4200
11 ### END INIT INFO
12
13 PATH=/sbin:/bin:/usr/sbin:/usr/bin
14 DESC="Shell In A Box Daemon"
15 NAME="shellinabox"
16 DAEMON="/usr/bin/shellinaboxd"
17 PIDFILE="/var/run/shellinaboxd.pid"
18 SCRIPTNAME=/etc/init.d/$NAME
19
20 # Gracefully exit if the package has been removed.
21 test -x $DAEMON || exit 0
22
23 . /lib/lsb/init-functions
24
25 # Include shellinabox defaults if available.
26 test -f /etc/default/shellinabox && . /etc/default/shellinabox
27
28 # Set some default values
29 SHELLINABOX_DATADIR="${SHELLINABOX_DATADIR:-/var/lib/shellinabox}"
30 SHELLINABOX_PORT="${SHELLINABOX_PORT:-4200}"
31 SHELLINABOX_USER="${SHELLINABOX_USER:-shellinabox}"
32 SHELLINABOX_GROUP="${SHELLINABOX_GROUP:-shellinabox}"
33
34 #
35 #       Function that starts the daemon/service.
36 #
37 d_start() {
38   if [ -z "$SHELLINABOX_DAEMON_START" -o                                      \
39           "$SHELLINABOX_DAEMON_START" = "0" ]; then
40     return 0
41   fi
42
43   eval start-stop-daemon --start --oknodo --pidfile "'$PIDFILE'"              \
44                     --exec "'$DAEMON'" -- -q --background="'$PIDFILE'"        \
45                     -c "'${SHELLINABOX_DATADIR}'" -p "'${SHELLINABOX_PORT}'"  \
46                     -u "'${SHELLINABOX_USER}'" -g "'${SHELLINABOX_GROUP}'"    \
47                     $(for i in $(ls /etc/shellinabox/options-enabled/*.css |
48                                  sed -e                                       \
49                                     's/.*[/]\([0-9]*\)[-_+][^/:,;]*[.]css/\1/'|
50                                  sort -u); do
51                         for j in /etc/shellinabox/options-enabled/"$i"*.css; do
52                           echo -n "$j" |
53                           sed -e 's/\(.*[/]\)\([0-9]*\)\([-_+]\)\([^/:,;]*\)[.]css/\4:\3\1\2\3\4.css,/
54                                   s/:_/:-/'
55                         done |
56                         sed -e 's/,$/;/'
57                       done |
58                       sed -e 's/;$//
59                               //b
60                               s/.*/--user-css "\0"/')                         \
61                     "${SHELLINABOX_ARGS}"
62 }
63
64 #
65 #       Function that stops the daemon/service.
66 #
67 d_stop() {
68   start-stop-daemon --stop --oknodo --pidfile "$PIDFILE"
69   rm -f "$PIDFILE"
70 }
71
72 #
73 #       Function that reloads the config file for the daemon/service.
74 #
75 d_reload() {
76   # Only reload if there are no active sessions running
77   [ -r "$PIDFILE" ] &&
78     [ `ps o pid= --ppid "\`cat "$PIDFILE"\`\`ps o pid= --ppid \
79                                                 \\\`cat "$PIDFILE"\\\`|
80                                              xargs -r -n 1 printf ',%s'\`" |
81        wc -l` -gt 1 ] &&
82     return 1
83
84   d_stop
85   d_start
86 }
87
88 #
89 #       Function that check the status of the daemon/service.
90 #
91 d_status() {
92   [ -r "$PIDFILE" ] && kill -0 `cat "$PIDFILE"` &&
93     echo "$DESC is running" || echo "$DESC is not running"
94 }
95
96 case "$1" in
97     start)
98         log_daemon_msg "Starting $DESC" "$NAME"
99         d_start
100         log_end_msg $?
101         ;;
102     stop)
103         log_daemon_msg "Stopping $DESC" "$NAME"
104         d_stop
105         log_end_msg $?
106         ;;
107     reload)
108         log_daemon_msg "Reloading services for $DESC" "$NAME"
109         d_reload
110         log_end_msg $?
111         ;;
112     restart|force-reload)
113         log_daemon_msg "Restarting $DESC" "$NAME"
114         d_stop
115         d_start
116         log_end_msg $?
117         ;;
118     status)
119         d_status
120         ;;
121     *)
122         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2
123         exit 1
124         ;;
125 esac
126
127 exit 0
This page took 0.037372 seconds and 5 git commands to generate.