Skip to content

Instantly share code, notes, and snippets.

@pulecp
Last active February 23, 2018 19:18
Show Gist options
  • Save pulecp/d0be93124968d42276f1 to your computer and use it in GitHub Desktop.
Save pulecp/d0be93124968d42276f1 to your computer and use it in GitHub Desktop.
The build script of .rpm package for graphhopper application: https://github.com/graphhopper/graphhopper
#!/bin/bash
rm -f *.rpm
rm -rf graphhopper
# clone and build the ap
git clone git://github.com/graphhopper/graphhopper.git
cd graphhopper
mvn --projects web -DskipTests=true install assembly:single
RELEASE=`git rev-list --all | wc -l`
VERSION=$(grep "<name>" -A 1 pom.xml | grep version | cut -d'>' -f2 | cut -d'<' -f1) #that command is overtaken from graphhopper.sh
# remove unnecessary stuff
rm -rf .git
# prepare before-install script which will create graphhopper user
cd ..
cat << EOF > before_install.sh
#!/bin/sh
if ! id -u "graphhopper" >/dev/null 2>&1; then
useradd -r -d /dev/null -s /sbin/nologin graphhopper
fi
EOF
cat << EOF > after_install.sh
#!/bin/sh
/bin/systemctl daemon-reload
/bin/chown -R graphhopper /opt/graphhopper
EOF
cat << EOF > graphhopper.conf
# Configuration for graphhopper
JAR_FILE="./web/target/graphhopper-web-${VERSION}-with-dep.jar"
JAVA_OPTS="jetty.port=8989 jetty.host=0.0.0.0 jetty.resourcebase=./web/src/main/webapp config=config-example.properties"
OSMREADER="belgium-latest.osm.pbf"
EOF
cat << EOF > graphhopper.service
; Graphhopper systemd service unit file
[Unit]
Description=Graphhopper
Requires=network.target
After=syslog.target
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/graphhopper
User=graphhopper
EnvironmentFile=-/etc/graphhopper.conf
ExecStart=/bin/java -server -jar \$JAR_FILE \$JAVA_OPTS osmreader.osm=\${OSMREADER}
ExecStop=/bin/kill -TERM \$MAINPID
TimeoutSec=300
[Install]
WantedBy=multi-user.target
EOF
# build the .rpm
echo 'buidling .rpm'
fpm -s dir -t rpm -d java \
--name "graphhopper" \
--version "0.6" \
--iteration "${RELEASE}" \
--architecture noarch \
--prefix / \
--vendor 'Inuits' \
--description 'Graphhopper app' \
--maintainer 'Jenkins' \
--epoch '1' \
--before-install before_install.sh \
--after-install after_install.sh \
graphhopper=/opt graphhopper.conf=/etc/graphhopper.conf graphhopper.service=/etc/systemd/system/graphhopper.service
rpm -qlp *.rpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment