NoPaste

Ubuntu: YaCy Daemon Script

von Anonymous

SNIPPET_TEXT:
  1. #! /bin/bash
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:          yacy
  5. # Required-Start:    $local_fs, $remote_fs, $network, $named, $time
  6. # Required-Stop:     $local_fs, $remote_fs, $network, $named, $time
  7. # Should-Start:      $syslog
  8. # Should-Stop:       $syslog
  9. # Default-Start:     2 3 4 5
  10. # Default-Stop:      0 1 6
  11. # Short-Description: Starts YaCy daemon processes with port
  12. # Description:       Starts YaCy daemon processes with port
  13. ### END INIT INFO
  14.  
  15. set -e
  16.  
  17. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  18. BASEPATH=/MYPATH/yacy
  19. DAEMON=${BASEPATH}/startYACY.sh
  20. STOPDAEMON=${BASEPATH}/stopYACY.sh
  21. KILLDAEMON=${BASEPATH}/killYACY.sh
  22. NAME=yacy
  23. DESC="yacy daemon"
  24. YACYPIDDIR=${BASEPATH}
  25. YACYPID=$YACYPIDDIR/yacy.pid
  26. DEFAULTSFILE=/etc/default/$NAME
  27. USER=yacy
  28. GROUP=yacy
  29. WAITFORDAEMON=360
  30. ARGS=""
  31. NICE=""
  32.  
  33. # Let's try to figure our some sane defaults:
  34. if [ -r /proc/sys/fs/file-max ]; then
  35.         system_max=`cat /proc/sys/fs/file-max`
  36.         if [ "$system_max" -gt "80000" ] ; then
  37.                 MAX_FILEDESCRIPTORS=32768
  38.         elif [ "$system_max" -gt "40000" ] ; then
  39.                 MAX_FILEDESCRIPTORS=16384
  40.         elif [ "$system_max" -gt "10000" ] ; then
  41.                 MAX_FILEDESCRIPTORS=8192
  42.         else
  43.                 MAX_FILEDESCRIPTORS=1024
  44.                 cat << EOF
  45.  
  46. Warning: Your system has very few filedescriptors available in total.
  47.  
  48. Maybe you should try raising that by adding 'fs.file-max=100000' to your
  49. /etc/sysctl.conf file.  Feel free to pick any number that you deem appropriate.
  50. Then run 'sysctl -p'.  See /proc/sys/fs/file-max for the current value, and
  51. file-nr in the same directory for how many of those are used at the moment.
  52.  
  53. EOF
  54.         fi
  55. else
  56.         MAX_FILEDESCRIPTORS=8192
  57. fi
  58.  
  59. test -x $DAEMON || exit 0
  60.  
  61. # Include tor defaults if available
  62. if [ -f $DEFAULTSFILE ] ; then
  63.         . $DEFAULTSFILE
  64. fi
  65.  
  66. wait_for_deaddaemon () {
  67.         pid=$1
  68.         echo -n "${NAME} stopping"
  69.         sleep 1
  70.         if test -n "$pid" ; then
  71.                 if kill -0 $pid 2>/dev/null ; then
  72.                         echo -n "."
  73.                         cnt=0
  74.                         while kill -0 $pid 2>/dev/null ; do
  75.                                 cnt=`expr $cnt + 1`
  76.                                 if [ $cnt -gt $WAITFORDAEMON ] ; then
  77.                                         echo " FAILED."
  78.                                         echo "Killing now ${NAME} (PID ${pid})..."
  79.                                         sudo -u ${USER} ${KILLDAEMON}
  80.                                         rm -f ${YACYPID}
  81.                                         return 1
  82.                                 fi
  83.                                 sleep 1
  84.                                 echo -n "."
  85.                         done
  86.                 fi
  87.         fi
  88.         echo " DONE"
  89.         rm -f ${YACYPID}
  90.         return 0
  91. }
  92.  
  93. check_yacypiddir () {
  94.         if test ! -d $YACYPIDDIR; then
  95.                 echo "There is no $YACYPIDDIR directory.  Creating one for you."
  96.                 mkdir -m 02700 "$YACYPIDDIR"
  97.                 chown ${USER}:${GROUP} "$YACYPIDDIR"
  98.         fi
  99.  
  100.         if test ! -x $YACYPIDDIR; then
  101.                 echo "Cannot access $YACYPIDDIR directory, are you root?" >&2
  102.                 exit 1
  103.         fi
  104. }
  105.  
  106. check_already_runnning () {
  107.         pid=`cat $YACYPID 2>/dev/null` || true
  108.         if test -f $YACYPID -a -n "$pid" -a kill -0 $pid 2>/dev/null ; then
  109.                 echo "Alread running (there is ${YACYPID} - PID ${pid})."
  110.                 exit 1
  111.         fi
  112.  
  113.         securepid=`fuser ${BASEPATH}/DATA/LOG/yacy00.log 2>/dev/null | awk '{print $1}' 2>/dev/null`
  114.         if test -n "${securepid}"; then
  115.                 echo "Alread running (there is PID ${securepid})."
  116.                 exit 1
  117.         fi
  118. }
  119.  
  120. case "$1" in
  121.   start)
  122.         if [ "$RUN_DAEMON" != "yes" ]; then
  123.                 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
  124.                 exit 0
  125.         fi
  126.  
  127.         if [ -n "$MAX_FILEDESCRIPTORS" ]; then
  128.                 echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
  129.                 if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
  130.                         echo "."
  131.                 else
  132.                         echo ": FAILED."
  133.                 fi
  134.         fi
  135.  
  136.         check_yacypiddir
  137.  
  138.         echo "Starting $DESC: $NAME..."
  139.  
  140.         check_already_runnning
  141.  
  142.         if test -n "$NICE" ; then
  143.                 nice -n $NICE sudo -u ${USER} $DAEMON $ARGS
  144.         else
  145.                 sudo -u ${USER} $DAEMON $ARGS
  146.         fi
  147.         echo "done."
  148.         ;;
  149.   stop)
  150.         echo -n "Stopping $DESC: "
  151.         pid=`cat $YACYPID 2>/dev/null` || true
  152.         securepid=`fuser ${BASEPATH}/DATA/LOG/yacy00.log 2>/dev/null | awk '{print $1}' 2>/dev/null`
  153.  
  154.         if test -f $YACYPID -a -n "$pid" -a kill -0 $pid 2>/dev/null; then
  155.                 sudo -u ${USER} ${STOPDAEMON}
  156.                 wait_for_deaddaemon $pid
  157.         elif test -n "${securepid}"; then
  158.                 sudo -u ${USER} ${STOPDAEMON}
  159.                 wait_for_deaddaemon ${securepid}
  160.         else
  161.                 echo "not running (there is no $YACYPID)."
  162.                 exit 0
  163.         fi
  164.  
  165.         ;;
  166.   reload|force-reload)
  167.         $0 restart
  168.         ;;
  169.   restart)
  170.         $0 stop
  171.         $0 start
  172.         ;;
  173.   *)
  174.         echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
  175.         exit 1
  176.         ;;
  177. esac
  178.  
  179. exit 0

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN