#!/bin/sh /etc/rc.common
# procd init file for OpenWrt service

START=99
USE_PROCD=1

_PID_FILE=/var/run/hetzner_ddns.pid

fix_permissions() {
         touch "${_PID_FILE}"

         chown nobody:nogroup "${_PID_FILE}"

         chmod u+w "${_PID_FILE}"
}

start_service() {
         fix_permissions
         procd_open_instance [hetzner_ddns]
         procd_set_param command /usr/bin/hetzner_ddns -V -c /etc/config/hetzner_ddns.json

         # respawn automatically if something died, be careful if you have an alternative process supervisor
         # if process exits sooner than respawn_threshold, it is considered crashed and after 5 retries the service is stopped
         # if process finishes later than respawn_threshold, it is restarted unconditionally, regardless of error code
         # notice that this is literal respawning of the process, not in a respawn-on-failure sense
         procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}

         procd_set_param limits core="0"
         procd_set_param file /etc/config/hetzner_ddns.json
         procd_set_param stdout 1
         procd_set_param stderr 1
         procd_set_param user nobody
         procd_set_param pidfile /var/run/hetzner_ddns.pid
         procd_close_instance
}
