start_one_dafilesrv 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. ################################################################################
  3. # Copyright (C) 2011 HPCC Systems.
  4. #
  5. # All rights reserved. This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ################################################################################
  18. #################################################
  19. ## Defaulting needed for new init system ##
  20. #################################################
  21. : ${LIBDIR:="."} #
  22. : ${BINDIR:="."} #
  23. export PATH=$BINDIR:$PATH #
  24. export LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH #
  25. #################################################
  26. DESTDIR=`dirname $0`
  27. cd $DESTDIR
  28. if [ "_$1" != "_loop" ]; then
  29. nohup $0 loop $* &>/dev/null &
  30. exit 0
  31. fi
  32. rm -f /var/run/dafilesrv.pid
  33. killall -9 dafilesrv 2> /dev/null
  34. sleep 1
  35. export PATH=`pwd`:$DESTDIR:$PATH
  36. export LD_LIBRARY_PATH=.
  37. ulimit -n 8192
  38. ulimit -c unlimited
  39. # dafilesrv is searched for in CURRENT_VERSION dir (if exists)
  40. # or /c$/dafilesrv
  41. # then $DESTDIR (location of scripts)
  42. # then $PATH
  43. if [ -e CURRENT_VERSION ]; then
  44. cd `cat CURRENT_VERSION`
  45. export PATH=`pwd`:$DESTDIR:$PATH
  46. export LOPT="-L /c$/dafilesrv"
  47. else
  48. export PATH=`pwd`:$DESTDIR:$PATH
  49. export LOPT=
  50. fi
  51. $BINDIR/dafilesrv -D $LOPT 1>/dev/null
  52. sleep 1
  53. pid=`pidof -x dafilesrv`
  54. if [ "$?" -eq "0" ]; then
  55. echo $pid > /var/run/dafilesrv.pid
  56. fi
  57. while [ -e /var/run/dafilesrv.pid ] && [ "`cat /var/run/dafilesrv.pid`" -eq "$pid" ]; do
  58. kill -0 $pid 2> /dev/null
  59. if [ "$?" -eq "0" ]; then
  60. sleep 60
  61. else
  62. rm -f /var/run/dafilesrv.pid
  63. killall -9 dafilesrv 2> /dev/null
  64. sleep 1
  65. $BINDIR/dafilesrv -D $LOPT 1>/dev/null
  66. sleep 1
  67. pid=`pidof -x dafilesrv`
  68. if [ "$?" -eq "0" ]; then
  69. if [ ! -e /var/run/dafilesrv.pid ]; then
  70. echo $pid > /var/run/dafilesrv.pid
  71. fi
  72. fi
  73. fi
  74. done