diff options
| author | Joe Carstairs <me@joeac.net> | 2026-08-12 11:05:38 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-08-12 11:05:38 +0100 |
| commit | 9bb0b7bab5e7d2bc441e65250c35f34e7975583f (patch) | |
| tree | 586ab510cd0c82b059546b10c3cbd9a812e7ec9f /ansible/roles/mox/templates | |
| parent | 0b0ce5e0a3a95e3a902f193b344a3891d255a93e (diff) | |
mox service waits for global ipv6
Diffstat (limited to 'ansible/roles/mox/templates')
| -rw-r--r-- | ansible/roles/mox/templates/openrc/mox | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/ansible/roles/mox/templates/openrc/mox b/ansible/roles/mox/templates/openrc/mox new file mode 100644 index 0000000..e04d96a --- /dev/null +++ b/ansible/roles/mox/templates/openrc/mox @@ -0,0 +1,77 @@ +#!/sbin/openrc-run + +description="Run mox email server" +extra_commands="configtest" +description_configtest="Check configuration via \"mox config test\"" + +configtest() +{ + if ! [ -f ~mox/config/mox.conf ]; then + eerror "The config file ~mox/config/mox.conf does not exist!" + return 1 + fi + cd ~mox + if mox config test >&/dev/null; then + einfo "config: ok" + else + eerror "config: error" + return 1 + fi +} + +depend() +{ + need net unbound +} + +start_pre() { + ebegin "Waiting for global IPv6 address {{ ansible_facts.default_ipv6.address }} to be ready" + + local i=0 + while [ "$i" -lt 30 ]; do + if ip -6 addr show scope global | grep -q "{{ ansible_facts.default_ipv6.address }}" && \ + ! ip -6 addr show scope global | grep -q "{{ ansible_facts.default_ipv6.address }}.*\btentative\b" + then + eend 0 + return 0 + fi + sleep 2 + i=$((i + 2)) + done + + eend 1 "Global IPv6 address {{ ansible_facts.default_ipv6.address }} not ready after 30 seconds" + return 1 +} + +start() +{ + configtest || return 1 + ebegin "Starting mox" + start-stop-daemon --start \ + --exec /usr/bin/mox \ + --background \ + --chdir ~mox \ + --stdout /var/log/mox.log \ + --stderr /var/log/mox.log \ + --make-pidfile \ + --pidfile /run/mox.pid \ + -- serve + eend $? +} + +stop() +{ + ebegin "Stopping mox" + start-stop-daemon --stop \ + --exec /usr/bin/mox \ + --pidfile /run/mox.pid + eend $? +} + +restart() +{ + ebegin "Restarting mox" + svc_stop + svc_start + eend $? +} |
