File: bittorrent.init

package info (click to toggle)
bittorrent 3.4.2-11.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,148 kB
  • ctags: 746
  • sloc: python: 7,014; objc: 1,181; sh: 201; makefile: 91
file content (125 lines) | stat: -rw-r--r-- 2,952 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
#! /bin/sh

### BEGIN INIT INFO
# Provides:          bittorrent
# Required-Start:    $network $local_fs
# Required-Stop:     $network $local_fs
# Should-Start:      
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start a bittorrent tracker
# Description:       Starts a bittorrent tracker, which
#                    aids bittorrent clients by locating
#                    other clients.
### END INIT INFO

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="BitTorrent tracker"
NAME=bttrack.bittorrent
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/bittorrent

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

. /lib/lsb/init-functions

PORT=6969
DFILE=/var/lib/bittorrent/bttrack.state

# Read config file if it is present.
if [ -r /etc/default/bittorrent ]; then
	. /etc/default/bittorrent
fi

# Add optional option $1 with argument $2 to OPTS, if $2 is nonempty
add_opt () {
	if ! test -z "$2" ; then
		OPTS="$OPTS $1 $2"
	fi
}

# Compose command-line arguments list for bttrack daemon, based on variables
# set in /etc/default/$NAME
OPTS=""
add_opt --dfile "$DFILE"
add_opt --port "$PORT"
add_opt --bind "$BIND"
add_opt --socket_timeout "$SOCKET_TIMEOUT"
add_opt --save_dfile_interval "$SAVE_DFILE_INTERVAL"
add_opt --timeout_downloaders_interval "$TIMEOUT_DOWNLOADERS_INTERVAL"
add_opt --reannounce_interval "$REANNOUNCE_INTERVAL"
add_opt --respose_size "$RESPONSE_SIZE"
add_opt --timeout_check_interval "$TIMEOUT_CHECK_INTERVAL"
add_opt --nat_check "$NAT_CHECK"
add_opt --min_time_between_log_flushes "$MIN_TIME_BETWEEN_LOG_FLUSHES"
add_opt --allowed_dir "$ALLOWED_DIR"
add_opt --parse_allowed_interval "$PARSE_ALLOWED_INTERVAL"
add_opt --show_names "$SHOW_NAMES"
add_opt --logfile "$DAEMONLOGFILE"
DAEMONOPTS="$OPTS"

# Add arguments for start-stop-daemon, based on variables set in
# /etc/default/$NAME
OPTS=""
add_opt --chuid "$DAEMONUSER"
add_opt --chroot "$DAEMONCHROOT"
add_opt --chdir "$DAEMONCHDIR"
add_opt --nicelevel "$DAEMONNICE"
METAOPTS="$OPTS"

#
#Function that starts the daemon/service.
#
d_start() {
	if [ $START_BTTRACK -ne 1 ]; then
		log_progress_msg "disabled in /etc/default/bittorrent"
		return 1
	else
		start-stop-daemon --start --background --quiet \
		--make-pidfile --pidfile "$PIDFILE" \
		$METAOPTS \
		--exec $DAEMON -- $DAEMONOPTS
		return 0
	fi
}

#
#Function that stops the daemon/service.
#
d_stop() {
	start-stop-daemon --stop --oknodo --quiet --pidfile "$PIDFILE"
}

case "$1" in
  start)
  	log_daemon_msg "Starting $DESC" "$NAME"
	d_start
	log_end_msg $?
	;;
  stop)
  	log_daemon_msg "Stopping $DESC" "$NAME"
	d_stop
	log_end_msg 0
	;;
  restart|force-reload)
  	log_daemon_msg "Restarting $DESC" "$NAME"
	d_stop
	sleep 1
	d_start
	log_end_msg $?
	;;
  status)
  	exit 4
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 2
	;;
esac

exit 0