mongodb-control 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/snap/wekan/current/lib/x86_64-linux-gnu
  15. # When starting MongoDB, if logfile exist, delete it, because now uses syslog instead of logfile,
  16. # because syslog usually already has log rotation.
  17. # https://github.com/wekan/wekan-snap/issues/92
  18. if test -f "$SNAP_COMMON/mongodb.log"; then
  19. rm -f "$SNAP_COMMON/mongodb.log"
  20. fi
  21. # Not in use. If uploads directory does not exist, create it.
  22. # Wekan will store attachments there.
  23. #if [ ! -d "$SNAP_COMMON/uploads" ]; then
  24. # mkdir "$SNAP_COMMON/uploads"
  25. #fi
  26. # Alternative: When starting MongoDB, and using logfile, truncate log to last 1000 lines of text.
  27. # 1) If file exists:
  28. #if test -f "$SNAP_COMMON/mongodb.log"; then
  29. # # 2) Copy last 1000 lines to variable loglast1000lines.
  30. # loglast1000lines=$(tail -1000 "$SNAP_COMMON/mongodb.log")
  31. # # 3) Copy variable to replace original MongoDB log.
  32. # echo "$loglast1000lines" > "$SNAP_COMMON/mongodb.log"
  33. # # 4) Set variable to be empty.
  34. # loglast1000lines=""
  35. #fi
  36. if [ -z "$MONGO_URL" ]; then
  37. # start mongo deamon
  38. BIND_OPTIONS=""
  39. if [ "nill" != "$MONGODB_BIND_UNIX_SOCKET" ] && [ "x" != "x${MONGODB_BIND_UNIX_SOCKET}" ]; then
  40. BIND_OPTIONS+=" --unixSocketPrefix $MONGODB_BIND_UNIX_SOCKET"
  41. fi
  42. if [ "x" != "x${MONGODB_BIND_IP}" ]; then
  43. BIND_OPTIONS+=" --bind_ip $MONGODB_BIND_IP"
  44. fi
  45. if [ "x" != "x${MONGODB_PORT}" ]; then
  46. BIND_OPTIONS+=" --port $MONGODB_PORT"
  47. fi
  48. echo "mongodb bind options: $BIND_OPTIONS"
  49. if [ "syslog" == "${MONGO_LOG_DESTINATION}" ]; then
  50. echo "Sending mongodb logs to syslog"
  51. mongod --dbpath $SNAP_COMMON --syslog --journal $BIND_OPTIONS --quiet
  52. exit 0
  53. fi
  54. if [ "snapcommon" == "${MONGO_LOG_DESTINATION}" ]; then
  55. echo "Sending mongodb logs to $SNAP_COMMON"
  56. mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $BIND_OPTIONS --quiet
  57. fi
  58. if [ "devnull" == "${MONGO_LOG_DESTINATION}" ]; then
  59. echo "Sending mongodb logs to /dev/null"
  60. mongod --dbpath $SNAP_COMMON --logpath /dev/null --journal $BIND_OPTIONS --quiet
  61. fi
  62. # Drop indexes on database upgrade, when starting MongoDB
  63. #mongo wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS
  64. mongo wekan --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.4" });' $BIND_OPTIONS
  65. else
  66. if [ "syslog" == "${MONGO_LOG_DESTINATION}" ]; then
  67. echo "Sending mongodb logs to syslog"
  68. mongod --dbpath $SNAP_COMMON --syslog --journal $MONGO_URL --quiet
  69. fi
  70. if [ "snapcommon" == "${MONGO_LOG_DESTINATION}" ]; then
  71. echo "Sending mongodb logs to $SNAP_COMMON"
  72. mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $MONGO_URL --quiet
  73. fi
  74. if [ "devnull" == "${MONGO_LOG_DESTINATION}" ]; then
  75. echo "Sending mongodb logs to /dev/null"
  76. mongod --dbpath $SNAP_COMMON --logpath /dev/null --journal $MONGO_URL --quiet
  77. fi
  78. # Drop indexes on database upgrade, when starting MongoDB
  79. #mongo wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS
  80. mongo wekan --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.4" });' $BIND_OPTIONS
  81. fi