File: freepops.init

package info (click to toggle)
freepops 0.2.7-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,464 kB
  • ctags: 2,677
  • sloc: ansic: 16,571; sh: 1,781; makefile: 1,127; cpp: 350
file content (128 lines) | stat: -rw-r--r-- 2,780 bytes parent folder | download | duplicates (5)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash

### BEGIN INIT INFO
# Provides:          freepops
# Required-Start: $network $local_fs $remote_fs
# Required-Stop:  $network $local_fs $remote_fs
# Should-Start:   $syslog
# Should-Stop:    $syslog
# X-Start-Before: fetchmail
# X-Stop-After:   fetchmail
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the freepopsd (* > pop3) daemon.
# Description:       Starts freepopsd, an everthing to pop3
#                    converter, usually used as a webmail to
#                    pop3 converter.
### END INIT INFO

# lsb functions, to use those ugly colors.. 
. /lib/lsb/init-functions

### some default values ###

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DEFAULT_DAEMON=/usr/bin/freepopsd
DEFAULT_PIDFILE=/var/run/freepopsd.pid
DEFAULT_CHROOTED_DAEMON_OPTS=" -n -s nobody.nogroup"
DEFAULT_DAEMON_OPTS=" -n"

NAME=freepopsd
DESC="freepops daemon"

### /etc/default/ loading ###

# Include freepops defaults if available. Used variables are:
# DAEMON, DAEMON_OPTS, CHROOTED_DAEMON_OPTS, PIDFILE, CHROOT
# all have a DEFAULT_ here, except CHROOT that is empty if the 
# daemon should run in the normal environment

if [ -f /etc/default/freepops ] ; then
	. /etc/default/freepops
fi

if [ -z "$DAEMON" ] ; then
	DAEMON=$DEFAULT_DAEMON
fi

if [ -z "$PIDFILE" ] ; then
	PIDFILE=$DEFAULT_PIDFILE
fi

if [ -z "$DAEMON_OPTS" ] ; then
	DAEMON_OPTS=$DEFAULT_DAEMON_OPTS
fi

if [ -z "$CHROOTED_DAEMON_OPTS" ] ; then
	CHROOTED_DAEMON_OPTS=$DEFAULT_CHROOTED_DAEMON_OPTS
fi

test -x $DAEMON || exit 0

set -e

### helpers ###

start_freepopsd () {
	if [ -z "$CHROOT" ] ; then
	  	log_daemon_msg "Starting $DESC" "$NAME"
		start-stop-daemon --start -b --quiet -m -p $PIDFILE \
			--exec $DAEMON -- $DAEMON_OPTS
		log_end_msg $?
	else
  		log_daemon_msg "Starting $DESC" "(chroot) $NAME"
		start-stop-daemon --start -b --quiet -m -p $PIDFILE \
			-r $CHROOT --exec $DAEMON -- $CHROOTED_DAEMON_OPTS
		log_end_msg $?
	fi
}

stop_freepopsd () {
	if [ -z "$CHROOT" ] ; then
	  	log_daemon_msg "Stopping $DESC" "$NAME"
		start-stop-daemon --stop --quiet -p $PIDFILE 
		log_end_msg $?
	else
	  	log_daemon_msg "Stopping $DESC" "(chroot) $NAME"
		start-stop-daemon --stop --quiet -p $PIDFILE 
		log_end_msg $?
	fi
	rm $PIDFILE
}

status_freepopsd () {
	P=`cat $PIDFILE`
	N=`ps -e | grep "^$P " | grep $DAEMON | wc -l`
	if [ $N > 0 ]; then
		echo freepops is running with pid $P.
	else
		echo freepops is dead.
	fi
}

### real code ###

case "$1" in
  start)
	start_freepopsd
	;;
  stop)
	stop_freepopsd
	;;
  restart|force-reload)
	stop_freepopsd
	sleep 1
	start_freepopsd
	;;
  status)
  	status_freepopsd
  	;;
  *)
	N=/etc/init.d/freepops
	echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0