Advertisement
Guest User

Untitled

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