Add pkg-message with hints on replacing init

Patch to allow running from PREFIX without copying (caveat-- must be on root
filesystem!)

Various minor runtime fixes
This commit is contained in:
Chris Rees 2016-08-11 21:06:42 +00:00
parent ae0b522276
commit aa463ad2ec
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=420105
8 changed files with 147 additions and 3 deletions

View File

@ -3,7 +3,7 @@
PORTNAME= runit
PORTVERSION= 2.1.2
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= sysutils
MASTER_SITES= http://smarden.org/${PORTNAME}/ \
http://www.bayofrum.net/dist/${PORTNAME}/
@ -18,21 +18,27 @@ USE_RC_SUBR= runsvdir
WRKSRC= ${WRKDIR}/admin/${DISTNAME}
SERVICE_DIR?= /var/service
SUB_FILES= pkg-message
SUB_LIST= SERVICE_DIR="${SERVICE_DIR}"
PORTDOCS= *
DOCS= package/CHANGES package/README \
package/THANKS doc/*.html
CONFIG= etc/freebsd/1 etc/2 etc/freebsd/3 etc/freebsd/ctrlaltdel \
etc/freebsd/getty-ttyv4/run etc/freebsd/getty-ttyv4/finish
etc/freebsd/getty-ttyv4/run etc/freebsd/getty-ttyv4/finish \
etc/freebsd/getty-ttyv4/whichtty
post-patch:
${REINPLACE_CMD} -i '' 's!/service/!${SERVICE_DIR}!' \
${WRKSRC}/man/* ${WRKSRC}/src/sv.c
${PATCH_WRKSRC}/man/* ${PATCH_WRKSRC}/src/sv.c
${REINPLACE_CMD} -i '' '\|^PATH=|s|$$|:${PREFIX}/bin:${PREFIX}/sbin|' \
${PATCH_WRKSRC}/etc/freebsd/3
${FIND} ${PATCH_WRKSRC} -name '*.orig' -delete
do-configure:
${ECHO_CMD} "${CC} ${CFLAGS}" > ${WRKSRC}/src/conf-cc
${ECHO_CMD} "${CC}" > ${WRKSRC}/src/conf-ld
${ECHO_CMD} '#define PREFIX "${PREFIX}"' >> ${WRKSRC}/src/runit.h
do-build:
cd ${WRKSRC} && package/compile && package/check

View File

@ -0,0 +1,7 @@
--- etc/freebsd/getty-ttyv4/finish 2016-07-28 16:39:47.000000000 +0100
+++ finish 2016-08-10 22:28:28.274811000 +0100
@@ -1,2 +1,3 @@
#!/bin/sh
-exec utmpset -w ttyv4
+. whichtty
+exec utmpset -w $tty

View File

@ -0,0 +1,8 @@
--- etc/freebsd/getty-ttyv4/run 2016-07-28 16:39:47.000000000 +0100
+++ run 2016-08-10 22:28:33.566527000 +0100
@@ -1,2 +1,4 @@
#!/bin/sh
-exec /usr/libexec/getty Pc ttyv4
+export TERM=xterm
+. whichtty
+exec /usr/libexec/getty Pc $tty

View File

@ -0,0 +1,8 @@
--- etc/freebsd/getty-ttyv4/whichtty 1970-01-01 01:00:00.000000000 +0100
+++ etc/freebsd/getty-ttyv4/whichtty 2016-08-10 22:34:36.558752671 +0100
@@ -0,0 +1,5 @@
+realpath=`realpath $0`
+dirname=`dirname $realpath`
+dirname=`basename $dirname`
+tty=`expr $dirname : 'getty-\(ttyv[0-9]\)'`
+[ -z "${tty%0}" ] && echo "Name of directory must be getty-ttyvx, where x is 0-9" && exit 1

View File

@ -0,0 +1,20 @@
$FreeBSD$
runit is designed to be placed in /sbin. However, there is no reason that
PREFIX cannot be respected here, so should a user define in loader.conf this
in place, then it will still be found.
init_path=/usr/local/sbin/runit-init:/sbin/init
--- src/runit-init.c.orig 2016-08-10 20:53:15 UTC
+++ src/runit-init.c
@@ -53,6 +53,9 @@ int main (int argc, const char * const *
/* kernel is starting init, runit does the job. */
execve(RUNIT, (char *const *)prog, envp);
+ /* OK, running from PREFIX-- should be default */
+ execve(PREFIX RUNIT, (char *const *)prog, envp);
+
/* serious error */
strerr_die4sys(111, FATAL, "unable to start ", prog[0], ": ");
}

View File

@ -0,0 +1,51 @@
$FreeBSD$
Should the user neglect to add the symlink, rather than stick them in a
reboot loop give a warning.
--- src/runit.c.orig 2016-08-10 21:03:05 UTC
+++ src/runit.c
@@ -22,10 +22,13 @@
#define WARNING "- runit: warning: "
#define FATAL "- runit: fatal: "
-const char * const stage[3] ={
+const char * const stage[] ={
"/etc/runit/1",
"/etc/runit/2",
- "/etc/runit/3" };
+ "/etc/runit/3",
+ PREFIX "/etc/runit/1",
+ PREFIX "/etc/runit/2",
+ PREFIX "/etc/runit/3" };
int selfpipe[2];
int sigc =0;
@@ -134,6 +137,13 @@ int main (int argc, const char * const *
strerr_warn3(INFO, "enter stage: ", stage[st], 0);
execve(*prog, (char *const *)prog, envp);
+ /* Try with PREFIX */
+ prog[0] = stage[st+3];
+ strerr_warn3(INFO,
+ "Trying in " PREFIX "; not found in /etc: ", stage[st], 0);
+ strerr_warn3(INFO,
+ "Must run ln -s " PREFIX "/etc/runit /etc/ to work!", stage[st], 0);
+ execve(*prog, (char *const *)prog, envp);
strerr_die4sys(0, FATAL, "unable to start child: ", stage[st], ": ");
}
@@ -229,6 +239,13 @@ int main (int argc, const char * const *
/* child */
strerr_warn3(INFO, "enter stage: ", prog[0], 0);
execve(*prog, (char *const *) prog, envp);
+ /* Try with PREFIX */
+ prog[0] = stage[st+3];
+ strerr_warn3(INFO,
+ "Trying in " PREFIX "; not found: ", stage[st], 0);
+ strerr_warn3(INFO,
+ "Must run ln -s " PREFIX "/etc/runit /etc/ to work!", stage[st], 0);
+ execve(*prog, (char *const *) prog, envp);
strerr_die4sys(0, FATAL, "unable to start child: ", prog[0], ": ");
}
if (wait_pid(&wstat, pid2) == -1)

View File

@ -0,0 +1,43 @@
Using runit with FreeBSD init:
# mkdir %%SERVICE_DIR%%
# cp -R %%PREFIX%%/etc/runit /etc/runit
# echo runsvdir_enable=yes >> /etc/rc.conf
runit is very easily used instead of init on FreeBSD, but the port maintainer
suggests the following alternative method (as opposed to the website method):
1. Copy all of the etc files from %%PREFIX%%/etc/runit to /etc/runit;
# cp -R %%PREFIX%%/etc/runit /etc/runit
2. Copy runit-init AND runit into /sbin;
# cp /usr/local/sbin/runit* /sbin
3. Create service directories, enable ttyv4 and disable it in ttys:
# mkdir %%SERVICE_DIR%%
# cp -R /etc/runit/getty-ttyv4 %%SERVICE_DIR%%
# sed 's/^ttyv4/#&/' /etc/ttys
(The getty-ttyvx directory will getty on whichever vtty x is on, for example
# cp -R %%SERVICE_DIR%%/getty-ttyv4 %%SERVICE_DIR%%/getty-ttyv3
will result in a tty on ttyv3 as well)
4. Don't replace FreeBSD init in place, tell loader to use runit instead:
# echo 'init_path="/sbin/runit-init:/sbin/init:/sbin/oinit:/sbin/init.bak:/rescue/init"' >> /boot/loader.conf
5. Reboot!
Note: On FreeBSD, runit-init works in %%PREFIX%%/sbin, but
*only* if %%PREFIX%%/sbin is on the same filesystem as /; check with:
# df %%PREFIX%%/sbin/runit | sed -ne 's,.* /,/,p' # If this does not return "/"
If the output is "/", you may skip step 2 and modify step 4:
# echo 'init_path="%%PREFIX%%/sbin/runit-init:/sbin/init:/sbin/oninit:/sbin/init.bak:/rescue/init"' >> /boot/loader.conf
making upgrades easier.

View File

@ -4,6 +4,7 @@
@sample %%ETCDIR%%/ctrlaltdel.sample
@sample %%ETCDIR%%/getty-ttyv4/run.sample
@sample %%ETCDIR%%/getty-ttyv4/finish.sample
@sample %%ETCDIR%%/getty-ttyv4/whichtty.sample
man/man8/chpst.8.gz
man/man8/runit-init.8.gz
man/man8/runit.8.gz