Create a gist now

Instantly share code, notes, and snippets.

@sheerun /deploy.sh
Last active Apr 25, 2017

Embed
What would you like to do?
#!/bin/bash
export NAME=ghost
export TARGET=root@1.2.3.4
export SERVICE=$(mktemp)
cat > $SERVICE <<EOF
[Unit]
Description=Ghost
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop ghost
ExecStartPre=-/usr/bin/docker rm ghost
ExecStartPre=/usr/bin/docker pull ghost:latest
ExecStart=/usr/bin/docker run --rm --name ghost -p 80:2368 ghost
[Install]
WantedBy=multi-user.target
EOF
echo "Uploading $NAME service..."
rsync $SERVICE $TARGET:/etc/systemd/system/$NAME.service
echo "Restarting $NAME service..."
ssh $TARGET "systemctl daemon-reload && systemctl restart ghost --no-block"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment