aboutsummaryrefslogtreecommitdiffstats
path: root/community/jool-tools/jool.initd
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2019-11-09 15:48:40 +0100
committerJakub Jirutka <jakub@jirutka.cz>2019-11-09 16:07:06 +0100
commitb1c0dca45d25efc6688e675249c9201f6cfd8e75 (patch)
tree5cacdbacf5fb9f199d7b2fbd9a2910d7f0d57e83 /community/jool-tools/jool.initd
parent4c11b21fb95fe5a73a4f231a025d4762bbe6e68d (diff)
downloadaports-b1c0dca45d25efc6688e675249c9201f6cfd8e75.tar.bz2
aports-b1c0dca45d25efc6688e675249c9201f6cfd8e75.tar.xz
community/jool-tools: add init scripts for jool and jool_siit
Diffstat (limited to 'community/jool-tools/jool.initd')
-rw-r--r--community/jool-tools/jool.initd99
1 files changed, 99 insertions, 0 deletions
diff --git a/community/jool-tools/jool.initd b/community/jool-tools/jool.initd
new file mode 100644
index 0000000000..e666c45729
--- /dev/null
+++ b/community/jool-tools/jool.initd
@@ -0,0 +1,99 @@
+#!/sbin/openrc-run
+
+case "${RC_SVCNAME#*[.-]}" in
+ jool[_-]siit)
+ name="SIIT"
+ description="Stateless IP/ICMP Translator"
+ command="/usr/bin/jool_siit"
+ kmod_name="jool_siit"
+ ;;
+ *)
+ name="NAT64"
+ description="Stateful NAT64"
+ kmod_name="jool"
+ command="/usr/bin/jool"
+ ;;
+esac
+
+: ${cfgfile:="/etc/jool/$RC_SVCNAME.conf"}
+
+required_files="$cfgfile"
+
+depends() {
+ need net
+}
+
+start_pre() {
+ resolve_instance_name
+
+ # Don't load module if it's already loaded.
+ if modprobe -qn "$kmod_name" && ! modprobe -qn --first-time "$kmod_name"; then
+ return 0
+ fi
+
+ ebegin "Loading $kmod_name kernel module"
+ modprobe -q $kmod_name
+ eend $?
+}
+
+start() {
+ ebegin "Loading $name instance $instance_name"
+ $command -i "$instance_name" file handle "$cfgfile"
+ eend $?
+}
+
+stop_pre() {
+ resolve_instance_name
+}
+
+stop() {
+ case $(instance_status) in
+ Running)
+ ebegin "Unloading $name instance $instance_name"
+ $command instance remove "$instance_name"
+ eend $?
+ ;;
+ *)
+ ewarn "WARNING: $name instance $instance_name is not running"
+ return 0
+ ;;
+ esac
+}
+
+status() {
+ resolve_instance_name
+
+ case "$(instance_status)" in
+ Running)
+ einfo "status: running"
+ return 0
+ ;;
+ Dead)
+ if service_started || service_crashed; then
+ eerror "status: crashed"
+ return 32
+ else
+ einfo "status: stopped"
+ return 3
+ fi
+ ;;
+ *)
+ eerror "status: error"
+ $command -i "$instance_name" instance status >&2
+ return 32
+ ;;
+ esac
+}
+
+instance_status() {
+ $command -i "$instance_name" instance status 2>/dev/null | head -1
+}
+
+resolve_instance_name() {
+ instance_name=$(sed -En 's/.*"instance":\s*"([^"]+)".*/\1/p' "$cfgfile")
+
+ if [ -z "$instance_name" ] && [ "${RC_SVCNAME#*[.-]}" != "$RC_SVCNAME" ]; then
+ instance_name="${RC_SVCNAME#*[.-]}"
+ fi
+ : ${instance_name:="default"}
+}