mongodb-control 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # 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. ## OLD: Logging to file.
  45. #mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $BIND_OPTIONS --smallfiles
  46. ## NEW: Logging to syslog, that usually has already log rotation.
  47. mongod --dbpath $SNAP_COMMON --syslog --journal $BIND_OPTIONS --quiet
  48. else
  49. ## OLD: Logging to file.
  50. #mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $MONGO_URL --smallfiles
  51. ## NEW: Logging to syslog, that usually has already log rotation.
  52. mongod --dbpath $SNAP_COMMON --syslog --journal $MONGO_URL --quiet
  53. fi
  54. # Drop indexes on database upgrade, when starting MongoDB
  55. #mongo wekan --eval "db.getCollectionNames().forEach(function(col_name) { var coll = db.getCollection(col_name); coll.dropIndexes(); });" $BIND_OPTIONS