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/etc/rc.conf.in (-1 / +7 lines)
Lines 73-79 Link Here
73
#rc_crashed_stop=NO
73
#rc_crashed_stop=NO
74
#rc_crashed_start=YES
74
#rc_crashed_start=YES
75
75
76
# Set rc_nocolor to yes if you do not want colors displayed in OpenRC
76
# Set rc_supervisor to use a program to monitor your daemons and restart
77
# them when they crash.
78
# Leaving this undefined uses start-stop-daemon, which is OpenRC's
79
# default.
80
#rc_supervisor=""
81
82
# Set rc_nocolor to yes if you do not want colors displayed in OpenRc
77
# output.
83
# output.
78
#rc_nocolor=NO
84
#rc_nocolor=NO
79
85
(-)a/man/openrc-run.8 (-2 / +15 lines)
Lines 115-125 Daemon to start or stop via Link Here
115
if no start or stop function is defined by the service.
115
if no start or stop function is defined by the service.
116
.It Ar command_args
116
.It Ar command_args
117
List of arguments to pass to the daemon when starting.
117
List of arguments to pass to the daemon when starting.
118
.It Ar command_args_background
119
List of arguments, if the deamon has them, that tells the daemon to
120
background itself. This should be used if the daemon's default mode is
121
to run in the foreground, but it has an option to put it in the
122
background. This should not be used along with command_background below.
123
.It Ar command_args_foreground
124
List of arguments, if the deamon has them, that tells the daemon to
125
run in the foreground. This should be used to force a daemon that
126
normally runs in the background to stay in the foreground.
118
.It Ar command_background
127
.It Ar command_background
119
Set this to "true", "yes" or "1" (case-insensitive) to force the daemon into
128
Set this to "true", "yes" or "1" (case-insensitive) if you want
120
the background. This implies the "--make-pidfile" and "--pidfile" option of
129
.Xr start-stop-daemon 8
130
to force the daemon into the background. This implies the "--make-pidfile"
131
and "--pidfile" option of
121
.Xr start-stop-daemon 8
132
.Xr start-stop-daemon 8
122
so the pidfile variable must be set.
133
so the pidfile variable must be set.
134
.It Ar command_user
135
The user and group privileges to switch to before running the daemon.
123
.It Ar pidfile
136
.It Ar pidfile
124
Pidfile to use for the above defined command.
137
Pidfile to use for the above defined command.
125
.It Ar name
138
.It Ar name
(-)a/sh/Makefile (-1 / +2 lines)
Lines 1-7 Link Here
1
DIR=	${LIBEXECDIR}/sh
1
DIR=	${LIBEXECDIR}/sh
2
SRCS=	init.sh.in functions.sh.in gendepends.sh.in \
2
SRCS=	init.sh.in functions.sh.in gendepends.sh.in \
3
	rc-functions.sh.in runscript.sh.in tmpfiles.sh.in ${SRCS-${OS}}
3
	rc-functions.sh.in runscript.sh.in tmpfiles.sh.in ${SRCS-${OS}}
4
INC=	rc-mount.sh functions.sh rc-functions.sh
4
INC=	rc-mount.sh functions.sh rc-functions.sh runit.sh \
5
		start-stop-daemon.sh
5
BIN=	gendepends.sh init.sh runscript.sh tmpfiles.sh ${BIN-${OS}}
6
BIN=	gendepends.sh init.sh runscript.sh tmpfiles.sh ${BIN-${OS}}
6
7
7
INSTALLAFTER=	_installafter
8
INSTALLAFTER=	_installafter
(-)a/sh/runit.sh (+48 lines)
Line 0 Link Here
1
# Copyright (c) 2014 Benda Xu <heroxbd@gentoo.org>
2
# Released under the 2-clause BSD license.
3
4
sv_dir="${RC_SVCDIR}/sv/${RC_SVCNAME}"
5
6
make_sv_dir()
7
{
8
	[ -d "${sv_dir}" ] || mkdir -p "${sv_dir}"
9
	if [ ! -x "${sv_dir}/run" ]; then
10
		[ -n "$command_user" ] && command_prefix="chpst -u $command_user"
11
		cat > "${sv_dir}/run" << EOF
12
#!/bin/sh
13
exec 2>&1
14
exec $command_prefix $command $command_args $command_args_foreground
15
EOF
16
		chmod +x "${sv_dir}/run"
17
	fi
18
19
	[ -d "${sv_dir}/log/main" ] || mkdir -p "${sv_dir}/log/main"
20
	if [ ! -X $sv_dir/log/run ]; then
21
		cat > "${sv_dir}/log/run" << EOF
22
#!/bin/sh
23
exec svlogd -tt ${sv_dir}/log/main
24
EOF
25
		chmod +x "${sv_dir}/log/run"
26
	fi
27
}
28
29
start()
30
{
31
	make_sv_dir
32
	ebegin "starting ${RC_SVCNAME} via runit"
33
	ln -s "${sv_dir}" "${RC_SVCDIR}/runit/${RC_SVCNAME}"
34
	# Some how we need to know that the service is active
35
		eend $?
36
}
37
38
stop()
39
{
40
	ebegin "stopping ${RC_SVCNAME} via runit"
41
	rm "${RC_SVCDIR}/runit/${RC_SVCNAME}"
42
	eend $?
43
}
44
45
status()
46
{
47
	sv status "${RC_SVCDIR}/runit"
48
}
(-)a/sh/runscript.sh.in (-62 / +9 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 supervisor
147
sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
148
if [ -n "$rc_supervisor" ]; then
149
	if ! sourcex -e "@LIBEXECDIR@/sh/${rc_supervisor}.sh"; then
150
		ewarn "$rc_supervisor is an invalid value for rc_supervisor"
151
		ewarn "Using the default."
152
	fi
153
fi
154
208
# Apply any ulimit defined
155
# Apply any ulimit defined
209
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
156
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
210
157
(-)a/sh/start-stop-daemon.sh (+71 lines)
Line 0 Link Here
1
# Default start / stop / status functions
2
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
3
# Released under the 2-clause BSD license.
4
5
start()
6
{
7
	[ -n "$command" ] || return 0
8
9
	local _background=
10
	ebegin "Starting ${name:-$RC_SVCNAME}"
11
	if yesno "${command_background}"; then
12
		if [ -z "${pidfile}" ]; then
13
			eend 1 "command_background option used but no pidfile specified"
14
			return 1
15
		fi
16
		if [ -n "${command_args_background}" ]; then
17
			eend 1 "command_background used with command_args_background"
18
			return 1
19
		fi
20
		_background="--background --make-pidfile"
21
	fi
22
	if yesno "$start_inactive"; then
23
		local _inactive=false
24
		service_inactive && _inactive=true
25
		mark_service_inactive
26
	fi
27
	eval start-stop-daemon --start \
28
		--exec $command \
29
		${procname:+--name} $procname \
30
		${pidfile:+--pidfile} $pidfile \
31
		${command_user+--user} $command_user \
32
		$_background $start_stop_daemon_args \
33
		-- $command_args $command_args_background
34
	if eend $? "Failed to start $RC_SVCNAME"; then
35
		service_set_value "command" "${command}"
36
		[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
37
		[ -n "${procname}" ] && service_set_value "procname" "${procname}"
38
		return 0
39
	fi
40
	if yesno "$start_inactive"; then
41
		if ! $_inactive; then
42
			mark_service_stopped
43
		fi
44
	fi
45
	return 1
46
}
47
48
stop()
49
{
50
	local startcommand="$(service_get_value "command")"
51
	local startpidfile="$(service_get_value "pidfile")"
52
	local startprocname="$(service_get_value "procname")"
53
	command="${startcommand:-$command}"
54
	pidfile="${startpidfile:-$pidfile}"
55
	procname="${startprocname:-$procname}"
56
	[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
57
	ebegin "Stopping ${name:-$RC_SVCNAME}"
58
	start-stop-daemon --stop \
59
		${retry:+--retry} $retry \
60
		${command:+--exec} $command \
61
		${procname:+--name} $procname \
62
		${pidfile:+--pidfile} $pidfile \
63
		${stopsig:+--signal} $stopsig
64
65
	eend $? "Failed to stop $RC_SVCNAME"
66
}
67
68
status()
69
{
70
	_status
71
}

Return to bug 501364