docker-entrypoint.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #set -e
  3. if [ "$1" = "storage" ] ; then
  4. FASTDFS_MODE="storage"
  5. sed -i "s|^url_have_group_name.*$|url_have_group_name=true|g" /etc/fdfs/mod_fastdfs.conf
  6. else
  7. FASTDFS_MODE="tracker"
  8. fi
  9. if [ -n "$PORT" ] ; then
  10. sed -i "s|^port=.*$|port=${PORT}|g" /etc/fdfs/"$FASTDFS_MODE".conf
  11. if [ "$1" = "storage" ] ; then
  12. sed -i "s|^storage_server_port=.*$|storage_server_port=${PORT}|g" /etc/fdfs/mod_fastdfs.conf
  13. fi
  14. fi
  15. if [ -n "$HTTPPORT" ] ; then
  16. sed -i "s|80|${HTTPPORT}|g" /usr/local/nginx/conf/nginx.conf
  17. fi
  18. if [ -n "$TRACKER_SERVER" ] ; then
  19. sed -i "s|tracker_server=.*$|tracker_server=${TRACKER_SERVER}|g" /etc/fdfs/storage.conf
  20. sed -i "s|tracker_server=.*$|tracker_server=${TRACKER_SERVER}|g" /etc/fdfs/client.conf
  21. sed -i "s|^tracker_server=.*$|tracker_server=${TRACKER_SERVER}|g" /etc/fdfs/mod_fastdfs.conf
  22. fi
  23. if [ -n "$GROUP_NAME" ] ; then
  24. sed -i "s|group_name=.*$|group_name=${GROUP_NAME}|g" /etc/fdfs/storage.conf
  25. sed -i "s|group1|${GROUP_NAME}|g" /usr/local/nginx/conf/nginx.conf
  26. sed -i "s|^group_name=.*$|group_name=${GROUP_NAME}|g" /etc/fdfs/mod_fastdfs.conf
  27. fi
  28. FASTDFS_LOG_FILE="${FASTDFS_BASE_PATH}/logs/${FASTDFS_MODE}d.log"
  29. PID_NUMBER="${FASTDFS_BASE_PATH}/data/fdfs_${FASTDFS_MODE}d.pid"
  30. echo "try to start the $FASTDFS_MODE node..."
  31. if [ -f "$FASTDFS_LOG_FILE" ]; then
  32. rm "$FASTDFS_LOG_FILE"
  33. fi
  34. # start the fastdfs node.
  35. fdfs_${FASTDFS_MODE}d /etc/fdfs/${FASTDFS_MODE}.conf start
  36. if [ "$1" = "storage" ] ; then
  37. /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  38. fi
  39. # wait for pid file(important!),the max start time is 5 seconds,if the pid number does not appear in 5 seconds,start failed.
  40. TIMES=5
  41. while [ ! -f "$PID_NUMBER" -a $TIMES -gt 0 ]
  42. do
  43. sleep 1s
  44. TIMES=`expr $TIMES - 1`
  45. done
  46. # if the storage node start successfully, print the started time.
  47. # if [ $TIMES -gt 0 ]; then
  48. # echo "the ${FASTDFS_MODE} node started successfully at $(date +%Y-%m-%d_%H:%M)"
  49. # # give the detail log address
  50. # echo "please have a look at the log detail at $FASTDFS_LOG_FILE"
  51. # # leave balnk lines to differ from next log.
  52. # echo
  53. # echo
  54. # # make the container have foreground process(primary commond!)
  55. # tail -F --pid=`cat $PID_NUMBER` /dev/null
  56. # # else print the error.
  57. # else
  58. # echo "the ${FASTDFS_MODE} node started failed at $(date +%Y-%m-%d_%H:%M)"
  59. # echo "please have a look at the log detail at $FASTDFS_LOG_FILE"
  60. # echo
  61. # echo
  62. # fi
  63. tail -f "$FASTDFS_LOG_FILE"