Created
September 11, 2014 22:42
-
-
Save vmassol/2cf7952d71521d626313 to your computer and use it in GitHub Desktop.
start_xwiki.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # --------------------------------------------------------------------------- | |
| # See the NOTICE file distributed with this work for additional | |
| # information regarding copyright ownership. | |
| # | |
| # This is free software; you can redistribute it and/or modify it | |
| # under the terms of the GNU Lesser General Public License as | |
| # published by the Free Software Foundation; either version 2.1 of | |
| # the License, or (at your option) any later version. | |
| # | |
| # This software is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| # Lesser General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU Lesser General Public | |
| # License along with this software; if not, write to the Free | |
| # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| # 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| # --------------------------------------------------------------------------- | |
| # --------------------------------------------------------------------------- | |
| # Optional ENV vars | |
| # ----------------- | |
| # XWIKI_OPTS - parameters passed to the Java VM when running XWiki | |
| # e.g. to increase the memory allocated to the JVM to 1GB, use | |
| # set XWIKI_OPTS=-Xmx1024m | |
| # JETTY_PORT - the port on which to start Jetty, 8080 by default | |
| # JETTY_STOP_PORT - the port on which Jetty listens for a Stop command, 8079 by default | |
| # --------------------------------------------------------------------------- | |
| # Ensure that the commands below are always started in the directory where this script is | |
| # located. To do this we compute the location of the current script. | |
| PRG="$0" | |
| while [ -h "$PRG" ]; do | |
| ls=`ls -ld "$PRG"` | |
| link=`expr "$ls" : '.*-> \(.*\)$'` | |
| if expr "$link" : '/.*' > /dev/null; then | |
| PRG="$link" | |
| else | |
| PRG=`dirname "$PRG"`/"$link" | |
| fi | |
| done | |
| PRGDIR=`dirname "$PRG"` | |
| cd "$PRGDIR" | |
| JETTY_HOME=jetty | |
| # If no XWIKI_OPTS env variable has been defined use default values. | |
| if [ -z "$XWIKI_OPTS" ] ; then | |
| XWIKI_OPTS="-Xmx512m -XX:MaxPermSize=196m" | |
| fi | |
| # The port on which to start Jetty can be defined in an enviroment variable called JETTY_PORT | |
| if [ -z "$JETTY_PORT" ]; then | |
| JETTY_PORT=8080 | |
| fi | |
| # The port on which Jetty listens for a Stop command can be defined in an enviroment variable called JETTY_STOP_PORT | |
| if [ -z "$JETTY_STOP_PORT" ]; then | |
| JETTY_STOP_PORT=8079 | |
| fi | |
| # The location where to store the process id | |
| XWIKI_LOCK_DIR="/var/tmp" | |
| # Parse script parameters | |
| while [[ $# > 0 ]]; do | |
| key="$1" | |
| shift | |
| case $key in | |
| -p|--port) | |
| JETTY_PORT="$1" | |
| shift | |
| ;; | |
| -sp|--stopport) | |
| JETTY_STOP_PORT="$1" | |
| shift | |
| ;; | |
| -ld|--lockdir) | |
| XWIKI_LOCK_DIR="$1" | |
| shift | |
| ;; | |
| -k|--kill) | |
| XWIKI_KILL="true" | |
| ;; | |
| *) | |
| # unknown option | |
| ;; | |
| esac | |
| done | |
| # Check if a lock file already exists for the specified port which means an XWiki instance is already running | |
| XWIKI_LOCK_FILE="${XWIKI_LOCK_DIR}/xwiki-${JETTY_PORT}.lck" | |
| if [ -e $XWIKI_LOCK_FILE ]; then | |
| if [ "$XWIKI_KILL" == "true" ]; then | |
| echo An XWiki instance is already running on port ${JETTY_PORT}, stopping it! | |
| /bin/sh stop_xwiki2.sh $JETTY_STOP_PORT | |
| else | |
| echo An XWiki lock files exists at ${XWIKI_LOCK_FILE}. Make sure no other XWiki instance is running... | |
| exit 1 | |
| fi | |
| fi | |
| echo Starting Jetty on port ${JETTY_PORT}, please wait... | |
| # Location where XWiki stores generated data and where database files are. | |
| XWIKI_DATA_DIR=${xwikiDataDir} | |
| XWIKI_OPTS="$XWIKI_OPTS -Dxwiki.data.dir=$XWIKI_DATA_DIR" | |
| # Ensure the data directory exists so that XWiki can use it for storing permanent data. | |
| mkdir -p $XWIKI_DATA_DIR 2>/dev/null | |
| # Ensure the logs directory exists as otherwise Jetty reports an error | |
| mkdir -p $XWIKI_DATA_DIR/logs 2>/dev/null | |
| # Specify port on which HTTP requests will be handled | |
| XWIKI_OPTS="$XWIKI_OPTS -Djetty.port=$JETTY_PORT" | |
| # Specify Jetty's home directory | |
| XWIKI_OPTS="$XWIKI_OPTS -Djetty.home=$JETTY_HOME" | |
| # Specify port and key to stop a running Jetty instance | |
| XWIKI_OPTS="$XWIKI_OPTS -DSTOP.KEY=xwiki -DSTOP.PORT=$JETTY_STOP_PORT" | |
| # Specify the encoding to use | |
| XWIKI_OPTS="$XWIKI_OPTS -Dfile.encoding=UTF8" | |
| # In order to avoid getting a "java.lang.IllegalStateException: Form too large" error | |
| # when editing large page in XWiki we need to tell Jetty to allow for large content | |
| # since by default it only allows for 20K. We do this by passing the | |
| # org.eclipse.jetty.server.Request.maxFormContentSize property. | |
| # Note that setting this value too high can leave your server vulnerable to denial of | |
| # service attacks. | |
| XWIKI_OPTS="$XWIKI_OPTS -Dorg.eclipse.jetty.server.Request.maxFormContentSize=1000000" | |
| java $XWIKI_OPTS -jar $JETTY_HOME/start.jar ${JETTY_HOME}/etc/jetty.xml ${JETTY_HOME}/etc/jetty-*.xml & | |
| XWIKI_PID=$! | |
| echo $XWIKI_PID > $XWIKI_LOCK_FILE | |
| trap "kill ${XWIKI_PID}; exit 1" INT | |
| wait $XWIKI_PID | |
| # Remove XWiki lock file | |
| rm -f $XWIKI_LOCK_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment