anubis.freebsd 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. # PROVIDE: anubis
  3. # REQUIRE: DAEMON NETWORKING
  4. # KEYWORD: shutdown
  5. # Add the following lines to /etc/rc.conf.local or /etc/rc.conf to enable anubis:
  6. # anubis_enable (bool): Set to "NO" by default.
  7. # Set it to "YES" to enable anubis.
  8. # anubis_user (user): Set to "www" by default.
  9. # User to run anubis as.
  10. # anubis_group (group): Set to "www" by default.
  11. # Group to run anubis as.
  12. # anubis_bin (str): Set to "/usr/local/bin/anubis" by default.
  13. # Location of the anubis binary
  14. # anubis_args (str): Set to "" by default.
  15. # Extra flags passed to anubis.
  16. # anubis_env (str): Set to "" by default.
  17. # List of environment variables to be set before starting..
  18. # anubis_env_file (str): Set to "/etc/anubis.env" by default.
  19. # Location of a file containing environment variables.
  20. #
  21. # Closely follows the init script from https://cgit.freebsd.org/ports/tree/www/go-anubis/files/anubis.in
  22. # with a couple of adjustments for more flexible environment variable handling
  23. . /etc/rc.subr
  24. name=anubis
  25. rcvar=anubis_enable
  26. load_rc_config ${name}
  27. : ${anubis_enable="NO"}
  28. : ${anubis_user="www"}
  29. : ${anubis_group="www"}
  30. : ${anubis_bin="/usr/local/bin/anubis"}
  31. : ${anubis_args=""}
  32. : ${anubis_env=""}
  33. : ${anubis_env_file="/etc/anubis.env"}
  34. pidfile=/var/run/${name}.pid
  35. daemon_pidfile=/var/run/${name}-daemon.pid
  36. command=/usr/sbin/daemon
  37. procname=${anubis_bin}
  38. logfile=/var/log/${name}.log
  39. command_args="-c -f -R 5 -r -T ${name} -p ${pidfile} -P ${daemon_pidfile} -o ${logfile} ${procname} ${anubis_args}"
  40. start_precmd=anubis_startprecmd
  41. stop_postcmd=anubis_stoppostcmd
  42. anubis_startprecmd () {
  43. if [ ! -e ${logfile} ]; then
  44. install -o ${anubis_user} -g ${anubis_group} /dev/null ${logfile}
  45. fi
  46. if [ ! -e ${daemon_pidfile} ]; then
  47. install -o ${anubis_user} -g ${anubis_group} /dev/null ${daemon_pidfile}
  48. fi
  49. if [ ! -e ${pidfile} ]; then
  50. install -o ${anubis_user} -g ${anubis_group} /dev/null ${pidfile}
  51. fi
  52. }
  53. anubis_stoppostcmd() {
  54. if [ -f "${daemon_pidfile}" ]; then
  55. pids=$( pgrep -F ${daemon_pidfile} 2>&1 )
  56. _err=$?
  57. [ ${_err} -eq 0 ] && kill -9 ${pids}
  58. fi
  59. }
  60. run_rc_command "$1"