2021-01-11 13:10:55 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2021-10-30 08:40:01 +00:00
|
|
|
os="$(cat "${__global}/explorer/os")"
|
|
|
|
case "${os}" in
|
|
|
|
debian|devuan)
|
|
|
|
svdir="/etc/service"
|
|
|
|
;;
|
|
|
|
*bsd)
|
|
|
|
svdir="/var/service"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Your OS '${OS}' is currently not supported." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-01-11 13:10:55 +00:00
|
|
|
sv="${__object_id}"
|
2021-10-30 08:40:01 +00:00
|
|
|
state="$(cat "${__object}/parameter/state")"
|
2021-01-11 13:10:55 +00:00
|
|
|
run_file="${svdir}/${sv}/run"
|
|
|
|
|
|
|
|
source="$(cat "$__object/parameter/source")"
|
|
|
|
if [ "$source" = "-" ]; then
|
|
|
|
source="$__object/stdin"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create this service's directory
|
|
|
|
__directory --state "${state}" "${svdir}/${sv}"
|
|
|
|
|
|
|
|
export require="__directory${svdir}/${sv}"
|
|
|
|
|
2021-10-30 08:40:01 +00:00
|
|
|
if [ "${state}" != "present" ]; then
|
|
|
|
# We are done here, the service gets removed
|
|
|
|
exit
|
|
|
|
fi
|
2021-01-11 13:10:55 +00:00
|
|
|
|
|
|
|
if [ -f "${__object}/parameter/log" ]; then
|
|
|
|
# Setup logger if requested
|
|
|
|
__directory --parents "${svdir}/${sv}/log/main"
|
|
|
|
export require="${require} __directory${svdir}/${sv}/log/main"
|
|
|
|
__file "${svdir}/${sv}/log/run" \
|
|
|
|
--state "${state}" \
|
|
|
|
--mode 0755 \
|
|
|
|
--source "-" <<EOF
|
|
|
|
#!/bin/sh
|
|
|
|
exec svlogd -tt ./main
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Setup run file
|
|
|
|
__file --state "${state}" --mode 0755 --source "${source}" "${run_file}"
|