Skip to content

Instantly share code, notes, and snippets.

@dkhenry
Last active December 24, 2015 02:29
Show Gist options
  • Save dkhenry/6730942 to your computer and use it in GitHub Desktop.
Save dkhenry/6730942 to your computer and use it in GitHub Desktop.
Using git-deploy and systemd to deploy Play2 webdsites

This uses systemd to control a play2 service

I also am including the git-deploy configuration to update and restart the service from a devleopment machine

  • play2.service

    The SystemD script Place in /etc/systemd/system/

  • after_push

    The after push configuration file goes in /deploy

  • before_restart

    The before restart file goes in /deploy

  • restart

    The restart file goes in /deploy

Note:

This still requires sbt to be installed on the remote server. I am looking at how to just build everything locally before I push

#!/usr/bin/env bash
set -e
oldrev=$1
newrev=$2
run() {
[ -x $1 ] && $1 $oldrev $newrev
}
echo files changed: $(git diff $oldrev $newrev --diff-filter=ACDMR --name-only | wc -l)
umask 002
git submodule init && git submodule sync && git submodule update
run deploy/before_restart
run deploy/restart && run deploy/after_restart
systemctl stop play2.service
sbt clean compile stage
[Unit]
Description=Play2 Server for <site>
After=network.target
[Service]
Type=simple
PIDFile=/opt/<site>/RUNNING_PID
ExecStart=/opt/CookieFix.com/target/start
ExecStop=/bin/kill -9 $MAINPID
ExecStopPost=/bin/rm /opt/CookieFix.com/RUNNING_PID
ExecRestart=/bin/kill $MAINPID
Restart=true
[Install]
WantedBy=multi-user.target
#!/bin/sh
touch tmp/restart.txt
echo "restarting Play app"
systemctl restart play2.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment