webkit 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/sh
  2. #
  3. # WebKit application server
  4. # part of Webware for Python
  5. # www.webwareforpython.org
  6. #
  7. # /etc/init.d/webkit
  8. #
  9. # init.d script for Debian GNU/Linux
  10. #
  11. ### START LOCAL CONFIGURATION
  12. # If you store this script in your Webware working directory
  13. # and create a symlink to it as /etc/init.d/webkit_appname,
  14. # it will try to guess your configuration parameters. You can
  15. # make changes either directly here or you can also override
  16. # the configuration in the Launch.py script.
  17. # The name of your Webware application:
  18. APP_NAME=`basename "$0"`
  19. # Description of your Webware application:
  20. DESC="Webware"
  21. # The location of the start sript:
  22. if [ -h "$0" ]; then
  23. # Get the target file if start script is given as a link:
  24. START_SCRIPT=`readlink -f "$0"`
  25. else
  26. START_SCRIPT="$0"
  27. fi
  28. # The working directory or path to WebKit:
  29. WORK_DIR=`dirname "$START_SCRIPT"`
  30. # Make sure to have the absolute path:
  31. test -d "$WORK_DIR" || exit 0
  32. WORK_DIR=`cd "$WORK_DIR" 2>/dev/null && pwd`
  33. # The app server launch script:
  34. APP_SERVER="$WORK_DIR/AppServer"
  35. test -x "$APP_SERVER" || exit 0
  36. # The app server configuration:
  37. APP_SERVER_CONFIG="$WORK_DIR/Configs/AppServer.config"
  38. test -f "$APP_SERVER_CONFIG" || exit 0
  39. # The WebKit app server log file
  40. # (you can set this in Launch.py as well):
  41. #LOG_FILE="/var/log/$APP_NAME.log"
  42. LOG_FILE="$WORK_DIR/Logs/webkit.log"
  43. # Use this extension if you want to move the last log away
  44. # (also consider using logrotate or something similar):
  45. LOG_OLD=".old"
  46. # The app server process id file
  47. # (you can set this in Launch.py as well):
  48. #PID_FILE="/var/run/$APP_NAME.pid"
  49. PID_FILE="$WORK_DIR/webkit.pid"
  50. # The user and group to run the app server
  51. # (you can set this in Launch.py as well).
  52. # If undefined, it will be the user and group
  53. # running the start script (usually root).
  54. # You should use a low-privilege account,
  55. # like the work dir owner, wwwrun or nobody.
  56. # This will use the owner of the AppServer script:
  57. WEBWARE_USER=`stat -c "%U" "$APP_SERVER"`
  58. WEBWARE_GROUP=`stat -c "%G" "$APP_SERVER"`
  59. # Unset the following variable if you want to store the
  60. # pid and log files as the user running the start script
  61. # (usually root) or set it if you want these files to be
  62. # written after switching to WEBWARE_USER:WEBWARE_GROUP.
  63. LAUNCH_AS_WEBWARE="yes"
  64. # Additional options -u or -O to be passed on to Python:
  65. PYTHONOPTS=
  66. # Additional libraries to be included in the Python path:
  67. PYTHONPATH=
  68. export PYTHONPATH
  69. ### END LOCAL CONFIGURATION
  70. set -e
  71. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  72. d_start() {
  73. # Keep backup of last log file:
  74. if [ "$LOG_OLD" -a -f "$LOG_FILE" ]; then
  75. if [ -s "$LOG_FILE" ]; then
  76. mv "$LOG_FILE" "$LOG_FILE$LOG_OLD"
  77. else
  78. rm "$LOG_FILE"
  79. fi
  80. fi
  81. # Prepare option to set group
  82. if [ "$WEBWARE_GROUP" ]; then
  83. WEBWARE_GROUP="-g $WEBWARE_GROUP"
  84. fi
  85. # Note that the pid file does not record the pid of the
  86. # wrapper script, but the pid of the Python app server:
  87. if [ "$LAUNCH_AS_WEBWARE" ]; then
  88. # Prepare option to set user
  89. if [ "$WEBWARE_USER" ]; then
  90. WEBWARE_USER="-c $WEBWARE_USER"
  91. fi
  92. # Switch user first, then create pid and log files:
  93. start-stop-daemon -S -b -q -p "$PID_FILE" \
  94. $WEBWARE_USER $WEBWARE_GROUP -a "$APP_SERVER" \
  95. -- $PYTHONOPTS -d "$WORK_DIR" -o "$LOG_FILE" \
  96. -i "$PID_FILE" > /dev/null
  97. else
  98. # Prepare option to set user
  99. if [ "$WEBWARE_USER" ]; then
  100. WEBWARE_USER="-u $WEBWARE_USER"
  101. fi
  102. # Create pid and log files first, then switch user:
  103. start-stop-daemon -S -q -p "$PID_FILE" -a "$APP_SERVER" \
  104. -- $PYTHONOPTS -d "$WORK_DIR" -i "$PID_FILE" \
  105. $WEBWARE_USER $WEBWARE_GROUP >> "$LOG_FILE" 2>&1 &
  106. fi
  107. }
  108. d_stop() {
  109. # Note that we are terminating the Python app server here;
  110. # the app server wrapper script will follow automatically:
  111. [ -f "$PID_FILE" ] && \
  112. start-stop-daemon -K -q -p $PID_FILE \
  113. $WEBWARE_USER -n python
  114. rm -f "$PID_FILE"
  115. }
  116. d_reload() {
  117. [ -f "$PID_FILE" ] && \
  118. start-stop-daemon -K -q -p $PID_FILE \
  119. $WEBWARE_USER -n python -s HUP
  120. }
  121. case "$1" in
  122. start)
  123. echo -n "Starting $DESC: $APP_NAME"
  124. d_start
  125. echo "."
  126. ;;
  127. stop)
  128. echo -n "Stopping $DESC: $APP_NAME"
  129. d_stop
  130. echo "."
  131. ;;
  132. reload|force-reload)
  133. echo -n "Reloading $DESC configuration..."
  134. d_reload
  135. echo "done."
  136. ;;
  137. restart)
  138. echo -n "Restarting $DESC: $NAME"
  139. d_stop
  140. sleep 1
  141. d_start
  142. echo "."
  143. ;;
  144. *)
  145. echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  146. exit 1
  147. ;;
  148. esac
  149. exit 0