From 2bfede2cfe9d750d50addf8fe50ebf8109253ff1 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 28 Feb 2021 10:26:09 +0100 Subject: [PATCH] Add /lib/finit/sample.conf for initctl create Signed-off-by: Joachim Wiberg --- configure.ac | 2 ++ src/Makefile.am | 4 ++-- src/sample.conf | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/serv.c | 5 ++++- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/sample.conf diff --git a/configure.ac b/configure.ac index 85e34196..5f555a6b 100644 --- a/configure.ac +++ b/configure.ac @@ -216,6 +216,8 @@ AC_DEFINE_UNQUOTED(PLUGIN_PATH, "$plugin_path", [Finit plugin path]) AC_EXPAND_DIR(rescue_conf, "$libdir/finit/rescue.conf") AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf]) +AC_EXPAND_DIR(sample_conf, "$libdir/finit/sample.conf") +AC_DEFINE_UNQUOTED(SAMPLE_CONF, "$sample_conf", [Finit sameple.conf for initctl create]) # Generate all files AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index 952be79c..926eec6c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -EXTRA_DIST = rescue.conf cgreaper.sh +EXTRA_DIST = cgreaper.sh rescue.conf sample.conf AM_CPPFLAGS = -U_FORTIFY_SOURCE AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE if STATIC @@ -12,7 +12,7 @@ sbin_PROGRAMS = finit initctl pkglibexec_SCRIPTS = cgreaper.sh finit_pkglibdir = $(pkglibdir) -finit_pkglib_SCRIPTS = rescue.conf +finit_pkglib_SCRIPTS = rescue.conf sample.conf if WATCHDOGD pkglibexec_PROGRAMS = watchdogd diff --git a/src/sample.conf b/src/sample.conf new file mode 100644 index 00000000..39acd874 --- /dev/null +++ b/src/sample.conf @@ -0,0 +1,45 @@ +# sample.conf: template run/task/service stanza for finit +# +# The one-shot commands 'run' and 'task' are called only once per +# runlevel. Finit does not restart them when they exit. +# +# - run : wait for completion before continuing with next stanza +# - task : like run but started in background, parallell with other stanzas +# - service : supervised daemon, run in foreground, restarted if it crashes +# +# The env: is an optional path to a file with environment variables to +# adjust the behavior of daemons. Debian and Buildroot use /etc/default +# while Alpine use /etc/conf.d -- ensure your Finit is built correctly. +# The leading '-' determines if its OK to start the service even if the +# env file is missing. +# +# run [LVLS] log command ARGS -- Command +# task [LVLS] log command ARGS -- Command +# service [LVLS] log env:[-]/etc/default/daemon daemon ARGS -- Daemon daemon +# ^ ^ ^ ^ ^ ^ ^ ^ +# | | | | | | | `-- Optional description +# | | | | | | `----------- Daemon arguments +# | | | | | `-------------------------- Path to daemon +# | | | | `---------------------------------------------------- Optional env. file +# | | | `-------------------------------------------------------- Redirect output to log +# | | `--------------------------------------------------------------- Optional conditions +# | `---------------------------------------------------------------------- Optional Runlevels +# `------------------------------------------------------------------------------ Monitored application + + +# Debian GNU/Linux: start SSH daemon as soon as basic networking comes up +#service [2345] env:-/etc/default/ssh /usr/sbin/sshd -D $SSHD_OPTS -- OpenSSH daemon + +# Alpine Linux: Oneshot task to run once at bootstrap, yes pipes are possible :) +#task [S] env:/etc/conf.d/loadkmap zcat $KEYMAP | loadkmap -- Loading keymap + +# Alpine Linux: start SSH daemon with $DROPBEAR_OPTS from /etc/conf.d +#service [2345] env:-/etc/conf.d/dropbear dropbear -R -F $DROPBEAR_OPTS -- Dropbear SSH daemon + +# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager) +# Depends on syslogd having started. Redirect any output to log. +#service [2345] log acpid -f -- ACPI daemon + +# Start rsyslogd as soon as possible, should always run +# Provides pid/syslogd condition +#service [S12345] name:syslogd env:-/etc/default/rsyslog rsyslogd -n $RSYSLOGD_OPTIONS -- Reliable syslog daemon diff --git a/src/serv.c b/src/serv.c index 130ba0c0..362a6a55 100644 --- a/src/serv.c +++ b/src/serv.c @@ -263,7 +263,10 @@ static int do_edit(char *arg, int creat) return serv_list("available"); } - /* XXX: fill with template/commented-out examples */ +#ifdef SAMPLE_CONF + /* Try copying file, it may have been removed by sysop */ + copyfile(SAMPLE_CONF, fn, 0, 0); +#endif } else if (creat) warnx("the file %s already exists, falling back to edit.", fn);