diff options
-rw-r--r-- | Makefile.am | 25 | ||||
-rwxr-xr-x | bin/gentoo-run-directory | 22 | ||||
-rwxr-xr-x | system-generators/gentoo-local-generator | 53 |
3 files changed, 59 insertions, 41 deletions
diff --git a/Makefile.am b/Makefile.am index 1c6f985..b91f88c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,34 +3,21 @@ DISTCHECK_CONFIGURE_FLAGS = \ --with-systemdsystemunitdir=\$${libdir}/systemd/system \ --with-systemdutildir=\$${libdir}/systemd +# TODO: upstream that? +systemdsystemgeneratordir = $(systemdutildir)/system-generators + dist_tmpfiles_DATA = \ tmpfiles.d/gentoo-run.conf dist_systemdsystemunit_DATA = \ mounts/var-lock.mount \ mounts/var-run.mount -dist_systemdutil_SCRIPTS = \ - bin/gentoo-run-directory +dist_systemdsystemgenerator_SCRIPTS = \ + system-generators/gentoo-local-generator -systemdsystemunit_DATA = \ - services/gentoo-local.service -EXTRA_DIST = \ - services/gentoo-local.service.in DISTCLEANFILES = \ $(systemdsystemunit_DATA) -services/gentoo-local.service: services/gentoo-local.service.in - -$(systemdsystemunit_DATA): config.status - $(MKDIR_P) services - rm -f $@ $@.tmp - $(SED) \ - -e "s|@systemdutildir[@]|$(systemdutildir)|" \ - ${srcdir}/$@.in > $@.tmp - chmod a-w $@.tmp - mv $@.tmp $@ - - -EXTRA_DIST += NEWS +EXTRA_DIST = NEWS NEWS: configure.ac Makefile.am git for-each-ref refs/tags --sort '-*committerdate' \ --format '# %(tag) (%(*committerdate:short))%0a%(contents:body)' \ diff --git a/bin/gentoo-run-directory b/bin/gentoo-run-directory deleted file mode 100755 index 93970a2..0000000 --- a/bin/gentoo-run-directory +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if [ ${#} -ne 2 ]; then - echo "Synopsis: ${0} <path> .<suffix>" >&2 - exit 1 -fi - -if ! cd "${1}"; then - echo "Unable to cd into ${1}" >&2 - exit 1 -fi - -for f in ./*"${2}"; do - if [ -x "${f}" ]; then - echo "* Starting ${f}" >&2 - if ! "${f}"; then - echo "! Failed to start ${f}: ${?}" >&2 - fi - elif [ -f "${f}" ]; then - echo "* Omitting ${f} (non-executable)" >&2 - fi -done diff --git a/system-generators/gentoo-local-generator b/system-generators/gentoo-local-generator new file mode 100755 index 0000000..c232d46 --- /dev/null +++ b/system-generators/gentoo-local-generator @@ -0,0 +1,53 @@ +#!/bin/sh + +locald_dir=/etc/local.d +cd "${locald_dir}" || exit 1 + +svc_dir=/run/systemd/generator +wan_dir=${svc_dir}/multi-user.target.wants +mkdir -p "${svc_dir}" "${wan_dir}" || exit 1 + +previous= + +for f in *.start *.stop; do + case "${f}" in + *.start) + is_start=1 + fn=${f%.start} + start_cmd="/usr/bin/env ${locald_dir}/${f}" + stop_cmd=/bin/true + if [ -f "${fn}".stop ]; then + stop_cmd="/usr/bin/env ${locald_dir}/${fn}.stop" + fi + ;; + *.stop) + is_start= + fn=${locald_dir}/${f%.stop} + start_cmd=/bin/true + stop_cmd="/usr/bin/env ${f}" + ;; + esac + + # omit .stop files which have matching .start files + [ -z "${is_start}" -a -e "${fn}.start" ] && continue + + svc_file=gentoo-local-${fn}.service + + cat > "${svc_dir}/${svc_file}" <<_EOF_ +[Unit] +Description=Service for local.d/${fn}.* +After=multi-user.target graphical.target ${previous} +ConditionFileIsExecutable=${locald_dir}/${f} + +[Service] +Type=forking +RemainAfterExit=on +TimeoutSec=0 +ExecStart=${start_cmd} +ExecStop=${stop_cmd} +_EOF_ + + ln -s "../${svc_file}" "${wan_dir}/${svc_file}" + + previous=${svc_file} +done |