Skip to content

Instantly share code, notes, and snippets.

@d5
Last active January 2, 2016 13:49
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 d5/8313139 to your computer and use it in GitHub Desktop.
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
#!/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