[gentoo-commits] proj/openrc:master commit in: sh/, man/

2018-05-31 Thread William Hubbs
commit: 6edf516a1fe0ad4f4e8738f9fdd1bf0bc7718361
Author: Austin English  gmail  com>
AuthorDate: Wed May 30 16:11:10 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May 30 16:11:10 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6edf516a

sh/supervise-daemon.sh: use start_stop_daemon_args if supervise_daemon_args is 
undefined

 man/openrc-run.8   | 3 +++
 sh/supervise-daemon.sh | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index f9109ef3..f0750406 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -119,6 +119,9 @@ The amount of time, in milliseconds, s6-svc should wait for 
the service
 to go down when stopping the service. The default is 6.
 .It Ar start_stop_daemon_args
 List of arguments passed to start-stop-daemon when starting the daemon.
+.It Ar supervise_daemon_args
+List of arguments passed to supervise-daemon when starting the daemon.
+If undefined, start_stop_daemon_args is used as a fallback.
 .It Ar command
 Daemon to start or stop via
 .Nm start-stop-daemon

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index b600b9c6..80e0260c 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -34,7 +34,7 @@ supervise_start()
${respawn_period:+--respawn-period} $respawn_period \
${command_user+--user} $command_user \
${umask+--umask} $umask \
-   $supervise_daemon_args \
+   ${supervise_daemon_args:-${start_stop_daemon_args}} \
$command \
-- $command_args $command_args_foreground
rc=$?



[gentoo-commits] proj/openrc:master commit in: sh/, man/

2017-11-29 Thread William Hubbs
commit: ddbdb696582e9fd61995f15d6a3a53055a151e41
Author: Julien Reichardt  jrei  ch>
AuthorDate: Mon Nov 20 22:45:51 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Nov 29 21:06:06 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ddbdb696

add more variables for start-stop-daemon and supervise-daemon options

Add the following variables to expose more arguments that can be passed
to start-stop-daemon or supervise-daemon:

- directory will be passed to --chdir
- error_log will be passed to --stderr
- output_log will be passed to --stdout
- umask will be passed to umask

This is for #184.

 man/openrc-run.8| 20 
 sh/start-stop-daemon.sh |  4 
 sh/supervise-daemon.sh  |  4 
 3 files changed, 28 insertions(+)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 3f4f7e81..e1db58bd 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -157,6 +157,24 @@ use this to change the user id before
 or
 .Xr supervise-daemon 8
 launches the daemon
+.It Ar output_log
+This is the path to a file or named pipe where the standard output from
+the service will be redirected. If you are starting this service with
+.Xr start-stop-daemon 8 ,
+,  you must set
+.Pa command_background
+to true. Keep in mind that this path will be inside the chroot if the
+.Pa chroot
+variable is set.
+.It Ar error_log
+The same thing as
+.Pa output_log
+but for the standard error output.
+.It Ar directory
+.Xr start-stop-daemon 8
+and
+.Xr supervise-daemon 8
+will chdir to this directory before starting the daemon.
 .It Ar chroot
 .Xr start-stop-daemon 8
 and
@@ -201,6 +219,8 @@ used along with in_background_fake to support re-entrant 
services.
 .It Ar in_background_fake
 Space separated list of commands which should always succeed when
 in_background is yes.
+.It Ar umask
+Set the umask of the daemon.
 .Pp
 Keep in mind that eval is used to process chroot, command, command_args_*,
 command_user, pidfile and procname. This may affect how they are

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 0793b19a..35c642c0 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -44,9 +44,13 @@ ssd_start()
eval start-stop-daemon --start \
--exec $command \
${chroot:+--chroot} $chroot \
+   ${directory:+--chdir} $directory \
+   ${output_log+--stdout} $output_log \
+   ${error_log+--stderr} $error_log \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \
+   ${umask+--umask} $umask \
$_background $start_stop_daemon_args \
-- $command_args $command_args_background
if eend $? "Failed to start ${name:-$RC_SVCNAME}"; then

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index f6e599d5..b600b9c6 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -24,12 +24,16 @@ supervise_start()
# to work properly.
eval supervise-daemon "${RC_SVCNAME}" --start \
${retry:+--retry} $retry \
+   ${directory:+--chdir} $directory  \
${chroot:+--chroot} $chroot \
+   ${output_log+--stdout} ${output_log} \
+   ${error_log+--stderr} $error_log \
${pidfile:+--pidfile} $pidfile \
${respawn_delay:+--respawn-delay} $respawn_delay \
${respawn_max:+--respawn-max} $respawn_max \
${respawn_period:+--respawn-period} $respawn_period \
${command_user+--user} $command_user \
+   ${umask+--umask} $umask \
$supervise_daemon_args \
$command \
-- $command_args $command_args_foreground



[gentoo-commits] proj/openrc:master commit in: sh/, man/, /

2017-11-16 Thread William Hubbs
commit: e805c74d31113c75058d860588e83bca120decf6
Author: William Hubbs  gmail  com>
AuthorDate: Thu Nov 16 21:35:35 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Nov 16 21:35:35 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e805c74d

s6 supervisor fixes

Add the ability to force-kill a service if it does not go down
successfully. Also, adjust the default wait time for an s6 service to go
down to 60 seconds.

 man/openrc-run.8 |  5 -
 s6-guide.md  |  4 
 sh/s6.sh | 20 +++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 471f63e5..3f4f7e81 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -111,9 +111,12 @@ The path to the s6 service directory if you are monitoring 
this service
 with S6. The default is /var/svc.d/${RC_SVCNAME}.
 .It Ar s6_svwait_options_start
 The options to pass to s6-svwait when starting the service via s6.
+.It Ar s6_force_kill
+Should we force-kill this service if s6_service_timeout_stop expires
+but the service doesn't go down during shutdown? The default is yes.
 .It Ar s6_service_timeout_stop
 The amount of time, in milliseconds, s6-svc should wait for the service
-to go down when stopping the service. The default is 1.
+to go down when stopping the service. The default is 6.
 .It Ar start_stop_daemon_args
 List of arguments passed to start-stop-daemon when starting the daemon.
 .It Ar command

diff --git a/s6-guide.md b/s6-guide.md
index 52262b3c..bcc3ac28 100644
--- a/s6-guide.md
+++ b/s6-guide.md
@@ -39,6 +39,10 @@ s6_service_path - the path to the s6 service directory. The 
default is
 s6_svwait_options_start - the options to pass to s6-svwait when starting
 the service. If this is not set, s6-svwait will not be called.
 
+s6_force_kill - Should we try to force kill this service if the
+s6_service_timeout_stop timeout expires when shutting down this service?
+The default is yes.
+
 s6_service_timeout_stop - the amount of time, in milliseconds, s6-svc
 should wait for a service to go down when stopping.
 

diff --git a/sh/s6.sh b/sh/s6.sh
index d1b9c103..33c478ad 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -12,6 +12,20 @@
 
 [ -z "${s6_service_path}" ] && s6_service_path="/var/svc.d/${RC_SVCNAME}"
 
+_s6_force_kill() {
+   local pid
+   s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
+   pid="${3%)}"
+   [ -z "${pid}" ] && return 0
+   if kill -0 "${pid}" 2> /dev/null; then
+   ewarn "Sending DOWN & KILL for ${RC_SVCNAME}"
+   s6-svc -dk "${s6_service_link}"
+   sleep 1
+   kill -0 "${pid}" 2>/dev/null && return 1
+   fi
+   return 0
+}
+
 s6_start()
 {
if [ ! -d "${s6_service_path}" ]; then
@@ -41,7 +55,11 @@ s6_stop()
  fi
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Stopping ${name:-$RC_SVCNAME}"
-   s6-svc -wD -d -T ${s6_service_timeout_stop:-1} "${s6_service_link}"
+   s6-svc -d -wD -T ${s6_service_timeout_stop:-6} "${s6_service_link}"
+   set -- $(s6-svstat "${s6_service_link}")
+   [ "$1" = "up" ] && 
+   yesno "${s6_force_kill:-yes}" &&
+   _s6_force_kill "$@"
set -- $(s6-svstat "${s6_service_link}")
[ "$1" = "down" ]
eend $? "Failed to stop ${name:-$RC_SVCNAME}"



[gentoo-commits] proj/openrc:master commit in: sh/, man/, src/rc/

2017-05-09 Thread William Hubbs
commit: 3673040722b75c0a4d06fbeb272f917c7d1ea7c4
Author: William Hubbs  gmail  com>
AuthorDate: Tue May  9 23:20:52 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May  9 23:30:08 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=36730407

supervise-daemon: add a --respawn-limit option

Allow limiting the number of times supervise-daemon will attempt to respawn a
daemon once it has died to prevent infinite respawning. Also, set a
reasonable default limit (10 times in a 5 second period).

This is for issue #126.

 man/openrc-run.8  |  6 ++
 man/supervise-daemon.8| 20 
 sh/supervise-daemon.sh|  1 +
 src/rc/supervise-daemon.c | 37 -
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 25ec5b91..c7ac2ac1 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -167,6 +167,12 @@ Display name used for the above defined command.
 Process name to match when signaling the daemon.
 .It Ar stopsig
 Signal to send when stopping the daemon.
+.It Ar respawn_limit
+Respawn limit
+.Xr supervise-daemon 8
+will use for this daemon.  See
+.Xr supervise-daemon 8
+for more information about this setting.
 .It Ar retry
 Retry schedule to use when stopping the daemon. It can either be a
 timeout in seconds or multiple signal/timeout pairs (like SIGTERM/5).

diff --git a/man/supervise-daemon.8 b/man/supervise-daemon.8
index 06087675..43e74ef7 100644
--- a/man/supervise-daemon.8
+++ b/man/supervise-daemon.8
@@ -34,6 +34,8 @@
 .Ar user
 .Fl r , -chroot
 .Ar chrootpath
+.Fl R , -respawn-limit
+.Ar limit
 .Fl 1 , -stdout
 .Ar logfile
 .Fl 2 , -stderr
@@ -99,6 +101,24 @@ Modifies the scheduling priority of the daemon.
 .It Fl r , -chroot Ar path
 chroot to this directory before starting the daemon. All other paths, such
 as the path to the daemon, chdir and pidfile, should be relative to the chroot.
+.It Fl R , -respawn-limit Ar limit
+Control how agressively
+.Nm
+will try to respawn a daemon when it fails to start. The limit argument
+can be a pair of integers separated bya colon or the string unlimited.
+.Pp
+If a pair of integers is given, the first is a maximum number of respawn
+attempts and the second is a time period. It should be interpreted as:
+If the daemon dies and has to be respawned more than 
+times in any time period of  seconds, exit and give up.
+.Pp
+For example, the default is 10:5.
+This means if the supervisor respawns a daemon more than ten times
+in any 5 second period, it gives up and exits.
+.Pp
+if unlimited is given as the limit, it means that the supervisor will
+not exit or give up, no matter how many times the daemon it is
+supervising needs to be respawned.
 .It Fl u , -user Ar user
 Start the daemon as the specified user.
 .It Fl 1 , -stdout Ar logfile

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index bff68a4c..c6130edb 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -25,6 +25,7 @@ supervise_start()
eval supervise-daemon --start \
${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
+   ${respawn_limit:+--respawn-limit} $respawn_limit \
${command_user+--user} $command_user \
$supervise_daemon_args \
$command \

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 2080e4a6..bd24d782 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -66,7 +66,7 @@ static struct pam_conv conv = { NULL, NULL};
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "d:e:g:I:Kk:N:p:r:Su:1:2:" \
+const char *getoptstring = "d:e:g:I:Kk:N:p:r:R:Su:1:2:" \
getoptstring_COMMON;
 const struct option longopts[] = {
{ "chdir",1, NULL, 'd'},
@@ -79,6 +79,7 @@ const struct option longopts[] = {
{ "pidfile",  1, NULL, 'p'},
{ "user", 1, NULL, 'u'},
{ "chroot",   1, NULL, 'r'},
+   { "respawn-limit",1, NULL, 'R'},
{ "start",0, NULL, 'S'},
{ "stdout",   1, NULL, '1'},
{ "stderr",   1, NULL, '2'},
@@ -95,6 +96,7 @@ const char * const longopts_help[] = {
"Match pid found in this file",
"Change the process user",
"Chroot to this directory",
+   "set a respawn limit",
"Start daemon",
"Redirect stdout to file",
"Redirect stderr to file",
@@ -424,7 +426,13 @@ int main(int argc, char **argv)
char *p;
char *token;
int i;
+   int n;
char exec_file[PATH_MAX];
+   int respawn_count = 0;
+   int respawn_max = 10;
+   int respawn_period = 5;
+   time_t respawn_now= 0;
+   time_t first_spawn= 0;
struct passwd *pw;
struct group *gr;
FILE *fp;
@@ -519,6 +527,17 @@ int main(int argc, char **argv)
  

[gentoo-commits] proj/openrc:master commit in: sh/, man/

2015-12-03 Thread William Hubbs
commit: 627e925463068e754ffd869f99a43634d6d9631e
Author: William Hubbs  gmail  com>
AuthorDate: Thu Dec  3 20:09:38 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Dec  3 22:52:15 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=627e9254

add support for -containers keyword

 man/openrc-run.8  |  3 +++
 sh/gendepends.sh.in   | 13 -
 sh/openrc-run.sh.in   | 13 -
 sh/rc-functions.sh.in | 21 +
 4 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 6aab067..5d18fe5 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -227,6 +227,9 @@ Same as -jail, but for Xen DOM0 systems.
 Same as -jail, but for Xen DOMU systems.
 .It Dv -docker
 Same as -jail, but for docker systems.
+.It Dv -containers
+Same as -jail, but for all relevant container types on the operating
+system.
 .El
 .El
 .Pp

diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
index 36caeb7..2ab798d 100644
--- a/sh/gendepends.sh.in
+++ b/sh/gendepends.sh.in
@@ -29,7 +29,18 @@ provide() {
[ -n "$*" ] && echo "$RC_SVCNAME iprovide $*" >&3
 }
 keyword() {
-   [ -n "$*" ] && echo "$RC_SVCNAME keyword $*" >&3
+   local c x
+   set -- $*
+   while [ -n "$*" ]; do
+   case "$1" in
+   -containers) x="$(_get_containers)" ;;
+   !-containers) x="$(_get_containers_remove)" ;;
+   *) x=$1 ;;
+   esac
+   c="${c}${x} "
+   shift
+   done
+   [ -n "$c" ] && echo "$RC_SVCNAME keyword $c" >&3
 }
 depend() {
:

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index c169204..5018cee 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -79,7 +79,18 @@ provide() {
[ -n "$*" ] && echo "provide $*"
 }
 keyword() {
-   [ -n "$*" ] && echo "keyword $*"
+   local c x
+   set -- $*
+   while [ -n "$*" ]; do
+   case "$1" in
+   -containers) x="$(_get_containers)" ;;
+   !-containers) x="$(_get_containers_remove)" ;;
+   *) x=$1 ;;
+   esac
+   c="${c}${x} "
+   shift
+   done
+   [ -n "$c" ] && echo "keyword $c"
 }
 
 # Describe the init script to the user

diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in
index c854876..12eb4e2 100644
--- a/sh/rc-functions.sh.in
+++ b/sh/rc-functions.sh.in
@@ -86,6 +86,27 @@ get_bootparam()
 }
 
 # Called from openrc-run.sh or gendepends.sh
+_get_containers() {
+   local c
+   case "${RC_UNAME}" in
+   FreeBSD)
+   c="-jail"
+   ;;
+   Linux)
+   c="-docker -lxc -openvz -rkt -systemd-nspawn -uml -vserver"
+   ;;
+   esac
+   echo $c
+}
+
+_get_containers_remove() {
+   local c
+   for x in $(_get_containers); do
+   c="${c}!${x} "
+   done
+   echo $c
+}
+
 _depend() {
depend
local _rc_svcname=$(shell_var "$RC_SVCNAME") _deptype= _depends=



[gentoo-commits] proj/openrc:master commit in: sh/, man/, /

2015-05-14 Thread William Hubbs
commit: b79d058f162d8b49ccc968744e7cb1b7a7ba729c
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Thu May 14 16:40:29 2015 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Thu May 14 16:40:29 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b79d058f

s6: Use s6-svc -Dd to stop services

This allows us to get rid of the sleep call in the stop function. Also,
we set a configurable timeout value for stopping daemons.

 man/openrc-run.8 |  5 +++--
 s6-guide.md  | 20 ++--
 sh/s6.sh |  6 +-
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 0a9f5bc..f08ad79 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -117,8 +117,9 @@ The path to the s6 service directory if you are monitoring 
this service
 with S6. The default is /var/svc.d/${RC_SVCNAME}.
 .It Ar s6_svwait_options_start
 The options to pass to s6-svwait when starting the service via s6.
-.It Ar s6_svwait_options_stop
-The options to pass to s6-svwait when stopping the service via s6.
+.It Ar s6_service_timeout_stop
+The amount of time, in milliseconds, s6-svc should wait for the service
+to go down when stopping the service. The default is 1.
 .It Ar start_stop_daemon_args
 List of arguments passed to start-stop-daemon when starting the daemon.
 .It Ar command

diff --git a/s6-guide.md b/s6-guide.md
index 9a09e32..63c63de 100644
--- a/s6-guide.md
+++ b/s6-guide.md
@@ -33,22 +33,14 @@ supervisor=s6
 Several other variables affect s6 services. They are documented on the
 openrc-run man page, but I will list them here for convenience:
 
-s6_service_path - the path to the s6 service directory
-s6_svwait_options_start - the options to pass to s6-svwait when starting
-s6_svwait_options_stop - the options to pass to s6-svwait when stopping.
-
-The s6_service_path variable defaults to /var/svc.d/${RC_SVCNAME} if it
-is not set in the service script. For example, if you want a service
-script called /etc/init.d/foobar to use s6 to monitor its daemon, the s6
-service should be the directory /var/svc.d/foobar.
+s6_service_path - the path to the s6 service directory. The default is
+/var/svc.d/$RC_SVCNAME.
 
-See the documentation for s6 for more information about s6 service
-directories.
+s6_svwait_options_start - the options to pass to s6-svwait when starting
+the service. If this is not set, s6-svwait will not be called.
 
-The s6_svwait_options_* variables set command line options to pass to
-s6-svwait when starting or stopping the s6 service. These can be very
-useful for waiting for s6 services to signal when they are up, timing out
-when an s6 service doesn't come up, etc.
+s6_service_timeout_stop - the amount of time, in milliseconds, s6-svc
+should wait for a service to go down when stopping.
 
 This is very early support, so feel free to file bugs if you have
 issues.

diff --git a/sh/s6.sh b/sh/s6.sh
index a99fd5b..99aba3f 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -31,11 +31,7 @@ s6_stop()
  fi
s6_service_link=${RC_SVCDIR}/s6-scan/${s6_service_path##*/}
ebegin Stopping ${name:-$RC_SVCNAME}
-   s6-svc -d ${s6_service_link}
-   if [ -n $s6_svwait_options_stop ]; then
-   s6-svwait ${s6_svwait_options_stop} ${s6_service_link}
-   fi
-   sleep 1.5
+   s6-svc -Dd -T ${s6_service_timeout_stop:-1} ${s6_service_link}
set -- $(s6-svstat ${s6_service_link})
[ $1 = down ]
eend $? Failed to stop $RC_SVCNAME



[gentoo-commits] proj/openrc:master commit in: sh/, man/, /

2015-05-13 Thread William Hubbs
commit: e372f97bebd4866633ad56aa5d5b1ae59fa88118
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Wed May 13 19:47:35 2015 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Wed May 13 21:10:08 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e372f97b

Fix the s6 handling

This changes the default s6 service directory to /var/svc.d, also
it changes the code to work with the individual services instead of
forcing a rescan when a service is started or stopped.

 man/openrc-run.8 |  2 +-
 s6-guide.md  |  4 ++--
 sh/s6.sh | 34 ++
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 259d23f..0a9f5bc 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -114,7 +114,7 @@ in this release is S6 from Skarnet software. To use this, 
set
 supervisor=s6.
 .It Ar s6_service_path
 The path to the s6 service directory if you are monitoring this service
-with S6. The default is /etc/svc.d/${RC_SVCNAME}.
+with S6. The default is /var/svc.d/${RC_SVCNAME}.
 .It Ar s6_svwait_options_start
 The options to pass to s6-svwait when starting the service via s6.
 .It Ar s6_svwait_options_stop

diff --git a/s6-guide.md b/s6-guide.md
index 4a37a9c..9a09e32 100644
--- a/s6-guide.md
+++ b/s6-guide.md
@@ -37,10 +37,10 @@ s6_service_path - the path to the s6 service directory
 s6_svwait_options_start - the options to pass to s6-svwait when starting
 s6_svwait_options_stop - the options to pass to s6-svwait when stopping.
 
-The s6_service_path variable defaults to /etc/svc.d/${RC_SVCNAME} if it
+The s6_service_path variable defaults to /var/svc.d/${RC_SVCNAME} if it
 is not set in the service script. For example, if you want a service
 script called /etc/init.d/foobar to use s6 to monitor its daemon, the s6
-service should be the directory /etc/svc.d/foobar.
+service should be the directory /var/svc.d/foobar.
 
 See the documentation for s6 for more information about s6 service
 directories.

diff --git a/sh/s6.sh b/sh/s6.sh
index 780beab..01527b6 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -2,7 +2,7 @@
 # Copyright (c) 2015 William Hubbs w.d.hu...@gmail.com
 # Released under the 2-clause BSD license.
 
-[ -z ${s6_service_path} ]  s6_service_path=/etc/svc.d/${RC_SVCNAME}
+[ -z ${s6_service_path} ]  s6_service_path=/var/svc.d/${RC_SVCNAME}
 
 s6_start()
 {
@@ -10,16 +10,17 @@ s6_start()
eerror ${s6_service_path} does not exist.
return 1
  fi
-   local rc
+   s6_service_link=${RC_SVCDIR}/s6-scan/${s6_service_path##*/}
ebegin Starting ${name:-$RC_SVCNAME}
-   ln -sf ${s6_service_path} ${RC_SVCDIR}/s6-scan
-   s6-svscanctl -an ${RC_SVCDIR}/s6-scan
-   rc=$?
+   ln -sf ${s6_service_path} ${s6_service_link}
+   s6-svc -u ${s6_service_link}
if [ -n $s6_svwait_options_start ]; then
-   s6-svwait ${s6_svwait_options_start} ${s6_service_path}
-   rc=$?
+   s6-svwait ${s6_svwait_options_start} ${s6_service_link}
fi
-   eend $rc Failed to start $RC_SVCNAME
+   sleep 1.5
+   set -- $(s6-svstat ${s6_service_link})
+   [ $1 = up ]
+   eend $? Failed to start $RC_SVCNAME
 }
 
 s6_stop()
@@ -28,19 +29,20 @@ s6_stop()
eerror ${s6_service_path} does not exist.
return 1
  fi
-   local rc
+   s6_service_link=${RC_SVCDIR}/s6-scan/${s6_service_path##*/}
ebegin Stopping ${name:-$RC_SVCNAME}
-   rm -rf ${RC_SVCDIR}/s6-scan/${s6_service_path##*/}
-   s6-svscanctl -an ${RC_SVCDIR}/s6-scan
-   rc=$? 
+   s6-svc -d ${s6_service_link}
if [ -n $s6_svwait_options_stop ]; then
-   s6-svwait ${s6_svwait_options_stop} ${s6_service_path}
-   rc=$?
+   s6-svwait ${s6_svwait_options_stop} ${s6_service_link}
fi
-   eend $rc Failed to stop $RC_SVCNAME
+   sleep 1.5
+   set -- $(s6-svstat ${s6_service_link})
+   [ $1 = down ]  rm -fr ${s6_service_link}
+   eend $? Failed to stop $RC_SVCNAME
 }
 
 s6_status()
 {
-   s6-svstat ${s6_service_path}
+   s6_service_link=${RC_SVCDIR}/s6-scan/${s6_service_path##*/}
+   s6-svstat ${s6_service_link}
 }



[gentoo-commits] proj/openrc:master commit in: sh/, man/

2014-10-20 Thread William Hubbs
commit: 8c7ea4e9e8da500877a514402bbe90aababda2d6
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Mon Oct 20 00:36:57 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Mon Oct 20 20:44:19 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=8c7ea4e9

runscript.sh: add chroot support

This adds support for a chroot variable which will be passed to the
start-stop-daemon --chroot switch to runscript.sh when starting a
daemon. This also needs to be saved so it can be used in locating the
pid file when stopping the daemon.

X-Gentoo-Bug: 524388
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524388

---
 man/openrc-run.8   | 3 +++
 sh/runscript.sh.in | 6 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index c8bf24d..3308f24 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -120,6 +120,9 @@ Set this to true, yes or 1 (case-insensitive) to 
force the daemon into
 the background. This implies the --make-pidfile and --pidfile option of
 .Xr start-stop-daemon 8
 so the pidfile variable must be set.
+.It Ar chroot
+.Xr start-stop-daemon 8
+will chroot into this path before writing the pid file or starting the daemon.
 .It Ar pidfile
 Pidfile to use for the above defined command.
 .It Ar name

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index b89c460..06d51d0 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -142,12 +142,14 @@ start()
fi
eval start-stop-daemon --start \
--exec $command \
+   ${chroot:+--chroot} $chroot \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
$_background $start_stop_daemon_args \
-- $command_args
if eend $? Failed to start $RC_SVCNAME; then
service_set_value command ${command}
+   [ -n ${chroot} ]  service_set_value chroot ${chroot}
[ -n ${pidfile} ]  service_set_value pidfile ${pidfile}
[ -n ${procname} ]  service_set_value procname 
${procname}
return 0
@@ -163,9 +165,11 @@ start()
 stop()
 {
local startcommand=$(service_get_value command)
+   local startchroot=$(service_get_value chroot)
local startpidfile=$(service_get_value pidfile)
local startprocname=$(service_get_value procname)
command=${startcommand:-$command}
+   chroot=${startchroot:-$chroot}
pidfile=${startpidfile:-$pidfile}
procname=${startprocname:-$procname}
[ -n $command -o -n $procname -o -n $pidfile ] || return 0
@@ -174,7 +178,7 @@ stop()
${retry:+--retry} $retry \
${command:+--exec} $command \
${procname:+--name} $procname \
-   ${pidfile:+--pidfile} $pidfile \
+   ${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
eend $? Failed to stop $RC_SVCNAME
 }