Last active
January 2, 2016 13:49
-
-
Save d5/8313139 to your computer and use it in GitHub Desktop.
op: install, start, stop, restart, status example: curl "https://gist.sh/8313139?op=stop,install,start" | sudo sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
info() { echo "INFO: $1"; } | |
die() { echo "ERROR: $1. Aborting!"; exit 1; } | |
{% for o in split(op, ",") %} | |
{% if o.value == "install" %} | |
if type yum > /dev/null 2>&1; then | |
yum install -y nginx | |
{% else %} | |
service nginx {{ o.value }} | |
{% endif %} | |
else if type zypper > /dev/null 2>&1; then | |
{% if o.value == "install" %} | |
zypper --non-interactive in nginx | |
{% else %} | |
{% endif %} | |
else if type apt-get > /dev/null 2>&1; then | |
apt-get install -y nginx | |
else | |
fi | |
{% endfor %} | |
{% if op == "install" %} | |
info "install Nginx" | |
{% elif op == "start" %} | |
info "start Nginx" | |
if type service > /dev/null 2>&1; then | |
service nginx start | |
fi | |
if type nginx > /dev/null 2>&1; then | |
nginx | |
fi | |
{% elif op == "stop" %} | |
info "stop Nginx" | |
if type service > /dev/null 2>&1; then | |
service nginx stop | |
fi | |
if type nginx > /dev/null 2>&1; then | |
nginx -s quit | |
fi | |
{% else %} | |
die "Incorrect operation: {{ op }}" | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment