diff options
author | Michał Górny <mgorny@gentoo.org> | 2013-08-01 18:08:48 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2013-08-01 18:21:24 +0200 |
commit | c60d39fc6d5222d9773179faf42c34a3217e9146 (patch) | |
tree | b7f2a53e438541f5237d6cf5182a6b267724d0fb /system-generators/gentoo-local-generator | |
parent | Initial version of local.d support. (diff) | |
download | gentoo-systemd-integration-c60d39fc6d5222d9773179faf42c34a3217e9146.tar.gz gentoo-systemd-integration-c60d39fc6d5222d9773179faf42c34a3217e9146.tar.bz2 gentoo-systemd-integration-c60d39fc6d5222d9773179faf42c34a3217e9146.zip |
Switch local.d support to a generator.
Diffstat (limited to 'system-generators/gentoo-local-generator')
-rwxr-xr-x | system-generators/gentoo-local-generator | 53 |
1 files changed, 53 insertions, 0 deletions
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 |