Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added action hooks and lein for running on openshift diy

  • Loading branch information...
commit e9d640cbc05b9cd11d155b960b5a87727aa96f1f 1 parent 52f724c
Remco van 't Veer authored June 21, 2012
12  .openshift/action_hooks/start
... ...
@@ -0,0 +1,12 @@
  1
+#!/bin/bash
  2
+
  3
+export HTTP_CLIENT="wget --no-check-certificate -O"
  4
+export PORT=$OPENSHIFT_INTERNAL_PORT
  5
+export HOST=$OPENSHIFT_INTERNAL_IP
  6
+export HOME=$OPENSHIFT_DATA_DIR/home
  7
+export LEIN_JVM_OPTS=-Duser.home=$HOME
  8
+
  9
+cd $OPENSHIFT_REPO_DIR
  10
+$OPENSHIFT_REPO_DIR/bin/lein run > ${OPENSHIFT_LOG_DIR}/lein.log 2>&1 &
  11
+
  12
+disown
4  .openshift/action_hooks/stop
... ...
@@ -0,0 +1,4 @@
  1
+#!/bin/bash
  2
+
  3
+kill `ps -ef | grep lein | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1
  4
+exit 0
292  bin/lein
... ...
@@ -0,0 +1,292 @@
  1
+#!/bin/bash
  2
+
  3
+export LEIN_VERSION="1.7.1"
  4
+
  5
+case $LEIN_VERSION in
  6
+    *SNAPSHOT) SNAPSHOT="YES" ;;
  7
+    *) SNAPSHOT="NO" ;;
  8
+esac
  9
+
  10
+# Make sure classpath is in unix format for manipulating, then put
  11
+# it back to windows format when we use it
  12
+if [ "$OSTYPE" = "cygwin" ] && [ "$CLASSPATH" != "" ]; then
  13
+    CLASSPATH=`cygpath -up $CLASSPATH`
  14
+fi
  15
+
  16
+if [ `whoami` = "root" ] && [ "$LEIN_ROOT" = "" ]; then
  17
+    echo "WARNING: You're currently running as root; probably by accident."
  18
+    echo "Press control-C to abort or Enter to continue as root."
  19
+    echo "Set LEIN_ROOT to disable this warning."
  20
+    read _
  21
+fi
  22
+
  23
+NOT_FOUND=1
  24
+ORIGINAL_PWD="$PWD"
  25
+while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ]
  26
+do
  27
+    cd ..
  28
+    if [ "$(dirname "$PWD")" = "/" ]; then
  29
+        NOT_FOUND=0
  30
+        cd "$ORIGINAL_PWD"
  31
+    fi
  32
+done
  33
+
  34
+if [ "$LEIN_HOME" = "" ]; then
  35
+  if [ -d "$PWD/.lein" ] && [ "$PWD" != "$HOME" ]; then
  36
+    echo "Leiningen is running in bundled mode."
  37
+    export LEIN_HOME="$PWD/.lein"
  38
+  else
  39
+    export LEIN_HOME="$HOME/.lein"
  40
+  fi
  41
+fi
  42
+
  43
+DEV_PLUGINS="$(ls -1 lib/dev/*jar .lein-plugins/*jar 2> /dev/null)"
  44
+USER_PLUGINS="$(ls -1 "$LEIN_HOME"/plugins/*jar 2> /dev/null)"
  45
+
  46
+artifact_name () {
  47
+    which rev > /dev/null
  48
+    if [ $? -eq 0 ]; then
  49
+        echo "$1" | sed -e "s/.*\/\(.*\)/\1/" | \
  50
+            rev | sed -e "s/raj[-[:digit:].]*-\(.*\)/\1/" | rev
  51
+    else
  52
+        echo "$1"
  53
+    fi
  54
+}
  55
+
  56
+unique_user_plugins () {
  57
+    saveIFS="$IFS"
  58
+    IFS="$(printf '\n\t')"
  59
+
  60
+    plugins="$(echo "$DEV_PLUGINS"; echo "$USER_PLUGINS")"
  61
+    artifacts="$(for i in $plugins; do echo "$(artifact_name "$i")"; done)"
  62
+    duplicates="$(echo "$artifacts" | sort | uniq -d)"
  63
+
  64
+    if [ -z "$duplicates" ]; then
  65
+        echo "$USER_PLUGINS"
  66
+    else
  67
+        for i in $USER_PLUGINS; do
  68
+            artifact="$(artifact_name "$i")"
  69
+            if ! echo "$duplicates" | grep -xq "$artifact"; then
  70
+                echo "$i"
  71
+            fi
  72
+        done
  73
+    fi
  74
+    IFS="$saveIFS"
  75
+}
  76
+
  77
+LEIN_PLUGIN_PATH="$(echo "$DEV_PLUGINS" | tr \\n :)"
  78
+LEIN_USER_PLUGIN_PATH="$(echo "$(unique_user_plugins)" | tr \\n :)"
  79
+CLASSPATH="$CLASSPATH:$LEIN_PLUGIN_PATH:$LEIN_USER_PLUGIN_PATH:test/:src/:resources/"
  80
+LEIN_JAR="$LEIN_HOME/self-installs/leiningen-$LEIN_VERSION-standalone.jar"
  81
+CLOJURE_JAR="$HOME/.m2/repository/org/clojure/clojure/1.2.1/clojure-1.2.1.jar"
  82
+NULL_DEVICE=/dev/null
  83
+
  84
+# apply context specific CLASSPATH entries
  85
+if [ -f .lein-classpath ]; then
  86
+    CLASSPATH="`cat .lein-classpath`:$CLASSPATH"
  87
+fi
  88
+
  89
+# normalize $0 on certain BSDs
  90
+if [ "$(dirname "$0")" = "." ]; then
  91
+    SCRIPT="$(which $(basename "$0"))"
  92
+else
  93
+    SCRIPT="$0"
  94
+fi
  95
+
  96
+# resolve symlinks to the script itself portably
  97
+while [ -h "$SCRIPT" ] ; do
  98
+    ls=`ls -ld "$SCRIPT"`
  99
+    link=`expr "$ls" : '.*-> \(.*\)$'`
  100
+    if expr "$link" : '/.*' > /dev/null; then
  101
+        SCRIPT="$link"
  102
+    else
  103
+        SCRIPT="$(dirname "$SCRIPT"$)/$link"
  104
+    fi
  105
+done
  106
+
  107
+BIN_DIR="$(dirname "$SCRIPT")"
  108
+
  109
+if [ -r "$BIN_DIR/../src/leiningen/core.clj" ]; then
  110
+    # Running from source checkout
  111
+    LEIN_DIR="$(dirname "$BIN_DIR")"
  112
+    LEIN_LIBS="$(find -H "$LEIN_DIR/lib" -mindepth 1 -maxdepth 1 -print0 2> /dev/null | tr \\0 \:)"
  113
+    CLASSPATH="$CLASSPATH:$LEIN_LIBS:$LEIN_DIR/src:$LEIN_DIR/classes:$LEIN_DIR/resources:$LEIN_JAR"
  114
+
  115
+    if [ "$LEIN_LIBS" = "" -a "$1" != "self-install" -a ! -r "$LEIN_JAR" ]; then
  116
+        echo "Leiningen is missing its dependencies. Please see \"Building\" in the README."
  117
+        exit 1
  118
+    fi
  119
+else
  120
+    # Not running from a checkout
  121
+    CLASSPATH="$CLASSPATH:$LEIN_JAR"
  122
+
  123
+    if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then
  124
+        "$0" self-install
  125
+    fi
  126
+fi
  127
+
  128
+HTTP_CLIENT="wget --no-check-certificate -O"
  129
+if type -p curl >/dev/null 2>&1; then
  130
+    if [ "$https_proxy" != "" ]; then
  131
+        CURL_PROXY="-x $https_proxy"
  132
+    fi
  133
+    HTTP_CLIENT="curl $CURL_PROXY --insecure -f -L -o"
  134
+fi
  135
+
  136
+# If we don't have Leiningen's own Clojure on the bootclasspath, boot
  137
+# will be slower, and versions of Clojure in :dev-dependencies can
  138
+# take precedence.
  139
+if [ ! -r "$CLOJURE_JAR" ]; then
  140
+    CLOJURE_JAR_URL=http://build.clojure.org/releases/org/clojure/clojure/1.2.1/clojure-1.2.1.jar
  141
+    CLOJURE_HASH="be088d20c078ce48d42afba05984f1ef7c02142b"
  142
+    mkdir -p "$(dirname $CLOJURE_JAR)"
  143
+    $HTTP_CLIENT $CLOJURE_JAR $CLOJURE_JAR_URL
  144
+    if [ "`shasum -a 1 $CLOJURE_JAR | cut -f 1 -d \" \"`" != "$CLOJURE_HASH" ]; then
  145
+        echo "WARNING: Clojure jar failed to download from $CLOJURE_JAR_URL"
  146
+    fi
  147
+fi
  148
+
  149
+export JAVA_CMD=${JAVA_CMD:-"java"}
  150
+export LEIN_JAVA_CMD=${LEIN_JAVA_CMD:-$JAVA_CMD}
  151
+
  152
+# Support $JAVA_OPTS for backwards-compatibility.
  153
+export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}"
  154
+export LEIN_JVM_OPTS=${LEIN_JVM_OPTS:-$JVM_OPTS}
  155
+
  156
+# TODO: investigate http://skife.org/java/unix/2011/06/20/really_executable_jars.html
  157
+# If you're packaging this for a package manager (.deb, homebrew, etc)
  158
+# you need to remove the self-install and upgrade functionality.
  159
+if [ "$1" = "self-install" ]; then
  160
+    if [ -r "$LEIN_JAR" ]; then
  161
+      echo "The self-install jar already exists at $LEIN_JAR."
  162
+      echo "If you wish to re-download, delete it and rerun \"$0 self-install\"."
  163
+      exit 1
  164
+    fi
  165
+    echo "Downloading Leiningen now..."
  166
+    LEIN_DIR=`dirname "$LEIN_JAR"`
  167
+    mkdir -p "$LEIN_DIR"
  168
+    LEIN_URL="https://github.com/downloads/technomancy/leiningen/leiningen-$LEIN_VERSION-standalone.jar"
  169
+    $HTTP_CLIENT "$LEIN_JAR" "$LEIN_URL"
  170
+    if [ $? != 0 ]; then
  171
+        echo "Failed to download $LEIN_URL"
  172
+        if [ $SNAPSHOT = "YES" ]; then
  173
+            echo "If you have Maven installed, you can do"
  174
+            echo "mvn dependency:copy-dependencies; mv target/dependency lib"
  175
+            echo "See README.md for further SNAPSHOT build instructions."
  176
+        fi
  177
+        rm $LEIN_JAR 2> /dev/null
  178
+        exit 1
  179
+    fi
  180
+elif [ "$1" = "upgrade" ]; then
  181
+    if [ "$LEIN_DIR" != "" ]; then
  182
+        echo "The upgrade task is not meant to be run from a checkout."
  183
+        exit 1
  184
+    fi
  185
+    if [ $SNAPSHOT = "YES" ]; then
  186
+        echo "The upgrade task is only meant for stable releases."
  187
+        echo "See the \"Hacking\" section of the README."
  188
+        exit 1
  189
+    fi
  190
+    if [ ! -w "$SCRIPT" ]; then
  191
+        echo "You do not have permission to upgrade the installation in $SCRIPT"
  192
+        exit 1
  193
+    else
  194
+        TARGET_VERSION="${2:-"stable"}"
  195
+        echo "The script at $SCRIPT will be upgraded to the latest $TARGET_VERSION version."
  196
+        echo -n "Do you want to continue [Y/n]? "
  197
+        read RESP
  198
+        case "$RESP" in
  199
+            y|Y|"")
  200
+                echo
  201
+                echo "Upgrading from $LEIN_VERSION..."
  202
+                TARGET="/tmp/lein-$$-upgrade"
  203
+                LEIN_SCRIPT_URL="https://github.com/technomancy/leiningen/raw/$TARGET_VERSION/bin/lein"
  204
+                $HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL" \
  205
+                    && mv "$TARGET" "$SCRIPT" \
  206
+                    && chmod +x "$SCRIPT" \
  207
+                    && echo && "$SCRIPT" self-install && echo && echo "Now running" `$SCRIPT version`
  208
+                exit $?;;
  209
+            *)
  210
+                echo "Aborted."
  211
+                exit 1;;
  212
+        esac
  213
+    fi
  214
+else
  215
+    if [ "$OSTYPE" = "cygwin" ]; then
  216
+        # When running on Cygwin, use Windows-style paths for java
  217
+        CLOJURE_JAR=`cygpath -w "$CLOJURE_JAR"`
  218
+        ORIGINAL_PWD=`cygpath -w "$ORIGINAL_PWD"`
  219
+        CLASSPATH=`cygpath -wp "$CLASSPATH"`
  220
+        NULL_DEVICE=NUL
  221
+    fi
  222
+
  223
+    if [ $DEBUG ]; then
  224
+        echo $CLASSPATH
  225
+        echo $CLOJURE_JAR
  226
+    fi
  227
+
  228
+    JLINE=""
  229
+    if [ -z $INSIDE_EMACS ] && [ "$TERM" != "dumb" ]; then
  230
+        # Use rlwrap if it's available, otherwise fall back to JLine
  231
+        RLWRAP=`which rlwrap`
  232
+        if [ ! -x "$RLWRAP" ] || [ "$RLWRAP" = "" ]; then
  233
+            if [ ! -r "$LEIN_HOME/.jline-warn" ]; then
  234
+                echo "Using JLine for console I/O; install rlwrap for optimum experience."
  235
+                touch "$LEIN_HOME/.jline-warn"
  236
+            fi
  237
+            RLWRAP=""
  238
+            JLINE=jline.ConsoleRunner
  239
+            if [ "$OSTYPE" = "cygwin" ]; then
  240
+                JLINE="-Djline.terminal=jline.UnixTerminal jline.ConsoleRunner"
  241
+                CYGWIN_JLINE=y
  242
+            fi
  243
+        else
  244
+            # Test to see if rlwrap supports custom quote chars
  245
+            rlwrap -m -q '"' echo "hi" > /dev/null 2>&1
  246
+            if [ $? -eq 0 ]; then
  247
+                RLWRAP="$RLWRAP -r -m -q '\"'"
  248
+            fi
  249
+            # see if there is a clojure-completion-file
  250
+            RLWRAP_CLJ_WORDS_FILE=${RLWRAP_CLJ_WORDS_FILE:-"${HOME}/.clj_completions"}
  251
+            RLWRAP_CLJ_WORDS_OPTION=""
  252
+            if [ -r "${RLWRAP_CLJ_WORDS_FILE}" ]; then
  253
+                RLWRAP_CLJ_WORDS_OPTION="-f ${RLWRAP_CLJ_WORDS_FILE}";
  254
+            fi
  255
+            RLWRAP="${RLWRAP} $RLWRAP_OPTIONS -b \"(){}[],^%$#@\";:'\" ${RLWRAP_CLJ_WORDS_OPTION}"
  256
+        fi
  257
+    fi
  258
+
  259
+    test $CYGWIN_JLINE && stty -icanon min 1 -echo
  260
+
  261
+    TRAMPOLINE_FILE="/tmp/lein-trampoline-$$"
  262
+    if [ "$OSTYPE" = "cygwin" ]; then
  263
+        TRAMPOLINE_FILE=`cygpath -w $TRAMPOLINE_FILE`
  264
+    fi
  265
+
  266
+    # The -Xbootclasspath argument is optional here: if the jar
  267
+    # doesn't exist everything will still work, it will just have a
  268
+    # slower JVM boot.
  269
+
  270
+    ## TODO: -XX:+UseCompressedOops only works on 64 bit jvm
  271
+    # is there some way of detecting 64bit at this stage? - tavisrudd
  272
+    $RLWRAP $LEIN_JAVA_CMD \
  273
+        -Xbootclasspath/a:"$CLOJURE_JAR" \
  274
+        -client $LEIN_JVM_OPTS \
  275
+        -XX:+TieredCompilation \
  276
+        -Dleiningen.original.pwd="$ORIGINAL_PWD" \
  277
+        -Dleiningen.trampoline-file=$TRAMPOLINE_FILE \
  278
+        -cp "$CLASSPATH" \
  279
+        $JLINE clojure.main \
  280
+        -e "(use 'leiningen.core)(-main)" \
  281
+        $NULL_DEVICE "$@"
  282
+    EXIT_CODE=$?
  283
+
  284
+    if [ -r $TRAMPOLINE_FILE ]; then
  285
+        TRAMPOLINE="$(cat $TRAMPOLINE_FILE)"
  286
+        rm $TRAMPOLINE_FILE
  287
+        exec sh -c "exec $TRAMPOLINE"
  288
+    else
  289
+        test $CYGWIN_JLINE && stty icanon echo
  290
+        exit $EXIT_CODE
  291
+    fi
  292
+fi
5  src/nos_tour_comments/core.clj
@@ -29,5 +29,6 @@
29 29
 (def app (-> handler (wrap-file "public") (wrap-file-info) wrap-gzip))
30 30
 
31 31
 (defn -main []
32  
-  (let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
33  
-    (run-jetty #'app {:port port})))
  32
+  (let [host (get (System/getenv) "HOST")
  33
+        port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
  34
+    (run-jetty #'app {:host host :port port})))

0 notes on commit e9d640c

Please sign in to comment.
Something went wrong with that request. Please try again.