mongodb-control 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # get wekan/mongo settings
  3. source $SNAP/bin/wekan-read-settings
  4. if [ "true" == "${DISABLE_MONGODB}" ]; then
  5. echo "mongodb is disabled. Stop service"
  6. snapctl stop --disable ${SNAP_NAME}.mongodb
  7. exit 0
  8. fi
  9. # make sure we have set minimum env variables for locale
  10. if [ -z "$LANG" ]; then
  11. export LANG=en_US.UTF-8
  12. fi
  13. export LC_ALL=C
  14. # When starting MongoDB, if logfile exist, delete it, because now uses syslog instead of logfile,
  15. # because syslog usually already has log rotation.
  16. # https://github.com/wekan/wekan-snap/issues/92
  17. if test -f "$SNAP_COMMON/mongodb.log"; then
  18. rm -f "$SNAP_COMMON/mongodb.log"
  19. fi
  20. # Alternative: When starting MongoDB, and using logfile, truncate log to last 1000 lines of text.
  21. # 1) If file exists:
  22. #if test -f "$SNAP_COMMON/mongodb.log"; then
  23. # # 2) Copy last 1000 lines to variable loglast1000lines.
  24. # loglast1000lines=$(tail -1000 "$SNAP_COMMON/mongodb.log")
  25. # # 3) Copy variable to replace original MongoDB log.
  26. # echo "$loglast1000lines" > "$SNAP_COMMON/mongodb.log"
  27. # # 4) Set variable to be empty.
  28. # loglast1000lines=""
  29. #fi
  30. if [ -z "$MONGO_URL" ]; then
  31. # start mongo deamon
  32. BIND_OPTIONS=""
  33. if [ "nill" != "$MONGODB_BIND_UNIX_SOCKET" ] && [ "x" != "x${MONGODB_BIND_UNIX_SOCKET}" ]; then
  34. BIND_OPTIONS+=" --unixSocketPrefix $MONGODB_BIND_UNIX_SOCKET"
  35. fi
  36. if [ "x" != "x${MONGODB_BIND_IP}" ]; then
  37. BIND_OPTIONS+=" --bind_ip $MONGODB_BIND_IP"
  38. fi
  39. if [ "x" != "x${MONGODB_PORT}" ]; then
  40. BIND_OPTIONS+=" --port $MONGODB_PORT"
  41. fi
  42. echo "mongodb bind options: $BIND_OPTIONS"
  43. ## OLD: Logging to file.
  44. #mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $BIND_OPTIONS --smallfiles
  45. ## NEW: Logging to syslog, that usually has already log rotation.
  46. mongod --dbpath $SNAP_COMMON --syslog --journal $BIND_OPTIONS --smallfiles --quiet
  47. else
  48. ## OLD: Logging to file.
  49. #mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $MONGO_URL --smallfiles
  50. ## NEW: Logging to syslog, that usually has already log rotation.
  51. mongod --dbpath $SNAP_COMMON --syslog --journal $MONGO_URL --smallfiles --quiet
  52. fi
  53. # Drop indexes on database upgrade, when starting MongoDB
  54. #mongo wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS