You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
948 B

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2021 Tianling Shen <cnsztl@immortalwrt.org>
  3. USE_PROCD=1
  4. START=99
  5. CONF="cloudflared"
  6. PROG="/usr/bin/cloudflared"
  7. append_param_arg() {
  8. local value
  9. config_get value "config" "$1" $2
  10. [ -n "$value" ] && procd_append_param command "--$1" "$value"
  11. }
  12. start_service() {
  13. config_load "$CONF"
  14. local enabled
  15. config_get_bool enabled "config" "enabled"
  16. [ "$enabled" -eq "1" ] || exit 1
  17. procd_open_instance "$CONF"
  18. procd_set_param command "$PROG" "tunnel"
  19. procd_append_param command "--no-autoupdate"
  20. append_param_arg "config" "/etc/cloudflared/config.yml"
  21. append_param_arg "origincert" "/etc/cloudflared/cert.pem"
  22. append_param_arg "region"
  23. append_param_arg "loglevel"
  24. append_param_arg "logfile"
  25. procd_append_param command "run"
  26. procd_set_param respawn
  27. procd_set_param stderr 1
  28. procd_close_instance
  29. }
  30. reload_service() {
  31. stop
  32. start
  33. }
  34. service_triggers() {
  35. procd_add_reload_trigger "$CONF"
  36. }