gnunet.initd 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2016 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. if [ -d /run ] ; then
  5. PIDFILE=${PIDFILE:-/run/gnunet/arm-service.pid}
  6. else
  7. PIDFILE=${PIDFILE:-/var/run/gnunet/arm-service.pid}
  8. fi
  9. depend() {
  10. # FIXME: refine?
  11. need net
  12. }
  13. GNUNET_PATH="/usr"
  14. GNUNET_HOME="/var/lib/gnunet"
  15. SUID_ROOT_HELPERS="exit nat-server nat-client transport-bluetooth transport-wlan vpn"
  16. chmodown_execbin() {
  17. if [ -x $1 ]; then
  18. if [ "$3" ]; then
  19. chown $3 $1 2>/dev/null && chmod $2 $1
  20. else
  21. chmod $2 $1
  22. fi
  23. fi
  24. }
  25. checkconfig() {
  26. if [ -n "$(find ${GNUNET_HOME}/.local/share/gnunet -maxdepth 1 -name gnunet.conf -perm +0044)" ] ; then
  27. eerror "${conf} must not be world or group readable. Try:"
  28. eerror " chmod 600 ${conf}"
  29. eerror " chown gnunet:gnunet ${conf}"
  30. return 1
  31. fi
  32. mkdir -p ${GNUNET_HOME}/.cache/gnunet
  33. # taken from dangole's lede config.. thx!
  34. local libexec="${GNUNET_PATH}/lib/gnunet/libexec" # why not /usr/libexec/gnunet ?
  35. # not reliable enough:
  36. #[ -e ${libexec}/.permfix ] && return
  37. for helper in $SUID_ROOT_HELPERS; do
  38. chmodown_execbin ${libexec}/gnunet-helper-$helper u+s
  39. done
  40. chmodown_execbin ${libexec}/gnunet-helper-dns 4750 root:gnunetdns
  41. chmodown_execbin ${libexec}/gnunet-service-dns 2750 gnunet:gnunetdns
  42. #touch ${libexec}/.permfix
  43. }
  44. start() {
  45. checkconfig || return 1
  46. local piddir=$(dirname ${PIDFILE})
  47. if [ ! -d ${piddir} ] ; then
  48. ebegin "Making ${piddir}"
  49. mkdir -p ${piddir}
  50. eend $?
  51. ebegin "Changing permissions of ${piddir}"
  52. chown gnunet:gnunet ${piddir}
  53. eend $?
  54. fi
  55. ebegin "Starting ${SVCNAME}"
  56. # shouldn't be necessary... but
  57. start-stop-daemon --start --user gnunet --name gnunet --pidfile ${PIDFILE} \
  58. --exec ${GNUNET_PATH}/lib/gnunet/libexec/gnunet-service-arm -- -d
  59. # flags to be passed to the process appear after the double-dash
  60. eend $?
  61. }
  62. stop() {
  63. ebegin "Stopping ${SVCNAME}"
  64. start-stop-daemon --stop --signal QUIT --pidfile ${PIDFILE}
  65. sleep 1
  66. killall -u gnunet
  67. sleep 1
  68. rm -rf /tmp/gnunet-gnunet-runtime >/dev/null 2>&1
  69. rm -rf /tmp/gnunet-system-runtime >/dev/null 2>&1
  70. eend $?
  71. }