/rc6.d/K50proftpd

http://github.com/brinkman83/bashrc · Shell · 225 lines · 178 code · 26 blank · 21 comment · 39 complexity · 2ea714226195edc7e933e367fd8dfe74 MD5 · raw file

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: proftpd
  4. # Required-Start: $syslog $local_fs $network
  5. # Required-Stop: $syslog $local_fs $network
  6. # Should-Start: $remote_fs $named
  7. # Should-Stop: $remote_fs $named
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: Starts ProFTPD daemon
  11. # Description: This script runs the FTP service offered
  12. # by the ProFTPD daemon
  13. ### END INIT INFO
  14. # Start the proftpd FTP daemon.
  15. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  16. DAEMON=/usr/sbin/proftpd
  17. NAME=proftpd
  18. # Defaults
  19. RUN="no"
  20. OPTIONS=""
  21. PIDFILE=`grep -i 'pidfile' /etc/proftpd/proftpd.conf | sed -e 's/pidfile[\t ]\+//i'`
  22. if [ "x$PIDFILE" = "x" ];
  23. then
  24. PIDFILE=/var/run/proftpd.pid
  25. fi
  26. # Read config (will override defaults)
  27. [ -r /etc/default/proftpd ] && . /etc/default/proftpd
  28. trap "" 1
  29. trap "" 15
  30. test -f $DAEMON || exit 0
  31. . /lib/lsb/init-functions
  32. #
  33. # Servertype could be inetd|standalone|none.
  34. # In all cases check against inetd and xinetd support.
  35. #
  36. if ! egrep -qi "^[[:space:]]*ServerType.*standalone" /etc/proftpd/proftpd.conf
  37. then
  38. if [ $(dpkg-divert --list xinetd|wc -l) -eq 1 ]
  39. then
  40. if egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.conf 2>/dev/null || \
  41. egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.d/* 2>/dev/null
  42. then
  43. RUN="no"
  44. INETD="yes"
  45. else
  46. if ! egrep -qi "^[[:space:]]*ServerType.*inetd" /etc/proftpd/proftpd.conf
  47. then
  48. RUN="yes"
  49. INETD="no"
  50. else
  51. RUN="no"
  52. INETD="no"
  53. fi
  54. fi
  55. else
  56. if egrep -qi "^ftp.*/usr/sbin/proftpd" /etc/inetd.conf 2>/dev/null
  57. then
  58. RUN="no"
  59. INETD="yes"
  60. else
  61. if ! egrep -qi "^[[:space:]]*ServerType.*inetd" /etc/proftpd/proftpd.conf
  62. then
  63. RUN="yes"
  64. INETD="no"
  65. else
  66. RUN="no"
  67. INETD="no"
  68. fi
  69. fi
  70. fi
  71. fi
  72. # /var/run could be on a tmpfs
  73. [ ! -d /var/run/proftpd ] && mkdir /var/run/proftpd
  74. start()
  75. {
  76. log_daemon_msg "Starting ftp server" "$NAME"
  77. start-stop-daemon --start --quiet --pidfile "$PIDFILE" --oknodo --exec $DAEMON -- $OPTIONS
  78. if [ $? != 0 ]; then
  79. log_end_msg 1
  80. exit 1
  81. else
  82. log_end_msg 0
  83. fi
  84. }
  85. signal()
  86. {
  87. if [ "$1" = "stop" ]; then
  88. SIGNAL="TERM"
  89. log_daemon_msg "Stopping ftp server" "$NAME"
  90. else
  91. if [ "$1" = "reload" ]; then
  92. SIGNAL="HUP"
  93. log_daemon_msg "Reloading ftp server" "$NAME"
  94. else
  95. echo "ERR: wrong parameter given to signal()"
  96. exit 1
  97. fi
  98. fi
  99. if [ -f "$PIDFILE" ]; then
  100. start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
  101. if [ $? = 0 ]; then
  102. log_end_msg 0
  103. else
  104. SIGNAL="KILL"
  105. start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
  106. if [ $? != 0 ]; then
  107. log_end_msg 1
  108. [ $2 != 0 ] || exit 0
  109. else
  110. log_end_msg 0
  111. fi
  112. fi
  113. if [ "$SIGNAL" = "KILL" ]; then
  114. rm -f "$PIDFILE"
  115. fi
  116. else
  117. log_end_msg 0
  118. fi
  119. }
  120. case "$1" in
  121. start)
  122. if [ "x$RUN" = "xyes" ] ; then
  123. start
  124. else
  125. if [ "x$INETD" = "xyes" ] ; then
  126. echo "ProFTPd is started from inetd/xinetd."
  127. else
  128. echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
  129. fi
  130. fi
  131. ;;
  132. force-start)
  133. if [ "x$INETD" = "xyes" ] ; then
  134. echo "Warning: ProFTPd is started from inetd/xinetd (trying to start anyway)."
  135. fi
  136. start
  137. ;;
  138. stop)
  139. if [ "x$RUN" = "xyes" ] ; then
  140. signal stop 0
  141. else
  142. if [ "x$INETD" = "xyes" ] ; then
  143. echo "ProFTPd is started from inetd/xinetd."
  144. else
  145. echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
  146. fi
  147. fi
  148. ;;
  149. force-stop)
  150. if [ "x$INETD" = "xyes" ] ; then
  151. echo "Warning: ProFTPd is started from inetd/xinetd (trying to kill anyway)."
  152. fi
  153. signal stop 0
  154. ;;
  155. reload)
  156. signal reload 0
  157. ;;
  158. force-reload|restart)
  159. if [ "x$RUN" = "xyes" ] ; then
  160. signal stop 1
  161. sleep 2
  162. start
  163. else
  164. if [ "x$INETD" = "xyes" ] ; then
  165. echo "ProFTPd is started from inetd/xinetd."
  166. else
  167. echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
  168. fi
  169. fi
  170. ;;
  171. status)
  172. if [ "x$INETD" = "xyes" ] ; then
  173. echo "ProFTPd is started from inetd/xinetd."
  174. exit 0
  175. else
  176. if [ -f "$PIDFILE" ]; then
  177. pid=$(cat $PIDFILE)
  178. else
  179. pid="x"
  180. fi
  181. if [ `pidof proftpd|grep "$pid"|wc -l` -ne 0 ] ; then
  182. echo "ProFTPd is started in standalone mode, currently running."
  183. exit 0
  184. else
  185. echo "ProFTPd is started in standalone mode, currently not running."
  186. exit 3
  187. fi
  188. fi
  189. ;;
  190. check-config)
  191. $DAEMON -t >/dev/null && echo "ProFTPd configuration OK" && exit 0
  192. exit 1
  193. ;;
  194. *)
  195. echo "Usage: /etc/init.d/$NAME {start|status|force-start|stop|force-stop|reload|restart|force-reload|check-config}"
  196. exit 1
  197. ;;
  198. esac
  199. exit 0