start_server.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. #####################################################################################
  3. # #
  4. # Script to start the server and wait. #
  5. # #
  6. # Usage : start_server #
  7. # #
  8. #####################################################################################
  9. PROFILE_NAME=${PROFILE_NAME:-"AppSrv01"}
  10. SERVER_NAME=${SERVER_NAME:-"server1"}
  11. update_hostname()
  12. {
  13. wsadmin.sh -lang jython -conntype NONE -f /work/updateHostName.py ${NODE_NAME:-"DefaultNode01"} $(hostname)
  14. touch /work/hostnameupdated
  15. }
  16. start_server()
  17. {
  18. echo "Starting server ..................."
  19. /opt/IBM/WebSphere/AppServer/profiles/$PROFILE_NAME/bin/startServer.sh $SERVER_NAME
  20. }
  21. run_logviewer(){
  22. echo "Starting logViewer ................"
  23. mkdir -p /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/server1/logdata
  24. touch /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/server1/logViewer.pos
  25. /opt/IBM/WebSphere/AppServer/bin/logViewer.sh -monitor 1 -resumable -resume -format json | grep --line-buffered "^{" &
  26. }
  27. stop_server()
  28. {
  29. echo "Stopping server ..................."
  30. kill -s INT $PID
  31. }
  32. applyConfigs(){
  33. if [ ! -z "$(ls /etc/websphere)" ]; then
  34. echo "+ Found config-files under /etc/websphere. Executing..."
  35. find /etc/websphere -type f \( -name \*.props -o -name \*.conf \) -print0 | sort -z | xargs -0 -n 1 -r /work/applyConfig.sh
  36. fi
  37. }
  38. configure_logging(){
  39. echo "Configure logging mode"
  40. /work/configure_logging.sh
  41. }
  42. ENABLE_BASIC_LOGGING=${ENABLE_BASIC_LOGGING:-"false"}
  43. if [ "$ENABLE_BASIC_LOGGING" = false ]; then
  44. configure_logging
  45. fi
  46. applyConfigs
  47. if [ "$EXTRACT_PORT_FROM_HOST_HEADER" = "true" ]; then
  48. /work/applyConfig.sh /work/config-ibm/webContainer.props
  49. fi
  50. if ! cmp -s "/tmp/passwordupdated" "/tmp/PASSWORD"; then
  51. /work/set_password.sh
  52. fi
  53. if [ "$UPDATE_HOSTNAME" = "true" ] && [ ! -f "/work/hostnameupdated" ]; then
  54. update_hostname
  55. fi
  56. trap "stop_server" TERM INT
  57. if [ "$ENABLE_BASIC_LOGGING" = false ]; then
  58. echo "HPEL is enabled"
  59. rm -f /opt/IBM/WebSphere/AppServer/profiles/$PROFILE_NAME/logs/$SERVER_NAME/SystemOut.log*
  60. rm -f /opt/IBM/WebSphere/AppServer/profiles/$PROFILE_NAME/logs/$SERVER_NAME/SystemErr.log*
  61. run_logviewer
  62. fi
  63. start_server || exit $?
  64. PID=$(ps -C java -o pid=,cmd= | grep com.ibm.ws.runtime.WsServer | awk '{print $1}')
  65. if [ "$ENABLE_BASIC_LOGGING" = true ]; then
  66. echo "Basic Logging is enabled"
  67. tail -F /opt/IBM/WebSphere/AppServer/profiles/$PROFILE_NAME/logs/$SERVER_NAME/SystemOut.log --pid $PID -n +0 &
  68. tail -F /opt/IBM/WebSphere/AppServer/profiles/$PROFILE_NAME/logs/$SERVER_NAME/SystemErr.log --pid $PID -n +0 >&2 &
  69. fi
  70. if [ "$ENABLE_BASIC_LOGGING" = true ]; then
  71. while [ -e "/proc/$PID" ]; do
  72. sleep 1
  73. done
  74. else
  75. while [ -e "/proc/$PID" ]; do
  76. ps cax | grep logViewer > /dev/null
  77. if [ $? -ne 0 ]; then
  78. run_logviewer
  79. fi
  80. sleep 1
  81. done
  82. LOGVIEWER_PID=$(ps -C logViewer.sh -o pid= | tr -d " ")
  83. if [ $? -eq 0 ]; then
  84. # give server time to flush logs and logViewer time to send them
  85. sleep 15
  86. echo "Stopping logViewer ................"
  87. kill -9 $LOGVIEWER_PID
  88. exit 0
  89. fi
  90. fi