1
0

tangd.rc.in 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. #
  3. # $FreeBSD$
  4. #
  5. # Should probably in the future allow running as non-root
  6. # and enable multiple interfaces in some cleaner way.
  7. # PROVIDE: tangd
  8. # REQUIRE: NETWORKING DAEMON
  9. # KEYWORD: nojail
  10. . /etc/rc.subr
  11. name="tangd"
  12. desc="Network Presence Binding Daemon (tang)"
  13. rcvar="tangd_enable"
  14. command="/usr/local/bin/socat"
  15. load_rc_config $name
  16. : ${tangd_enable:=no}
  17. : ${tangd_ip="127.0.0.1"}
  18. : ${tangd_port="8888"}
  19. : ${tangd_jwkdir="@jwkdir@"}
  20. : ${tangd_logfile="/var/log/tang"}
  21. : ${tangd_executable="@libexecdir@/tangd"}
  22. pidfile="/var/run/${name}.pid"
  23. required_files="@libexecdir@/${name}"
  24. required_dirs="${tangd_jwkdir}"
  25. start_postcmd="${name}_poststart"
  26. _tangd_listen_args="TCP-LISTEN:${tangd_port},bind=${tangd_ip},fork"
  27. command_args="${_tangd_listen_args} SYSTEM:\"${tangd_executable} ${tangd_jwkdir} 2>> ${tangd_logfile} \" &"
  28. # Since we may not be the only socat running we can't use the built-in process
  29. # management, so we'll need to use a pid file and find the pid from unique arguments.
  30. tangd_poststart() {
  31. ps_pid=`ps ax -o pid= -o command= | grep ${_tangd_listen_args} | grep -v grep | awk '{print $1}'`
  32. if [ -z "$ps_pid" ]; then
  33. err 1 "Cannot get pid for ${command} ${command_args}"
  34. fi
  35. echo $ps_pid > ${pidfile}
  36. return $?
  37. }
  38. run_rc_command "$1"