Skip to content

Commit

Permalink
openshift now running as jetty.
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo1905 committed Jun 17, 2012
1 parent bc53c6c commit ddb54fb
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 41 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ zktodo2test.dat.properties
/.project
/.classpath
/.settings
/.openshift
/zktodo2test.dat.script
/nohup.out
12 changes: 12 additions & 0 deletions .openshift/action_hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# This is a simple build script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the deploy step. This script gets executed directly, so it
# could be python, php, ruby, etc.
#
# cannot write to ~/.m2 so we configure mvn to have a local jar cache elsewhere
mkdir -p ${OPENSHIFT_DATA_DIR}/m2/repository
echo -e "<settings><localRepository>${OPENSHIFT_DATA_DIR}m2/repository</localRepository>\n</settings>\n" > ${OPENSHIFT_DATA_DIR}/settings.xml
#
cd ${OPENSHIFT_REPO_DIR}
mvn -Dmaven.test.skip=true -s ${OPENSHIFT_DATA_DIR}settings.xml package
5 changes: 5 additions & 0 deletions .openshift/action_hooks/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# This deploy hook gets executed after dependencies are resolved and the
# build hook has been run but before the application has been started back
# up again. This script gets executed directly, so it could be python, php,
# ruby, etc.
4 changes: 4 additions & 0 deletions .openshift/action_hooks/post_deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# This is a simple post deploy hook executed after your application
# is deployed and started. This script gets executed directly, so
# it could be python, php, ruby, etc.
5 changes: 5 additions & 0 deletions .openshift/action_hooks/pre_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# This is a simple script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the build step. This script gets executed directly, so it
# could be python, php, ruby, etc.
6 changes: 6 additions & 0 deletions .openshift/action_hooks/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
#
nohup java -Djetty.host=${OPENSHIFT_INTERNAL_IP} -Djetty.port=${OPENSHIFT_INTERNAL_PORT} -DDATABASE_URL=postgres://${OPENSHIFT_DB_USERNAME}:${OPENSHIFT_DB_PASSWORD}@${OPENSHIFT_DB_HOST}/${OPENSHIFT_GEAR_NAME} -jar ${OPENSHIFT_REPO_DIR}target/jetty-runner-jmx.jar --port ${OPENSHIFT_INTERNAL_PORT} --config ${OPENSHIFT_REPO_DIR}src/etc/jetty.xml ${OPENSHIFT_REPO_DIR}/target/zktodo2.war > ${OPENSHIFT_LOG_DIR}server.log 2>&1 &
6 changes: 6 additions & 0 deletions .openshift/action_hooks/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# The logic to stop your application should be put in this script.
#
# Here we do a polite SIGTERM which both the jvm and jetty respond to (post deploy we will do a hard kill in case it stays hung)
ps -ef | grep zktodo2.war | grep -v grep | awk '{ print $2 }' | xargs kill -SIGTERM > /dev/null 2>&1
exit 0
48 changes: 9 additions & 39 deletions openshift.build.and.run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Create Domain, Application and Database
# if you don't have one yet you need to create a domain on their cloud (pick your own name not 'zkdemo')
rhc-create-domain -n zkdemo -l your@login.email -p

#setup the cloud app instance as jbossas-7 (okay to set the app name to 'zktd2')
rhc-create-app -a zktd2 -t jbossas-7
#setup the cloud app instance as DIY type (okay to set the app name to 'zktd2')
rhc-create-app -a zktd2 -t diy-0.1 -p

# details can be confirmed with by logging into the openshift web console
# your app is UUID@appname-namespace.rhcloud.com (e.g. 62f0ef4ab25b47de8702c9ed12bfdbaf@zktd2-zkdemo.rhcloud.com)
# you can login to your cloud instance with "ssh UUID@appname-namespace.rhcloud.com"
# if you get permission denied add your ~/.ssh/id_rsa.pub key
# as your SSH PUBLIC KEY on the openshift console (required to push code)
# ensure you can login to your cloud instance with "ssh UUID@appname-namespace.rhcloud.com"
# if you get permission denied add your local ~/.ssh/id_rsa.pub key
# as your SSH PUBLIC KEY on your openshift console (this required to push code to the server)

# add a postregsql database to your instance
# important! note down the details of your database including password, db, url (which has host ip) as output by this command
Expand All @@ -50,14 +51,16 @@ Create Domain, Application and Database
#ssh to your cloud instance, connect to the database and run a test query, create the table (find the UUID on your web console and use your app-domain.rhcloud.com)
ssh 62f0ef4ab25b47de8702c9ed12bfdbaf@zktd2-zkdemo.rhcloud.com
# the password and ip to use were on the output of the create database command you ran as well as your database name
PGPASSWORD=xxxx psql -h 127.11.255.1 -U admin -d zktd2
PGPASSWORD=${OPENSHIFT_DB_PASSWORD} psql -h ${OPENSHIFT_DB_HOST} -U ${OPENSHIFT_DB_USERNAME} -d zktd2
select 1 as a, 2 as b, 3 as c;
CREATE TABLE reminder ( reminder_id bigint NOT NULL, date timestamp without time zone, name character varying(255), priority integer, CONSTRAINT reminder_pkey PRIMARY KEY (reminder_id ));
\q
exit

# go into the server folder on your workstation and git pull in the demo source code into the server
cd zktd2/
# backup the readme file as it has interesting infomation about your app
cp README ..
#add the demo code repo to the folder
git remote add upstream https://simbo1905@github.com/simbo1905/ZkToDo2.git
# in the next command just hit return if asked for a password for downloading the code
Expand Down Expand Up @@ -103,38 +106,5 @@ using a completely different set of commands.
I don't have any tips for debugging as I always debug with embedded jetty:run with a local spring
setup then push to containers. Its always worth the overhead to set this up to debug locally without a full j2ee container.

Running Locally - (Not Kept Up To Date)
=======================================

To develop locally on JBossAS7.0 & MySQL 5.x DB (your gonna need it to do anything more serious
than the demo app):

#use the versions they are currently using when you created your openshift!
unzip boss-as-web-7.0.x.Final.zip
setup a local mysql database server

create com.mysql JDBC driver for your local JBossAS7.0 standalone config
http://community.jboss.org/wiki/DataSourceConfigurationInAS7
step "Installing a JDBC driver as a module" @ that page
step "Defining the DataSource itself" @ that page

your openshift app will deploy as ROOT.war so you need to disable the JBossAS7.0 welcome page
in $JBOSS_HOME/standalone/configuration/standalone.xml set "enable-welcome-root=false"

ensure that you have your local db settings as environment variables before you run the code
export OPENSHIFT_DB_HOST=localhost
export OPENSHIFT_DB_PORT=3306
export OPENSHIFT_DB_USERNAME=zk_db_user
export OPENSHIFT_DB_PASSWORD=zk_db_passwd

build the app setting the profile 'openzone' to package the mysql settings and deploy to local server

mvn -Dmaven.test.skip=true -P openzone clean package
cp deployments/ROOT.war $JBOSSAS7_HOME/standalone/deployments
$JBOSSAS7_HOME/bin/standalone.sh
# open a browser http://127.0.0.1:9999

If you have issue don't ask me; use the JBoss forums and the opensift forums.

End.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
</dependency>
</dependencies>
<build>
<finalName>zktodo2-${project.version}</finalName>
<finalName>zktodo2</finalName>
<plugins>
<!-- run jetty from eclipse or commandline with jmx enable for jconsole or StopJettyJmx.jar clean shutdown -->
<plugin>
Expand Down

0 comments on commit ddb54fb

Please sign in to comment.