Skip to content

Instantly share code, notes, and snippets.

@ajroetker
Created June 11, 2014 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajroetker/ea494d8518a93fa31728 to your computer and use it in GitHub Desktop.
Save ajroetker/ea494d8518a93fa31728 to your computer and use it in GitHub Desktop.
bounce_service from installer
# 1. Name of service .
bounce_service() {
prepare_platform
# If all three of these are true it is using upstart, so we need to grep the results of service rather than trusting the return code, which will probably just be 0 in all cases.
if ([ -h /etc/init.d/${1?} ] && [ $(readlink -f /etc/init.d/${1?}) = "/lib/init/upstart-job" ]) || [ -f /etc/init/${1?}.conf ]; then
if (service "${1?}" status | ${PLATFORM_EGREP?} -q "stop/waiting") > /dev/null 2>&1; then
run_suppress_output "service ${1?} start | ${PLATFORM_EGREP?} -q 'start/running'"
else
run_suppress_output "service ${1?} restart | ${PLATFORM_EGREP?} -q 'start/running'"
fi
else
# NONPORTABLE
case "${PLATFORM_NAME?}" in
amazon | centos | rhel | ubuntu | sles | debian | cumulus | eos)
if ! (service "${1?}" status) > /dev/null 2>&1; then
run_suppress_output "service ${1?} start"
else
run_suppress_output "service ${1?} restart"
fi
;;
aix)
if ! (/bin/lssrc -s ${1?} | egrep -q "^.*${1?}.*[[:space:]]+active") > /dev/null 2>&1; then
run_suppress_output "/bin/startsrc -s ${1?}"
else
run_suppress_output "/bin/stopsrc -s ${1?}; /bin/startsrc -s ${1?}"
fi
;;
solaris)
run_suppress_output "/opt/puppet/bin/puppet resource service ${1?} ensure=stopped"
run_suppress_output "/opt/puppet/bin/puppet resource service ${1?} ensure=running"
;;
*)
display_failure "Do not know how to restart service on this platform."
;;
esac
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment