mongodb-control 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/${SNAP_NAME}/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. # Alternative: When starting MongoDB, and using logfile, truncate log to last 1000 lines of text.
  22. # 1) If file exists:
  23. #if test -f "$SNAP_COMMON/mongodb.log"; then
  24. # # 2) Copy last 1000 lines to variable loglast1000lines.
  25. # loglast1000lines=$(tail -1000 "$SNAP_COMMON/mongodb.log")
  26. # # 3) Copy variable to replace original MongoDB log.
  27. # echo "$loglast1000lines" > "$SNAP_COMMON/mongodb.log"
  28. # # 4) Set variable to be empty.
  29. # loglast1000lines=""
  30. #fi
  31. if [ -z "$MONGO_URL" ]; then
  32. # start mongo deamon
  33. BIND_OPTIONS=""
  34. if [ "nill" != "$MONGODB_BIND_UNIX_SOCKET" ] && [ "x" != "x${MONGODB_BIND_UNIX_SOCKET}" ]; then
  35. BIND_OPTIONS+=" --unixSocketPrefix $MONGODB_BIND_UNIX_SOCKET"
  36. fi
  37. if [ "x" != "x${MONGODB_BIND_IP}" ]; then
  38. BIND_OPTIONS+=" --bind_ip $MONGODB_BIND_IP"
  39. fi
  40. if [ "x" != "x${MONGODB_PORT}" ]; then
  41. BIND_OPTIONS+=" --port $MONGODB_PORT"
  42. fi
  43. echo "mongodb bind options: $BIND_OPTIONS"
  44. if [ "syslog" == "${MONGO_LOG_DESTINATION}" ]; then
  45. echo "Sending mongodb logs to syslog"
  46. mongod --dbpath $SNAP_COMMON --syslog --journal $BIND_OPTIONS --quiet
  47. exit 0
  48. fi
  49. if [ "snapcommon" == "${MONGO_LOG_DESTINATION}" ]; then
  50. echo "Sending mongodb logs to $SNAP_COMMON"
  51. mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $BIND_OPTIONS --quiet
  52. fi
  53. if [ "devnull" == "${MONGO_LOG_DESTINATION}" ]; then
  54. echo "Sending mongodb logs to /dev/null"
  55. mongod --dbpath $SNAP_COMMON --logpath /dev/null --journal $BIND_OPTIONS --quiet
  56. fi
  57. # Drop indexes on database upgrade, when starting MongoDB
  58. #mongo wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS
  59. mongo wekan --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.4" });' $BIND_OPTIONS
  60. # Delete incomplete uploads so that they would not prevent starting WeKan
  61. mongo wekan --eval 'db.getCollection("cfs.attachments.filerecord").find( { "uploadedAt": { "$exists": true }, "copies.attachments" : null,"failures.copies.attachments.doneTrying" : {"$ne" : true}});' $BIND_OPTIONS
  62. else
  63. if [ "syslog" == "${MONGO_LOG_DESTINATION}" ]; then
  64. echo "Sending mongodb logs to syslog"
  65. mongod --dbpath $SNAP_COMMON --syslog --journal $MONGO_URL --quiet
  66. fi
  67. if [ "snapcommon" == "${MONGO_LOG_DESTINATION}" ]; then
  68. echo "Sending mongodb logs to $SNAP_COMMON"
  69. mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $MONGO_URL --quiet
  70. fi
  71. if [ "devnull" == "${MONGO_LOG_DESTINATION}" ]; then
  72. echo "Sending mongodb logs to /dev/null"
  73. mongod --dbpath $SNAP_COMMON --logpath /dev/null --journal $MONGO_URL --quiet
  74. fi
  75. # Drop indexes on database upgrade, when starting MongoDB
  76. #mongo wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS
  77. mongo wekan --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.2" });' $BIND_OPTIONS
  78. # Delete incomplete uploads so that they would not prevent starting WeKan
  79. mongo wekan --eval 'db.getCollection("cfs.attachments.filerecord").find( { "uploadedAt": { "$exists": true }, "copies.attachments" : null,"failures.copies.attachments.doneTrying" : {"$ne" : true}});' $BIND_OPTIONS
  80. fi