summaryrefslogtreecommitdiffstats
path: root/projectroot/etc/init.d/thttpd
blob: 51102b9d0f60ac43b12bf51cdc8ce591547b1c44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
#
# thttpd
#

PREFIX="thttpd: "
THISFILE=$0
DOCUMENTROOT="/var/www"
thttpd="/usr/sbin/thttpd"
PIDFILE="/var/run/thttpd.pid"
LOGFILE="/var/log/thttpd.log"

usage() {
	echo "${PREFIX}usage: $THISFILE [start|stop]"
}

case $1 in

	start)
		echo "${PREFIX} starting"
		if [ -e "$PIDFILE" ]; then
			echo "${PREFIX} warning: another thttpd seems to be running, trying to kill it"
			kill -9 `cat $PIDFILE`
			rm -f $PIDFILE
		fi
		$thttpd -d $DOCUMENTROOT -u www -nor -nos -p 80 -c '**.cgi' -i $PIDFILE -l $LOGFILE
		if [ "$?" != "0" ]; then
			echo "${PREFIX} error, could not start server"
			rm -f $PIDFILE
		else
			echo "${PREFIX} done"
		fi
		;;

	stop)
		if [ -e "$PIDFILE" ]; then
			echo "${PREFIX} stopping"
			kill -USR1 `cat $PIDFILE`
			rm -f $PIDFILE
			echo "${PREFIX} done"
		else
			echo "${PREFIX} not running"
		fi
		;;

	*)

		usage
		exit 1
		;;

esac