overpass 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: overpass
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Overpass startup script for dispatcher, area-queries and diff updates
  9. ### END INIT INFO
  10. #You can override those variables in /etc/default/overpass
  11. DIFF_URL="http://planet.osm.org/replication/minute"
  12. DB_DIR=/var/lib/overpass/
  13. EXEC_DIR=/usr/local/bin/
  14. #This directory will only contain logs in case of problems at start
  15. LOG_DIR=/var/log/overpass/
  16. RUN_AS_USER=root
  17. META=yes
  18. #To enable area, setting this to yes isn't enought ! Please also read : http://wiki.openstreetmap.org/wiki/Talk:Overpass_API/install
  19. AREA=no
  20. if test -f /etc/default/overpass; then
  21. . /etc/default/overpass
  22. fi
  23. mkdir $LOG_DIR 2>/dev/null
  24. mkdir $DB_DIR 2>/dev/null
  25. chown $RUN_AS_USER $DB_DIR
  26. DISPATCHER_PID_FILE=/var/run/dispatcher.pid
  27. DISPATCHER_AREA_PID_FILE=/var/run/dispatcher_area.pid
  28. DIFF_UPDATE_PID_FILE=/var/run/diff_update.pid
  29. AREA_UPDATE_PID_FILE=/var/run/area_update.pid
  30. DISPATCHER=$EXEC_DIR/dispatcher
  31. DIFF_UPDATER=$EXEC_DIR/fetch_osc_and_apply.sh
  32. AREA_BUILDER=$EXEC_DIR/rules_loop.sh
  33. DISPATCHER_OPTIONS="--meta=$META --osm-base --db-dir=$DB_DIR"
  34. AREA_DISPATCHER_OPTIONS="--areas --db-dir=$DB_DIR"
  35. DIFF_UPDATER_OPTION="$DIFF_URL --meta=$META"
  36. test -x $DISPATCHER || exit 0
  37. . /lib/lsb/init-functions
  38. # Are we running from init?
  39. run_by_init() {
  40. ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
  41. }
  42. check_dev_null() {
  43. if [ ! -c /dev/null ]; then
  44. if [ "$1" = log_end_msg ]; then
  45. log_end_msg 1 || true
  46. fi
  47. if ! run_by_init; then
  48. log_action_msg "/dev/null is not a character device!"
  49. fi
  50. exit 1
  51. fi
  52. }
  53. case "$1" in
  54. start)
  55. check_dev_null
  56. log_daemon_msg "Starting Overpass dispatcher daemon" "dispatcher"
  57. if test -f $DISPATCHER_PID_FILE ; then
  58. echo "dispatcher allready running ? : pid file exists in $DISPATCHER_PID_FILE"
  59. exit 0
  60. fi
  61. rm /dev/shm/osm3s* 2>/dev/null
  62. rm $DB_DIR/osm3s* 2>/dev/null
  63. if start-stop-daemon --start --quiet -b --oknodo --make-pidfile -c $RUN_AS_USER --pidfile $DISPATCHER_PID_FILE --exec $DISPATCHER -- $DISPATCHER_OPTIONS >> $LOG_DIR/dispatcher.log 2>&1; then
  64. #That directory is used by the xapi translator and not automatically created
  65. mkdir /tmp/translate_xapi 2>/dev/null
  66. chmod 777 /tmp/translate_xapi
  67. log_end_msg 0
  68. else
  69. log_end_msg 1
  70. fi
  71. if [ $AREA = "yes" ] ; then
  72. log_daemon_msg "Starting Overpass dispatcher daemon for areas" "dispatcher areas"
  73. if start-stop-daemon --start --quiet -b --oknodo --make-pidfile -c $RUN_AS_USER --pidfile $DISPATCHER_AREA_PID_FILE --exec $DISPATCHER -- $AREA_DISPATCHER_OPTIONS >> $LOG_DIR/dispatcher.log 2>&1; then
  74. log_end_msg 0
  75. else
  76. log_end_msg 1
  77. fi
  78. log_daemon_msg "Starting Overpass areas builder" "areas building"
  79. if start-stop-daemon --start --quiet -b --oknodo --make-pidfile -c $RUN_AS_USER --pidfile $AREA_UPDATE_PID_FILE --exec $AREA_BUILDER -- $DB_DIR >> $LOG_DIR/area_update.log 2>&1; then
  80. log_end_msg 0
  81. else
  82. log_end_msg 1
  83. fi
  84. fi
  85. if test -x $DIFF_UPDATER ; then
  86. log_daemon_msg "Starting Overpass diff updates with command $DIFF_UPDATER $DIFF_UPDATER_OPTION" "diff updates"
  87. if start-stop-daemon --start --quiet -b --oknodo --make-pidfile -c $RUN_AS_USER --pidfile $DIFF_UPDATE_PID_FILE --exec $DIFF_UPDATER -- $DIFF_UPDATER_OPTION >> $LOG_DIR/diff-updates.log 2>&1; then
  88. log_end_msg 0
  89. else
  90. log_end_msg 1
  91. fi
  92. fi
  93. ;;
  94. stop)
  95. if test -x $DIFF_UPDATER ; then
  96. if start-stop-daemon --stop --quiet --oknodo --pidfile $DIFF_UPDATE_PID_FILE; then
  97. log_daemon_msg "Stopping Overpass diff updates" "diff updates"
  98. #A little clean up of the xapi tmp dirrectory
  99. rm -r /tmp/translate_xapi 2>/dev/null
  100. rm -f $DIFF_UPDATE_PID_FILE
  101. log_end_msg 0
  102. else
  103. log_end_msg 1
  104. fi
  105. fi
  106. log_daemon_msg "Stopping Overpass dispatcher daemon" "dispatcher"
  107. if start-stop-daemon --stop --quiet --oknodo --pidfile $DISPATCHER_PID_FILE; then
  108. log_end_msg 0
  109. rm /dev/shm/osm3s* 2>/dev/null
  110. rm $DB_DIR/osm3s* 2>/dev/null
  111. rm -f $DISPATCHER_PID_FILE
  112. else
  113. log_end_msg 1
  114. fi
  115. if [ $AREA = "yes" ] ; then
  116. log_daemon_msg "Stopping Overpass dispatcher area daemon " "dispatcher area"
  117. if start-stop-daemon --stop --quiet --oknodo --pidfile $DISPATCHER_AREA_PID_FILE; then
  118. log_end_msg 0
  119. rm -f $DISPATCHER_AREA_PID_FILE
  120. else
  121. log_end_msg 1
  122. fi
  123. #FIXME this isn't enought, the osm3s_query builder will keep running for an entire loop of several hours, but we don't get it's pid
  124. # Better than nothing -- sly
  125. killall osm3s_query
  126. log_daemon_msg "Stopping Overpass area builder " "area builder"
  127. if start-stop-daemon --stop --quiet --oknodo --pidfile $AREA_UPDATE_PID_FILE; then
  128. log_end_msg 0
  129. rm -f $AREA_UPDATE_PID_FILE
  130. else
  131. log_end_msg 1
  132. fi
  133. fi
  134. ;;
  135. status)
  136. status_of_proc -p $DISPATCHER_PID_FILE "" "overpass dispatcher"
  137. status_of_proc -p $DIFF_UPDATE_PID_FILE "" "overpass diff updates"
  138. if [ $AREA = "yes" ] ; then
  139. status_of_proc -p $DISPATCHER_AREA_PID_FILE "" "overpass dispatcher areas"
  140. fi
  141. ;;
  142. *)
  143. log_action_msg "Usage: /etc/init.d/overpass {start|stop|status}"
  144. exit 1
  145. esac
  146. exit 0