Skip to content

Instantly share code, notes, and snippets.

@fclairamb
Last active December 21, 2015 20:09
Show Gist options
  • Save fclairamb/6359276 to your computer and use it in GitHub Desktop.
Save fclairamb/6359276 to your computer and use it in GitHub Desktop.
Jetty debian package builder. It takes the jetty script as is and build a jetty server that runs at startup. It's quick & simple version. Improvements are welcome.
#!/bin/sh
JETTY_VERSION=9.0.5.v20130815
# We reset everything
rm -Rf jetty-distribution-${JETTY_VERSION} jetty
# We prepare the dirs
mkdir -p jetty/opt jetty/etc/init.d jetty/etc/default jetty/DEBIAN
# We download the archive
wget -c http://eclipse.ialto.com/jetty/stable-9/dist/jetty-distribution-${JETTY_VERSION}.zip
unzip jetty-distribution-${JETTY_VERSION}.zip
# We copy the main files
mv jetty-distribution-${JETTY_VERSION} jetty/opt/jetty-${JETTY_VERSION}
ln -s jetty-${JETTY_VERSION} jetty/opt/jetty
# We remove the demo files
rm -Rf jetty/opt/jetty/webapps.demo
cp jetty/opt/jetty/bin/jetty.sh jetty/etc/init.d/jetty || return 1
# We prepare the default file
cat <<EOF > jetty/etc/default/jetty
JETTY_USER=jetty
JETTY_HOME=/opt/jetty
EOF
chmod +x jetty/etc/default/jetty
# We have all the files, we just have to prepare the debian package file
cat <<EOF > jetty/DEBIAN/control
Package: jetty
Priority: optional
Section: web
Maintainer: Florent Clairambault
Architecture: all
Version: ${JETTY_VERSION}
Depends: oracle-java7-installer
Description: Whatever
EOF
cat <<EOF > jetty/DEBIAN/postinst
#!/bin/sh
groupadd -r -f jetty
useradd -r -s /sbin/nologin -d /opt/jetty --gid jetty jetty
chown -R jetty:jetty /opt/jetty-${JETTY_VERSION}
cd /etc/init.d ; update-rc.d -f jetty defaults 2>/dev/null
service jetty start || /bin/echo "Could not start jetty !"
EOF
chmod 0755 jetty/DEBIAN/postinst
cat <<EOF > jetty/DEBIAN/prerm
#!/bin/sh
service jetty stop
cd /etc/init.d ; update-rc.d -f jetty remove 2>/dev/null
killall -9 -u jetty
userdel jetty || echo "No user jetty ? --> Not a big deal"
#groupdel jetty || echo "No group jetty ? --> Not a big deal"
EOF
chmod 0755 jetty/DEBIAN/prerm
dpkg-deb -b jetty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment