sing-box.initd 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/sbin/openrc-run
  2. name=$RC_SVCNAME
  3. description="sing-box service"
  4. supervisor="supervise-daemon"
  5. command="/usr/bin/sing-box"
  6. extra_commands="checkconfig"
  7. extra_started_commands="reload"
  8. : ${SINGBOX_CONFIG:=${config:-"/etc/sing-box"}}
  9. if [ -d "$SINGBOX_CONFIG" ]; then
  10. _config_opt="-C $SINGBOX_CONFIG"
  11. elif [ -z "$SINGBOX_CONFIG" ]; then
  12. _config_opt=""
  13. else
  14. _config_opt="-c $SINGBOX_CONFIG"
  15. fi
  16. _workdir=${SINGBOX_WORKDIR:-${workdir:-"/var/lib/sing-box"}}
  17. command_args="run --disable-color
  18. -D $_workdir
  19. $_config_opt"
  20. depend() {
  21. after net dns
  22. }
  23. checkconfig() {
  24. ebegin "Checking $RC_SVCNAME configuration"
  25. sing-box check -D "$_workdir" $_config_opt
  26. eend $?
  27. }
  28. start_pre() {
  29. checkconfig
  30. }
  31. reload() {
  32. ebegin "Reloading $RC_SVCNAME"
  33. checkconfig && $supervisor "$RC_SVCNAME" --signal HUP
  34. eend $?
  35. }