opendkim.initd 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/openrc-run
  2. # Copyright 1999-2013 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. CONFFILE=/etc/opendkim/${SVCNAME}.conf
  5. depend() {
  6. use dns logger net
  7. before mta
  8. }
  9. check_cfg() {
  10. PIDFILE=$(sed -ne 's/^[[:space:]]*PidFile[[:space:]]\+//p' "${CONFFILE}")
  11. local PIDDIR="${PIDFILE%/*}"
  12. if [ ! -d "${PIDDIR}" ] ; then
  13. checkpath -q -d -o opendkim:mail -m 0755 "${PIDDIR}" || return 1
  14. fi
  15. if [ ! -f "${CONFFILE}" ] ; then
  16. eerror "Configuration file ${CONFFILE} is missing"
  17. return 1
  18. fi
  19. if [ -z "${PIDFILE}" ] ; then
  20. eerror "Configuration file needs PidFile setting - recommend adding 'PidFile /run/opendkim/${SVCNAME}.pid' to ${CONFFILE}"
  21. return 1
  22. fi
  23. if egrep -q '^[[:space:]]*Background[[:space:]]+no' "${CONFFILE}" ; then
  24. eerror "${SVCNAME} service cannot run with Background key set to yes!"
  25. return 1
  26. fi
  27. }
  28. start() {
  29. check_cfg || return 1
  30. # Remove stalled Unix socket if no other process is using it
  31. local UNIX_SOCKET=$(sed -ne 's/^[[:space:]]*Socket[[:space:]]\+\(unix\|local\)://p' "${CONFFILE}")
  32. if [ -S "${UNIX_SOCKET}" ] && ! fuser -s "${UNIX_SOCKET}"; then
  33. rm "${UNIX_SOCKET}"
  34. fi
  35. ebegin "Starting OpenDKIM"
  36. start-stop-daemon --start --pidfile "${PIDFILE}" \
  37. --exec /usr/bin/opendkim -- -x "${CONFFILE}"
  38. eend $?
  39. }
  40. stop() {
  41. check_cfg || return 1
  42. ebegin "Stopping OpenDKIM"
  43. start-stop-daemon --stop --pidfile "${PIDFILE}"
  44. eend $?
  45. }