File: distributed-net.init

package info (click to toggle)
distributed-net 2.9112.521%2Barm64-3
  • links: PTS
  • area: non-free
  • in suites: bookworm, forky, sid, trixie
  • size: 9,336 kB
  • sloc: sh: 144; makefile: 51
file content (170 lines) | stat: -rw-r--r-- 4,699 bytes parent folder | download | duplicates (3)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
### BEGIN INIT INFO
# Provides:          distributed-net
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      $network
# Should-Stop:       $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the distributed.net client at boot time.
# Description:       Execute the distributed.net client as a background daemon during boot
#                    and provide an interface for controlling it which is consistent with
#                    other system services.
### END INIT INFO
#
# Notes:
#   - distributed.net does not like to play nicely with init scripts.  It needs to be run
#     without the -quiet option.  Otherwise it will detach from the shell and there will
#     be no way to determine its PID.  
#
# This script was originally written by: Noel@debian.org, 2001-12-16.
# James Stark <jstark@ieee.org>, 2014-02-23

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="distributed.net client"
NAME=distributed-net
DAEMON="/usr/bin/dnetc"
DAEMON_ARGS=""
PIDFILE="/var/run/$NAME.pid"
LOGFILE="/var/log/$NAME.log"
CONFFILE="/etc/$NAME.conf"
SCRIPTNAME="/etc/init.d/$NAME"
BUFFIN="/var/lib/distributed-net/buff-in"
BUFFOUT="/var/lib/distributed-net/buff-out"

dnetc_opts=""

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions
. /lib/lsb/init-functions

# Build up the full list of arguments to the distributed.net client
DAEMON_ARGS="$DAEMON_ARGS -ini $CONFFILE -l $LOGFILE -inbase $BUFFIN -outbase $BUFFOUT $dnetc_opts"

#
# Attempt to start the distributed-net client.  The client will only be started
# if the configuration file is present and it is not already running.  Once the
# client has been successfully started set the scheduling priority to
# SCHED_IDLE for the client and all of its sub-processes.
#
do_start ()
{
	result=0 

	if [ -e /etc/distributed-net.conf ]; then
		if start-stop-daemon --start --quiet --user daemon --group daemon --pidfile $PIDFILE --exec $DAEMON --test > /dev/null; then
			chrt -i -p 0 $$
			start-stop-daemon --start --quiet --user daemon --group daemon --pidfile $PIDFILE --exec $DAEMON --chuid daemon:daemon --chdir /var/lib/$NAME/ --background --make-pidfile -- $DAEMON_ARGS || retval=2
		else
			result=1
		fi
	else
		log_failure_msg "distributed-net is not configured please run:  dpkg-reconfigure distributed-net"
		result=2
	fi

	return $result
}

#
# Shutdown the distributed.net client. It should clean up all of this children.
#
do_stop ()
{
	start-stop-daemon --stop --quiet --user daemon --group daemon --pidfile $PIDFILE --name "dnetc" --retry=TERM/30/KILL/5
	rm $PIDFILE

	return $?
}

#
# Perform various client actions like updating buffers.  The name of the client
# option is passed as an argument.  Since the distributed.net client is its own
# control program, start-stop-daemon will refuse to execute any of these actions
# as the client will already be running.  Therefore the action will be performed
# using su.
#
do_action ()
{
	result=0

	if cd /var/lib/distributed-net; then
		if start-stop-daemon --stop --quiet --signal 0 --user daemon --group daemon --name "dnetc" 2> /dev/null; then
			su daemon -s /bin/sh -c "$DAEMON $DAEMON_ARGS -$1"
		else
			result=2
		fi
	else
		result=2
	fi

	return $result
}

case "$1" in
	start)
		[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
		do_start
		case "$?" in
			0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
			2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
		esac
		;;
	stop)
		[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
		do_stop
		case "$?" in
			0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
			2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
		esac
		;;
	status)
		status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
		;;
	restart|force-reload|reload)
		log_daemon_msg "Restarting $DESC" "$NAME"
		do_stop
		case "$?" in
			0|1)
				do_start
				case "$?" in
					0) log_end_msg 0 ;;
					1) log_end_msg 1 ;; # Old process is still running
					*) log_end_msg 1 ;; # Failed to start
				esac
				;;
			*)
				log_end_msg 1 ;; # Failed to stop
		esac
		;;
	fetch)
		log_daemon_msg "$DESC Fetching blocks"
		do_action "fetch"
		log_end_msg 0
		;;
	flush)
		log_daemon_msg "$DESC Flushing blocks"
		do_action "flush"
		log_end_msg 0
		;;
	update)
		log_daemon_msg "$DESC Updating blocks"
		do_action "update"
		log_end_msg 0
		;;
	*)
		echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload|fetch|flush|update}" >&3
		exit 3
		;;
esac

exit 0