Skip to content

Instantly share code, notes, and snippets.

@bdelacretaz
Created November 7, 2014 08:43
Show Gist options
  • Save bdelacretaz/03ece77da0a10741b8fb to your computer and use it in GitHub Desktop.
Save bdelacretaz/03ece77da0a10741b8fb to your computer and use it in GitHub Desktop.
Bruce Edge's debian package patch for Sling
diff --git a/launchpad/builder/pom.xml b/launchpad/builder/pom.xml
index 079cd92..2e216a8 100644
--- a/launchpad/builder/pom.xml
+++ b/launchpad/builder/pom.xml
@@ -65,6 +65,12 @@
Context path of the Sling web application
-->
<jetty.sling.context>/</jetty.sling.context>
+
+ <!--
+ jdeb plugin version for debian package
+ -->
+ <jdeb.version>1.0.1</jdeb.version>
+
</properties>
<build>
@@ -284,6 +290,41 @@
</filters>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>jdeb</artifactId>
+ <groupId>org.vafer</groupId>
+ <version>${jdeb.version}</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>jdeb</goal>
+ </goals>
+ <configuration>
+ <dataSet>
+ <data>
+ <src>${project.build.directory}/${project.artifactId}-${project.version}-standalone.jar</src>
+ <type>file</type>
+ <mapper>
+ <type>perm</type>
+ <prefix>/opt/sling/${project.artifactId}</prefix>
+ </mapper>
+ </data>
+ <data>
+ <src>${project.basedir}/src/root_fs/</src>
+ <type>directory</type>
+ <excludes>**/.svn/</excludes>
+ <mapper>
+ <type>perm</type>
+ <prefix>/</prefix>
+ </mapper>
+ </data>
+ </dataSet>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
<reporting>
diff --git a/launchpad/builder/src/deb/control/control b/launchpad/builder/src/deb/control/control
new file mode 100644
index 0000000..70d8b25
--- /dev/null
+++ b/launchpad/builder/src/deb/control/control
@@ -0,0 +1,9 @@
+Package: [[artifactId]]
+Version: [[version]]
+Section: misc
+Priority: optional
+Architecture: all
+Maintainer: Bruce Edge <bruce.edge@nextissuemedia.com>
+Depends: oracle-java7-installer
+Description: [[description]]
+Distribution: development
diff --git a/launchpad/builder/src/deb/control/postinst b/launchpad/builder/src/deb/control/postinst
new file mode 100644
index 0000000..e8ee193
--- /dev/null
+++ b/launchpad/builder/src/deb/control/postinst
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+echo $0 $*
+[ "$DEBUG" ] && set -x
+
+
+
+SLING_DEFAULTS=/etc/default/sling
+if [ ! -e $SLING_DEFAULTS ] ; then
+ cp $SLING_DEFAULTS.sample $SLING_DEFAULTS
+fi
+. $SLING_DEFAULTS
+
+chmod +x /etc/init.d/sling
+
+# Check for sling user
+if ! getent passwd | grep -q sling ; then
+ useradd --home-dir $SLING_HOME --gid adm $SLING_USER
+fi
+
+# Make data dir
+SLING_DATA=/var/lib/sling
+if [ ! -d $SLING_DATA ] ; then
+ echo Create $SLING_DATA
+ mkdir -p $SLING_DATA
+ chown -R $SLING_USER:adm $SLING_DATA
+fi
+
+# Make log dir
+if [ ! -d $SLING_LOG_DIR ] ; then
+ echo Create $SLING_LOG_DIR
+ mkdir -p $SLING_LOG_DIR
+ chown -R $SLING_USER:adm $SLING_LOG_DIR
+fi
+
diff --git a/launchpad/builder/src/deb/control/preinst b/launchpad/builder/src/deb/control/preinst
new file mode 100755
index 0000000..eac1403
--- /dev/null
+++ b/launchpad/builder/src/deb/control/preinst
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+echo $0 $*
+[ "$DEBUG" ] && set -x
+
+
diff --git a/launchpad/builder/src/deb/control/prerm b/launchpad/builder/src/deb/control/prerm
new file mode 100644
index 0000000..9541cac
--- /dev/null
+++ b/launchpad/builder/src/deb/control/prerm
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+echo $0 $*
+[ "$DEBUG" ] && set -x
+
+. /etc/default/sling || exit
+
+if [ remove = "$1" ]; then
+ rm -f $SLING_DEFAULTS
+ if [ "$SLING_DATA" && -d $SLING_DATA ] ; then
+ echo Purge $SLING_DATA
+ rm -rf $SLING_DATA
+ fi
+fi
diff --git a/launchpad/builder/src/root_fs/etc/default/sling.sample b/launchpad/builder/src/root_fs/etc/default/sling.sample
new file mode 100644
index 0000000..1f2e1ed
--- /dev/null
+++ b/launchpad/builder/src/root_fs/etc/default/sling.sample
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# sling defaults
+
+set -a
+SLING_DATA=/var/lib/sling
+set +a
+
+# usage: org.apache.sling.launchpad.app.Main [ start | stop | status ] [ -j adr ] [ -l loglevel ] [ -f logfile ] [ -c slinghome ] [ -i launchpadhome ] [ -a address ] [ -p port ] { -Dn=v } [ -h ]
+# start listen for control connection (uses -j)
+# stop terminate running Apache Sling (uses -j)
+# status check whether Apache Sling is running (uses -j)
+# -j adr host and port to use for control connection in the format '[host:]port' (default 127.0.0.1:0)
+# -l loglevel the initial loglevel (0..4, FATAL, ERROR, WARN, INFO, DEBUG)
+# -f logfile the log file, "-" for stdout (default logs/error.log)
+# -c slinghome the sling context directory (default sling)
+# -i launchpadhome the launchpad directory (default slinghome)
+# -a address the interfact to bind to (use 0.0.0.0 for any)
+# -p port the port to listen to (default 8080)
+# -r path the root servlet context path for the http service (default is /)
+# -n don't install the shutdown hook
+# -Dn=v sets property n to value v. Make sure to use this option *after* the jar filename. The JVM also has a -D option which has a different meaning
+# -h prints this usage message
+
+SLING_DEFAULT_ARGS="-c $SLING_DATA -p 8090"
+
+# Don't change anything below this line unless you want to break something
+# ========================================================================
+
+set -a
+SLING_HOME=/opt/sling
+SLING_LOG_DIR=/var/log/sling
+LOG_FILE=$SLING_LOG_DIR/${NAME}-start.log
+SLING_USER=sling
+SLING_DATA=/var/lib/sling
+SLING_DEFAULTS=/etc/default/sling
+set +a
diff --git a/launchpad/builder/src/root_fs/etc/init.d/sling b/launchpad/builder/src/root_fs/etc/init.d/sling
new file mode 100755
index 0000000..85bdd4e
--- /dev/null
+++ b/launchpad/builder/src/root_fs/etc/init.d/sling
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+#
+# Usage
+#
+function usage () {
+ echo "Purpose: Stop/Start sling"
+ echo "Usage : $0 { stop | start }"
+}
+
+NAME=sling
+
+PID=/var/run/${NAME}.pid
+
+[ "$DEBUG" ] && set -x
+
+. /etc/profile
+
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
+
+SLING_DEFAULTS=/etc/default/sling
+[ -r $SLING_DEFAULTS ] && . $SLING_DEFAULTS
+
+SLING_JAR=$(find $SLING_HOME -name \*-standalone.jar)
+
+running()
+{
+ local PID=$(cat "$1" 2>/dev/null) || return 1
+ kill -0 "$PID" 2>/dev/null
+}
+
+#
+# Kill current sling instance
+#
+function stop () {
+ start-stop-daemon --stop --pidfile $PID --chdir $SLING_HOME --startas "./$NAME" --signal KILL
+}
+
+#
+# Start batch job scheduler
+#
+function start () {
+
+ if start-stop-daemon --start \
+ --chdir "$SLING_HOME" \
+ --chuid $SLING_USER \
+ --pidfile "$PID" \
+ --make-pidfile \
+ --startas $(which java) \
+ -- -jar $SLING_JAR $SLING_DEFAULT_ARGS \
+ >>$LOG_FILE 2>&1 &
+ then
+ sleep 3s
+ if running "$PID"
+ then
+ echo "OK"
+ else
+ echo "FAILED"
+ fi
+ fi
+
+}
+
+if test -z "$1"; then
+ usage
+ exit
+fi
+case $1 in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ sleep 1
+ start
+ ;;
+ *)
+ echo "Unknown parameter: $1"
+ usage
+ ;;
+ esac
+
+
+# end_of_file
diff --git a/launchpad/builder/src/root_fs/etc/logrotate.d/sling b/launchpad/builder/src/root_fs/etc/logrotate.d/sling
new file mode 100644
index 0000000..cf06eb5
--- /dev/null
+++ b/launchpad/builder/src/root_fs/etc/logrotate.d/sling
@@ -0,0 +1,9 @@
+/var/log/sling/sling-start.log {
+ rotate 5
+ size 4M
+ copytruncate
+ daily
+ compress
+ missingok
+ notifempty
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment