From 90c819ddbed0c272b3e273b3237ca47927859d44 Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Thu, 8 Mar 2018 05:16:46 +0000 Subject: [PATCH] New port: sysutils/runit-faster Runit is a daemontools replacement with the following features: - Service supervision - Clean process state - Reliable logging facility - Fast system bootup and shutdown - Packaging friendly - Small code size This very experimental port comes with a complete suite of configuration files and services to replace init(8) and rc(8) with runit for initializing your system. Heavily inspired by Void Linux' init scripts. For usage instructions visit: https://people.freebsd.org/~tobik/runit-faster.html Some fixes applied to sysutils/runit: - Fix most compiler warnings - Fix bug where runit will only halt the system instead of powering it off - Pet rclint for runsvdir - Pet portlint and regenerate patches --- sysutils/Makefile | 1 + sysutils/runit-faster/Makefile | 97 +++++++++++++++++++ sysutils/runit-faster/distinfo | 5 + .../runit-faster/files/patch-src_chkshsgr.c | 11 +++ .../files/patch-src_pathexec__run.c | 28 ++++++ sysutils/runit-faster/files/patch-src_prot.c | 20 ++++ sysutils/runit-faster/files/patch-src_prot.h | 15 +++ sysutils/runit-faster/files/patch-src_runit.c | 15 +++ .../runit-faster/files/patch-src_svlogd.c | 10 ++ sysutils/runit-faster/files/patch-utmpx | 90 +++++++++++++++++ sysutils/runit-faster/files/runsvdir.in | 38 ++++++++ sysutils/runit-faster/pkg-descr | 15 +++ sysutils/runit-faster/pkg-message | 2 + sysutils/runit-faster/pkg-plist | 13 +++ 14 files changed, 360 insertions(+) create mode 100644 sysutils/runit-faster/Makefile create mode 100644 sysutils/runit-faster/distinfo create mode 100644 sysutils/runit-faster/files/patch-src_chkshsgr.c create mode 100644 sysutils/runit-faster/files/patch-src_pathexec__run.c create mode 100644 sysutils/runit-faster/files/patch-src_prot.c create mode 100644 sysutils/runit-faster/files/patch-src_prot.h create mode 100644 sysutils/runit-faster/files/patch-src_runit.c create mode 100644 sysutils/runit-faster/files/patch-src_svlogd.c create mode 100644 sysutils/runit-faster/files/patch-utmpx create mode 100644 sysutils/runit-faster/files/runsvdir.in create mode 100644 sysutils/runit-faster/pkg-descr create mode 100644 sysutils/runit-faster/pkg-message create mode 100644 sysutils/runit-faster/pkg-plist diff --git a/sysutils/Makefile b/sysutils/Makefile index 705224d4355e..24ad00cc01ea 100644 --- a/sysutils/Makefile +++ b/sysutils/Makefile @@ -1078,6 +1078,7 @@ SUBDIR += rubygem-yell SUBDIR += rundeck SUBDIR += runit + SUBDIR += runit-faster SUBDIR += runwhen SUBDIR += s6 SUBDIR += s6-rc diff --git a/sysutils/runit-faster/Makefile b/sysutils/runit-faster/Makefile new file mode 100644 index 000000000000..df52e407f2e5 --- /dev/null +++ b/sysutils/runit-faster/Makefile @@ -0,0 +1,97 @@ +# Created by: Sergei Kolobov +# $FreeBSD$ + +PORTNAME= runit +DISTVERSION= 2.1.2-0.1.13 +RUNITVERSION= ${DISTVERSION:C/(.*)-(.*)/\1/} +CONFVERSION= ${DISTVERSION:C/(.*)-(.*)/\2/} +CATEGORIES= sysutils +MASTER_SITES= http://smarden.org/runit/ \ + http://www.bayofrum.net/dist/runit/ \ + LOCAL/tobik:config \ + https://pkg.tobik.me/distfiles/:config +PKGNAMESUFFIX= -faster +DISTFILES= runit-${RUNITVERSION}${EXTRACT_SUFX} \ + freebsd-runit-${CONFVERSION}${EXTRACT_SUFX}:config + +MAINTAINER= tobik@FreeBSD.org +COMMENT= Runit based init replacement for ${OPSYS} + +LICENSE= BSD3CLAUSE +LICENSE_FILE= ${WRKSRC}/package/COPYING + +RUN_DEPENDS= snooze:sysutils/snooze + +CONFLICTS_INSTALL= runit + +PLIST_SUB= RUNITDIR=${RUNITDIR} +USE_RC_SUBR= runsvdir +WRKSRC= ${WRKDIR}/admin/runit-${RUNITVERSION} + +OPTIONS_DEFINE= DOCS ROOT + +ROOT_DESC= Install bootstrap files into /etc/runit and /sbin + +PORTDOCS= * + +ROOT_VARS= RUNITDIR=/etc/runit SBINDIR=/sbin +ROOT_VARS_OFF= RUNITDIR=${PREFIX}/etc/runit SBINDIR=${PREFIX}/sbin + +post-patch: + @${REINPLACE_CMD} -e 's,/service/,/var/service,' \ + -e 's,/etc/runit,${RUNITDIR},' \ + -e 's,/sbin/runit,${SBINDIR}/runit,' \ + ${WRKSRC}/man/* ${WRKSRC}/doc/*.html \ + ${WRKSRC}/src/sv.c \ + ${WRKSRC}/src/runsvchdir.c \ + ${WRKSRC}/src/runit.c \ + ${WRKSRC}/src/runit.h + +do-configure: + @${ECHO_CMD} "${CC} ${CFLAGS}" > ${WRKSRC}/src/conf-cc + @${ECHO_CMD} "${CC}" > ${WRKSRC}/src/conf-ld + +do-build: + @cd ${WRKSRC} && package/compile + +do-install: + @${MKDIR} ${STAGEDIR}${RUNITDIR} ${STAGEDIR}${SBINDIR} + ${INSTALL_PROGRAM} ${WRKSRC}/command/* ${STAGEDIR}${SBINDIR} + ${INSTALL_MAN} ${WRKSRC}/man/*.8 ${STAGEDIR}${PREFIX}/man/man8 + @${DO_MAKE_BUILD} -C ${WRKDIR}/freebsd-runit-${CONFVERSION} \ + DESTDIR=${STAGEDIR} \ + LOCALBASE=${LOCALBASE} \ + PREFIX=${PREFIX} \ + RUNITDIR=${RUNITDIR} \ + SVDIR=${PREFIX}/etc/sv \ + install +# Point runit to the run directory (a necessity to let runit work on +# read-only root filesystems) and make sure rebooting and powering off +# can work correctly. + @${LN} -s /var/run/runit/reboot ${STAGEDIR}${RUNITDIR}/reboot + @${LN} -s /var/run/runit/stopit ${STAGEDIR}${RUNITDIR}/stopit + +do-install-DOCS-on: + @${MKDIR} ${STAGEDIR}${DOCSDIR} + cd ${WRKSRC} && ${INSTALL_DATA} \ + package/CHANGES package/README package/THANKS doc/*.html \ + ${STAGEDIR}${DOCSDIR} + +post-install: +# Micromanaging pkg-plist is no fun here... Generate it on the fly +# instead. + @${FIND} -s ${STAGEDIR}${RUNITDIR} ${STAGEDIR}${PREFIX}/etc/sv ${STAGEDIR}${SBINDIR} \ + -not -type d | ${SORT} | ${SED} \ + -e 's,^${STAGEDIR},,' \ + -e 's,^${PREFIX}/,,' \ + >> ${TMPPLIST} + @${FIND} -s ${STAGEDIR}${RUNITDIR} ${STAGEDIR}${PREFIX}/etc/sv ${STAGEDIR}${SBINDIR} \ + -type d | ${SORT} | ${SED} \ + -e 's,^${STAGEDIR},,' \ + -e 's,^${PREFIX}/,,' \ + -e 's,^,@dir ,' >> ${TMPPLIST} + +do-test: + @cd ${WRKSRC} && package/check + +.include diff --git a/sysutils/runit-faster/distinfo b/sysutils/runit-faster/distinfo new file mode 100644 index 000000000000..c09f5d89c37f --- /dev/null +++ b/sysutils/runit-faster/distinfo @@ -0,0 +1,5 @@ +TIMESTAMP = 1520485557 +SHA256 (runit-2.1.2.tar.gz) = 6fd0160cb0cf1207de4e66754b6d39750cff14bb0aa66ab49490992c0c47ba18 +SIZE (runit-2.1.2.tar.gz) = 110916 +SHA256 (freebsd-runit-0.1.13.tar.gz) = d7c7dd66f5fdd06ebf80c5348cf05796a3e0abddacc456e6955da33b88ac1fab +SIZE (freebsd-runit-0.1.13.tar.gz) = 14164 diff --git a/sysutils/runit-faster/files/patch-src_chkshsgr.c b/sysutils/runit-faster/files/patch-src_chkshsgr.c new file mode 100644 index 000000000000..d88355d58005 --- /dev/null +++ b/sysutils/runit-faster/files/patch-src_chkshsgr.c @@ -0,0 +1,11 @@ +--- src/chkshsgr.c.orig 2018-03-05 09:33:03 UTC ++++ src/chkshsgr.c +@@ -4,7 +4,7 @@ + + int main() + { +- short x[4]; ++ gid_t x[4]; + + x[0] = x[1] = 0; + if (getgroups(1,x) == 0) if (setgroups(1,x) == -1) _exit(1); diff --git a/sysutils/runit-faster/files/patch-src_pathexec__run.c b/sysutils/runit-faster/files/patch-src_pathexec__run.c new file mode 100644 index 000000000000..6dd033e247bb --- /dev/null +++ b/sysutils/runit-faster/files/patch-src_pathexec__run.c @@ -0,0 +1,28 @@ +--- src/pathexec_run.c.orig 2014-08-10 18:22:35 UTC ++++ src/pathexec_run.c +@@ -5,6 +5,7 @@ + #include "str.h" + #include "env.h" + #include "pathexec.h" ++#include + + static stralloc tmp; + +@@ -15,7 +16,7 @@ void pathexec_run(const char *file,const char * const + int savederrno; + + if (file[str_chr(file,'/')]) { +- execve(file,argv,envp); ++ execve(file,(char *const *)argv,(char *const *)envp); + return; + } + +@@ -32,7 +33,7 @@ void pathexec_run(const char *file,const char * const + if (!stralloc_cats(&tmp,file)) return; + if (!stralloc_0(&tmp)) return; + +- execve(tmp.s,argv,envp); ++ execve(tmp.s,(char *const *)argv,(char * const *)envp); + if (errno != error_noent) { + savederrno = errno; + if ((errno != error_acces) && (errno != error_perm) && (errno != error_isdir)) return; diff --git a/sysutils/runit-faster/files/patch-src_prot.c b/sysutils/runit-faster/files/patch-src_prot.c new file mode 100644 index 000000000000..be141c9119b3 --- /dev/null +++ b/sysutils/runit-faster/files/patch-src_prot.c @@ -0,0 +1,20 @@ +--- src/prot.c.orig 2018-03-05 09:31:55 UTC ++++ src/prot.c +@@ -3,7 +3,7 @@ + #include "hasshsgr.h" + #include "prot.h" + +-int prot_gid(int gid) ++int prot_gid(gid_t gid) + { + #ifdef HASSHORTSETGROUPS + short x[2]; +@@ -15,7 +15,7 @@ int prot_gid(int gid) + return setgid(gid); /* _should_ be redundant, but on some systems it isn't */ + } + +-int prot_uid(int uid) ++int prot_uid(uid_t uid) + { + return setuid(uid); + } diff --git a/sysutils/runit-faster/files/patch-src_prot.h b/sysutils/runit-faster/files/patch-src_prot.h new file mode 100644 index 000000000000..298aed099afe --- /dev/null +++ b/sysutils/runit-faster/files/patch-src_prot.h @@ -0,0 +1,15 @@ +--- src/prot.h.orig 2018-03-05 09:38:43 UTC ++++ src/prot.h +@@ -3,7 +3,10 @@ + #ifndef PROT_H + #define PROT_H + +-extern int prot_gid(int); +-extern int prot_uid(int); ++#include ++#include ++ ++extern int prot_gid(gid_t); ++extern int prot_uid(uid_t); + + #endif diff --git a/sysutils/runit-faster/files/patch-src_runit.c b/sysutils/runit-faster/files/patch-src_runit.c new file mode 100644 index 000000000000..714547c222f2 --- /dev/null +++ b/sysutils/runit-faster/files/patch-src_runit.c @@ -0,0 +1,15 @@ +--- src/runit.c.orig 2018-03-06 14:39:19 UTC ++++ src/runit.c +@@ -309,10 +309,10 @@ int main (int argc, const char * const *argv, char * c + reboot_system(RB_AUTOBOOT); + } + else { +-#ifdef RB_POWER_OFF ++#ifdef RB_POWEROFF + strerr_warn2(INFO, "power off...", 0); + sync(); +- reboot_system(RB_POWER_OFF); ++ reboot_system(RB_POWEROFF); + sleep(2); + #endif + #ifdef RB_HALT_SYSTEM diff --git a/sysutils/runit-faster/files/patch-src_svlogd.c b/sysutils/runit-faster/files/patch-src_svlogd.c new file mode 100644 index 000000000000..66e3b2f46987 --- /dev/null +++ b/sysutils/runit-faster/files/patch-src_svlogd.c @@ -0,0 +1,10 @@ +--- src/svlogd.c.orig 2014-08-10 18:22:34 UTC ++++ src/svlogd.c +@@ -430,6 +430,7 @@ unsigned int logdir_open(struct logdir *ld, const char + ld->name =(char*)fn; + ld->ppid =0; + ld->match ='+'; ++ ld->udpaddr.sin_family =AF_INET; + ld->udpaddr.sin_port =0; + ld->udponly =0; + while (! stralloc_copys(&ld->prefix, "")) pause_nomem(); diff --git a/sysutils/runit-faster/files/patch-utmpx b/sysutils/runit-faster/files/patch-utmpx new file mode 100644 index 000000000000..ede6ce74285c --- /dev/null +++ b/sysutils/runit-faster/files/patch-utmpx @@ -0,0 +1,90 @@ +Since init lacks this code in FreeBSD (utx-logout is performed in pam_lastlog) +we will simply make utmpset.c a noop if utmpx is present. + +http://lists.freebsd.org/pipermail/freebsd-ports/2011-May/067872.html + +--- src/tryuwtmpx.c.orig 2014-08-10 18:22:35 UTC ++++ src/tryuwtmpx.c +@@ -1,9 +1,9 @@ + #include + #include + +-struct futmpx ut; ++struct utmpx ut; + + int main(void) { +- char *s =ut.ut_name; ++ char *s =ut.ut_user; + return(0); + } +--- src/utmpset.c.orig 2014-08-10 18:22:35 UTC ++++ src/utmpset.c +@@ -22,6 +22,11 @@ const char *progname; + void usage(void) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } + + int utmp_logout(const char *line) { ++ ++#ifdef _UW_TMP_UTMPX ++ int ok = 1; /* do_nada(); */ ++#else /* _UW_TMP_UTMP */ ++ + int fd; + uw_tmp ut; + int ok =-1; +@@ -45,9 +50,13 @@ int utmp_logout(const char *line) { + break; + } + close(fd); ++#endif /* _UW_TMP_UTMPX */ + return(ok); + } + int wtmp_logout(const char *line) { ++#ifdef _UW_TMP_UTMPX ++ return 1; /* do_nada(); */ ++#else /* _UW_TMP_UTMP */ + int fd; + int len; + struct stat st; +@@ -79,6 +88,7 @@ int wtmp_logout(const char *line) { + } + close(fd); + return(1); ++#endif /* _UW_TMP_UTMPX */ + } + + int main (int argc, const char * const *argv, const char * const *envp) { +--- src/uw_tmp.h1.orig 2014-08-10 18:22:35 UTC ++++ src/uw_tmp.h1 +@@ -3,6 +3,8 @@ + + /* sysdep: -utmpx */ + ++#ifndef _UW_TMP_UTMP ++#define _UW_TMP_UTMP + #ifdef _PATH_UTMP + #define UW_TMP_UFILE _PATH_UTMP + #define UW_TMP_WFILE _PATH_WTMP +@@ -17,3 +19,4 @@ + #endif + + typedef struct utmp uw_tmp; ++#endif /* _UW_TMP_UTMP */ +--- src/uw_tmp.h2.orig 2014-08-10 18:22:35 UTC ++++ src/uw_tmp.h2 +@@ -3,11 +3,12 @@ + + /* sysdep: +utmpx */ + +-#define UW_TMP_UFILE _UTMPX_FILE +-#define UW_TMP_WFILE _WTMPX_FILE +- ++#ifndef _UW_TMP_UTMPX ++#define _UW_TMP_UTMPX + #ifndef ut_time + #define ut_time ut_tv.tv_sec + #endif + +-typedef struct futmpx uw_tmp; ++typedef struct utmpx uw_tmp; ++ ++#endif /* _UW_TMP_UTMPX */ diff --git a/sysutils/runit-faster/files/runsvdir.in b/sysutils/runit-faster/files/runsvdir.in new file mode 100644 index 000000000000..e2a09fa5e0ec --- /dev/null +++ b/sysutils/runit-faster/files/runsvdir.in @@ -0,0 +1,38 @@ +#!/bin/sh +# +# $FreeBSD$ +# +# PROVIDE: runsvdir +# BEFORE: SERVERS +# KEYWORD: shutdown +# +# Add the following lines to /etc/rc.conf to enable `runsvdir': +# +# runsvdir_enable="YES" +# runsvdir_path="/var/service" + +. /etc/rc.subr + +name=runsvdir +desc="starts and monitors a collection of runsv(8) processes" +rcvar=runsvdir_enable + +load_rc_config runsvdir + +: ${runsvdir_enable:=NO} +: ${runsvdir_path=/var/service} + +command="%%PREFIX%%/sbin/runsvdir" +start_cmd=runsvdir_start +stop_postcmd="%%PREFIX%%/sbin/sv exit ${runsvdir_path}/*" + +runsvdir_start() +{ + /bin/test -d ${runsvdir_path} || /bin/mkdir -p ${runsvdir_path} + /usr/bin/env -i \ + PATH=/command:%%PREFIX%%/sbin:%%PREFIX%%/bin:/sbin:/bin:/usr/sbin:/usr/bin \ + /usr/sbin/daemon -c -f \ + ${command} ${runsvdir_path} +} + +run_rc_command $1 diff --git a/sysutils/runit-faster/pkg-descr b/sysutils/runit-faster/pkg-descr new file mode 100644 index 000000000000..8feb8f74966c --- /dev/null +++ b/sysutils/runit-faster/pkg-descr @@ -0,0 +1,15 @@ +Runit is a daemontools replacement with the following features: + +- Service supervision +- Clean process state +- Reliable logging facility +- Fast system bootup and shutdown +- Packaging friendly +- Small code size + +This very experimental port comes with a complete suite of +configuration files and services to replace init(8) and rc(8) with +runit for initializing your system. Heavily inspired by Void Linux' +init scripts. + +WWW: http://smarden.org/runit/ diff --git a/sysutils/runit-faster/pkg-message b/sysutils/runit-faster/pkg-message new file mode 100644 index 000000000000..20aa262e0835 --- /dev/null +++ b/sysutils/runit-faster/pkg-message @@ -0,0 +1,2 @@ +Please see https://people.freebsd.org/~tobik/runit-faster.html for +usage intstructions. diff --git a/sysutils/runit-faster/pkg-plist b/sysutils/runit-faster/pkg-plist new file mode 100644 index 000000000000..cff8daf214a4 --- /dev/null +++ b/sysutils/runit-faster/pkg-plist @@ -0,0 +1,13 @@ +man/man8/chpst.8.gz +man/man8/runit-init.8.gz +man/man8/runit.8.gz +man/man8/runsv.8.gz +man/man8/runsvchdir.8.gz +man/man8/runsvdir.8.gz +man/man8/sv.8.gz +man/man8/svlogd.8.gz +man/man8/utmpset.8.gz +@postexec [ ! -e %%RUNITDIR%%/runsvdir/current ] && cd %%RUNITDIR%%/runsvdir && ln -s default current +@postunexec rm -f %%RUNITDIR%%/runsvdir/current +@postexec ln -sf /var/run/runit/runsvdir/current /var/service +@postunexec rm -f /var/service