Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 501364 | Differences between
and this patch

Collapse All | Expand All

(-)a/Makefile (-1 / +1 lines)
Lines 4-10 Link Here
4
4
5
include Makefile.inc
5
include Makefile.inc
6
6
7
SUBDIR=		conf.d etc init.d local.d man scripts sh src sysctl.d
7
SUBDIR=		conf.d etc init.d local.d man scripts sh src sysctl.d addon
8
8
9
# Build pkgconfig or not
9
# Build pkgconfig or not
10
MKPKGCONFIG?=	yes
10
MKPKGCONFIG?=	yes
(-)a/addon/Makefile (+9 lines)
Line 0 Link Here
1
DIR=	${LIBEXECDIR}/addons
2
INC=	runit.sh ssdaemon.sh
3
4
MK=	../mk
5
6
include ${MK}/scripts.mk
7
8
check test::
9
	./runtests.sh
(-)a/addon/runit.sh (+59 lines)
Line 0 Link Here
1
# Copyright (c) 2014 Benda Xu <heroxbd@gentoo.org>
2
# Released under the 2-clause BSD license.
3
4
RUNIT_DIR="${EPREFIX}/var/runit/${RC_SVCNAME}"
5
6
status()
7
{
8
	eval sv status "${RUNIT_DIR}"
9
}
10
11
reload()
12
{
13
	eval sv force-reload "${RUNIT_DIR}"
14
}
15
16
stop()
17
{
18
	ebegin "stopping ${RC_SVCNAME} via runit"
19
	eval sv stop "${RUNIT_DIR}"
20
	eend $?
21
}
22
23
start()
24
{
25
	ebegin "starting ${RC_SVCNAME} via runit"
26
27
	if [ ! -x "${RUNIT_DIR}/run" ]; then
28
		[ -n "$arg_foreground" ] && command_args="$command_args $arg_foreground"
29
		[ -d "${RUNIT_DIR}" ] || mkdir -p "${RUNIT_DIR}"
30
		touch "${RUNIT_DIR}/down"
31
		[ -d "${RUNIT_DIR}/log/main" ] || mkdir -p "${RUNIT_DIR}/log/main"
32
		cat > "${RUNIT_DIR}/log/run" << EOF
33
#!/bin/sh
34
exec svlogd -tt ${RUNIT_DIR}/log/main
35
EOF
36
		chmod +x "${RUNIT_DIR}/log/run"
37
38
		command_prefixed=$command
39
		[ -n "$command_user" ] && command_prefixed="chpst -u $command_user $command_prefixed"
40
		[ -n "$command_env" ] && command_prefixed="env $command_env $command_prefixed"
41
		cat > "${RUNIT_DIR}/run" << EOF
42
#!/bin/sh
43
exec 2>&1
44
exec $command_prefixed $command_args
45
EOF
46
		chmod +x "${RUNIT_DIR}/run"
47
		# from manpage of runsvdir: At least every
48
		# five seconds runsvdir checks whether the
49
		# time of last modification, the inode, or the
50
		# device, of the services directory dir has
51
		# changed. So we wait for 5 seconds here. It
52
		# would be cooler if we can signal runsvdir
53
		# such change. Better if we can control runsv
54
		# via runsvdir.
55
		ebegin "set up ${RUNIT_DIR}, wait for 5 seconds for runsvdir to pick it up and spawn runsv"
56
		sleep 5
57
		eend $?
58
	fi
59
}
(-)a/addon/runtests.sh (+6 lines)
Line 0 Link Here
1
#!/bin/sh
2
for f in ./*.sh; do
3
	[ $f = ./runtests.sh ] && continue
4
	. $f || exit 1
5
done
6
exit 0
(-)a/addon/ssdaemon.sh (+67 lines)
Line 0 Link Here
1
# Template start / stop / status functions
2
start()
3
{
4
	[ -n "$command" ] || return 0
5
	[ -n "$arg_background" ] && command_args="$command_args $arg_background"
6
7
	local _background=
8
	ebegin "Starting ${name:-$RC_SVCNAME}"
9
	if yesno "${command_background}"; then
10
		if [ -z "${pidfile}" ]; then
11
			eend 1 "command_background option used but no pidfile specified"
12
			return 1
13
		fi
14
		_background="--background --make-pidfile"
15
	fi
16
	if yesno "$start_inactive"; then
17
		local _inactive=false
18
		service_inactive && _inactive=true
19
		mark_service_inactive
20
	fi
21
	eval start-stop-daemon --start \
22
		--exec $command \
23
		${procname:+--name} $procname \
24
		${pidfile:+--pidfile} $pidfile \
25
		${command_user+--user} $command_user \
26
		${command_env+--env} "$command_env" \
27
		${start_wait+--wait} "$start_wait" \
28
		$_background $start_stop_daemon_args \
29
		-- $command_args
30
	if eend $? "Failed to start $RC_SVCNAME"; then
31
		service_set_value "command" "${command}"
32
		[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
33
		[ -n "${procname}" ] && service_set_value "procname" "${procname}"
34
		return 0
35
	fi
36
	if yesno "$start_inactive"; then
37
		if ! $_inactive; then
38
			mark_service_stopped
39
		fi
40
	fi
41
	return 1
42
}
43
44
stop()
45
{
46
	local startcommand="$(service_get_value "command")"
47
	local startpidfile="$(service_get_value "pidfile")"
48
	local startprocname="$(service_get_value "procname")"
49
	command="${startcommand:-$command}"
50
	pidfile="${startpidfile:-$pidfile}"
51
	procname="${startprocname:-$procname}"
52
	[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
53
	ebegin "Stopping ${name:-$RC_SVCNAME}"
54
	start-stop-daemon --stop \
55
		${retry:+--retry} $retry \
56
		${command:+--exec} $command \
57
		${procname:+--name} $procname \
58
		${pidfile:+--pidfile} $pidfile \
59
		${stopsig:+--signal} $stopsig
60
61
	eend $? "Failed to stop $RC_SVCNAME"
62
}
63
64
status()
65
{
66
	_status
67
}
(-)a/sh/runscript.sh.in (-62 / +7 lines)
Lines 122-189 _status() Link Here
122
	fi
122
	fi
123
}
123
}
124
124
125
# Template start / stop / status functions
126
start()
127
{
128
	[ -n "$command" ] || return 0
129
	local _background=
130
	ebegin "Starting ${name:-$RC_SVCNAME}"
131
	if yesno "${command_background}"; then
132
		if [ -z "${pidfile}" ]; then
133
			eend 1 "command_background option used but no pidfile specified"
134
			return 1
135
		fi
136
		_background="--background --make-pidfile"
137
	fi
138
	if yesno "$start_inactive"; then
139
		local _inactive=false
140
		service_inactive && _inactive=true
141
		mark_service_inactive
142
	fi
143
	eval start-stop-daemon --start \
144
		--exec $command \
145
		${procname:+--name} $procname \
146
		${pidfile:+--pidfile} $pidfile \
147
		$_background $start_stop_daemon_args \
148
		-- $command_args
149
	if eend $? "Failed to start $RC_SVCNAME"; then
150
		service_set_value "command" "${command}"
151
		[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
152
		[ -n "${procname}" ] && service_set_value "procname" "${procname}"
153
		return 0
154
	fi
155
	if yesno "$start_inactive"; then
156
		if ! $_inactive; then
157
			mark_service_stopped
158
		fi
159
	fi
160
	return 1
161
}
162
163
stop()
164
{
165
	local startcommand="$(service_get_value "command")"
166
	local startpidfile="$(service_get_value "pidfile")"
167
	local startprocname="$(service_get_value "procname")"
168
	command="${startcommand:-$command}"
169
	pidfile="${startpidfile:-$pidfile}"
170
	procname="${startprocname:-$procname}"
171
	[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
172
	ebegin "Stopping ${name:-$RC_SVCNAME}"
173
	start-stop-daemon --stop \
174
		${retry:+--retry} $retry \
175
		${command:+--exec} $command \
176
		${procname:+--name} $procname \
177
		${pidfile:+--pidfile} $pidfile \
178
		${stopsig:+--signal} $stopsig
179
	eend $? "Failed to stop $RC_SVCNAME"
180
}
181
182
status()
183
{
184
	_status
185
}
186
187
yesno $RC_DEBUG && set -x
125
yesno $RC_DEBUG && set -x
188
126
189
_conf_d=${RC_SERVICE%/*}/../conf.d
127
_conf_d=${RC_SERVICE%/*}/../conf.d
Lines 205-210 unset _conf_d Link Here
205
# Load any system overrides
143
# Load any system overrides
206
sourcex -e "@SYSCONFDIR@/rc.conf"
144
sourcex -e "@SYSCONFDIR@/rc.conf"
207
145
146
# load a service controller
147
if [ -n $VIA ] && has_addon $VIA; then
148
	import_addon $VIA
149
else
150
	import_addon ssdaemon
151
fi
152
208
# Apply any ulimit defined
153
# Apply any ulimit defined
209
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
154
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
210
155

Return to bug 501364