Permalink
Browse files

Finished moving script templates into ./resources

  • Loading branch information...
zk committed May 1, 2010
1 parent 0726b68 commit 2333331b4bf2bdfdfc6fe21cafd0bb6f36a0ecea
Showing with 123 additions and 97 deletions.
  1. +8 −0 resources/clean-template
  2. +63 −0 resources/init-script-template
  3. +17 −0 resources/install-template
  4. +35 −97 src/leiningen/init_script.clj
View
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+NAME=%s
+JAR_INSTALL_DIR=%s
+INIT_SCRIPT_INSTALL_DIR=%s
+
+rm -f $JAR_INSTALL_DIR/"$NAME"-standalone.jar
+rm -f $INIT_SCRIPT_INSTALL_DIR/"$NAME"d
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+NAME=%s
+PID_DIR=%s
+PID_FILE=$PID_DIR/$NAME.pid
+INSTALL_DIR=%s
+INSTALL_JAR=$INSTALL_DIR/"$NAME"-standalone.jar
+mkdir -p $PID_DIR
+
+start() {
+ if [ -e $PID_FILE ]
+ then
+ echo "$NAME is already running as process `cat $PID_FILE`."
+ exit 1
+ fi
+ echo "Starting $NAME"
+ java -jar $INSTALL_JAR > /dev/null &
+ PID=$!
+ echo $PID > $PID_FILE
+ exit 0
+}
+
+stop() {
+ if [ ! -e $PID_FILE ]
+ then
+ echo "$NAME is not running."
+ else
+ echo "Shutting down $NAME"
+ kill `cat $PID_FILE`
+ rm $PID_FILE
+ fi
+}
+
+status() {
+ if [ -e $PID_FILE ]
+ then
+ echo "$NAME is running."
+ else
+ echo "$NAME is not running."
+ fi
+ exit 0
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ *)
+ echo "Usage: "$NAME"d {start|stop|status|restart}"
+ exit 1
+ ;;
+esac
+exit $?
View
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+NAME=%s
+JAR_INSTALL_DIR=%s
+ARTIFACT_UBERJAR_PATH=%s
+INIT_SCRIPT_INSTALL_DIR=%s
+ARTIFACT_INIT_SCRIPT_PATH=%s
+INSTALLED_INIT_SCRIPT_PATH=%s
+
+#standalone jar
+mkdir -p $JAR_INSTALL_DIR
+cp $ARTIFACT_UBERJAR_PATH $JAR_INSTALL_DIR/"$NAME"-standalone.jar
+
+#init script
+mkdir -p $INIT_SCRIPT_INSTALL_DIR
+cp $ARTIFACT_INIT_SCRIPT_PATH $INIT_SCRIPT_INSTALL_DIR
+chmod u+x $INSTALLED_INIT_SCRIPT_PATH
@@ -6,7 +6,41 @@
(def gen-init-script)
(def gen-install-script)
-(def gen-clean-script)
+
+(defn resource-input-stream [res-name]
+ (.getResourceAsStream (.getContextClassLoader (Thread/currentThread)) res-name))
+
+
+(def init-script-template (slurp* (resource-input-stream "init-script-template")))
+(def install-template (slurp* (resource-input-stream "install-template")))
+(def clean-template (slurp* (resource-input-stream "clean-template")))
+
+(defn gen-init-script [project opts]
+ (let [name (:name project)
+ description (:description project)
+ pid-dir (:pid-dir opts)
+ jar-install-dir (:jar-install-dir opts)]
+ (format init-script-template name pid-dir jar-install-dir)))
+
+(defn gen-install-script [uberjar-path init-script-path opts]
+ (let [jar-install-dir (:jar-install-dir opts)
+ init-script-install-dir (:init-script-install-dir opts)
+ name (:name opts)
+ installed-init-script-path (str init-script-install-dir "/" name "d")]
+ (format install-template
+ name
+ jar-install-dir
+ uberjar-path
+ init-script-install-dir
+ init-script-path
+ installed-init-script-path)))
+
+(defn gen-clean-script [project opts]
+ (let [jar-install-dir (:jar-install-dir opts)
+ init-script-install-dir (:init-script-install-dir opts)
+ name (:name project)]
+ (format clean-template name jar-install-dir init-script-install-dir)))
+
(defn create-output-dir [path]
(.mkdirs (java.io.File. path)))
@@ -40,100 +74,4 @@
(spit clean-script-path (gen-clean-script projects opts))
(println (str "*** Done generating init scripts, see the " artifact-dir " directory"))))
-(defn gen-install-script [uberjar-path init-script-path opts]
- (let [jar-install-dir (:jar-install-dir opts)
- init-script-install-dir (:init-script-install-dir opts)
- name (:name opts)
- installed-init-script-path (str init-script-install-dir "/" name "d")]
- (str "#!/bin/bash
-mkdir -p " jar-install-dir "
-cp " uberjar-path " " jar-install-dir "/" name "-standalone.jar
-mkdir -p " init-script-install-dir "
-cp " init-script-path " " init-script-install-dir "
-chmod u+x " installed-init-script-path "
-")))
-
-(defn gen-clean-script [project opts]
- (let [jar-install-dir (:jar-install-dir opts)
- init-script-install-dir (:init-script-install-dir opts)
- name (:name project)]
- (str "#!/bin/bash
-rm -f " jar-install-dir "/" name "-standalone.jar
-rm -f " init-script-install-dir "/" name "d
-")))
-
-
-(defn gen-init-script [project opts]
- (let [name (:name project)
- description (:description project)
- pid-dir (:pid-dir opts)
- jar-install-dir (:jar-install-dir opts)]
- (str "#!/bin/bash
-#
-# /etc/rc.d/init.d/" name "d
-#
-# " name " daemon
-# " description "
-#
-
-NAME=" name "
-PID_DIR=" pid-dir "
-PID_FILE=$PID_DIR/$NAME.pid
-INSTALL_DIR=" jar-install-dir "
-INSTALL_JAR=$INSTALL_DIR/$NAME-standalone.jar
-mkdir -p $PID_DIR
-
-start() {
- if [ -e $PID_FILE ]
- then
- echo \"$NAME is already running as process `cat $PID_FILE`.\"
- exit 1
- fi
- echo \"Starting $NAME\"
- java -jar $INSTALL_JAR > /dev/null &
- PID=$!
- echo $PID > $PID_FILE
- exit 0
-}
-
-stop() {
- if [ ! -e $PID_FILE ]
- then
- echo \"$NAME is not running.\"
- else
- echo \"Shutting down $NAME\"
- kill `cat $PID_FILE`
- rm $PID_FILE
- fi
-}
-
-status() {
- if [ -e $PID_FILE ]
- then
- echo \"$NAME is running.\"
- else
- echo \"$NAME is not running.\"
- fi
- exit 0
-}
-case \"$1\" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status
- ;;
- restart)
- stop
- start
- ;;
- *)
- echo \"Usage: $NAME\"\"d {start|stop|status|restart}\"
- exit 1
- ;;
-esac
-exit $?")))

0 comments on commit 2333331

Please sign in to comment.