blob: a6b3f5f96b4ef2e2289fa6e4ba62ec8f4a472fd2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/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
# omit non-existing files ('*.start' when glob doesn't match)
[ -f "${f}" ] || continue
case "${f}" in
*.start)
is_start=1
fn=${f%.start}
# 'env' guarantees shell-like behavior when starting files.
# Especially that text files without shebangs will be
# executed via shell.
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
|