I use webfaction.com to host gidley.co.uk and I notice they have started letting us run any application. So finally this may let me use Java for bits of my own website. To date I haven’t done this as java app hosting is much more expensive than PHP.
I have decided to use Jetty and see how hard it is to get going.
Steps
- Create a custom application - this tells you the folder and port to use.
- Download Sun JDK 1.6 (the bin version) and upload it to webfaction
- Download Jetty and upload it to webfaction
- Edit jetty.xml and set
- The TCP Port to be the assigned port (from webfaction control panel)
- You may want to disable request logging by removing references to it
- Create a script to start jetty - make sure you set the -Xmx parameter to be less than your hosting plan.
JAVA_OPTS=-Xmx64M
#!/bin/bash
JETTY_HOME=/home2/bgidley/webapps/webtide/jetty
JAVA_HOME=/home2/bgidley/webapps/webtide/jdk
TEST=`pgrep java -u bgidley`#if [ $(ps -ef | grep java | grep bgidley | grep -v grep) ] ; then
if [ -z $TEST ] ; then
echo “Jetty Not Running so starting”
cd $JETTY_HOME
nohup $JAVA_HOME/bin/java $JAVA_OPTS -jar start.jar &
echo $(ps -ef | grep java | grep bgidley | grep -v grep)
else
echo “Running”
fi - Start it and map it into one of your sites in control page.
- Optionally add the startup script to cron to restart it every 20 minutes if it crashes.
Post a Comment