Skip to content

Instantly share code, notes, and snippets.

@ssummer3
Forked from monksy/upgradeServicefolderByGit.sh
Last active February 22, 2016 21:32
Show Gist options
  • Select an option

  • Save ssummer3/a3898742dec3f67b7c11 to your computer and use it in GitHub Desktop.

Select an option

Save ssummer3/a3898742dec3f67b7c11 to your computer and use it in GitHub Desktop.
This gist is responsible for upgrading a system service (systemd) and going into the folder by it's specified user and performing a git pull. After the pull occures bring the service back up.
#! /bin/bash
set -o nounset
set -o errexit
if [[ $# -lt 3 ]]; then
echo "No arguments supplied."
echo " Example: upgradeFoldByBash: [Service name] [service account] [folder]"
exit 1
fi
SUDO="sudo -u ${2}"
pushd "${3}" >/dev/null
echo "Fetching updates."
${SUDO} git fetch
# only if we have updates to apply...
if [[ -n "$(${SUDO} git rev-list @{u}...)" ]]; then
echo "Stopping the ${1} Service"
systemctl stop ${1}
echo "Performing the update."
${SUDO} git merge
echo "Restarting the ${1} Service"
systemctl start ${1}
else
echo "No update needed."
fi
popd >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment