Skip to content

Instantly share code, notes, and snippets.

@bdtomlin
Created July 5, 2010 18:33
Show Gist options
  • Save bdtomlin/464577 to your computer and use it in GitHub Desktop.
Save bdtomlin/464577 to your computer and use it in GitHub Desktop.
nginx ruby script
#!/usr/bin/env ruby
USAGE = %{
Usage:
Put this script somewhere in your path, I use ~/bin
chmod +x to make it executable.
nginx start (starts nginx)
nginx stop (stops nginx)
nginx restart (calls stop and then start)
nginx conf (opens nginx.conf in macvim, or regular vim if macvim doesn't exist)
}
def start
`sudo /opt/nginx/sbin/nginx &`
end
def stop
pid = File.read('/opt/nginx/logs/nginx.pid')
# use back-tic not exec so these can be chained
`sudo kill #{pid}`
end
def conf
begin
exec "sudo mvim /opt/nginx/conf/nginx.conf"
rescue Errno::ENOENT # use vim because mvim doesn't exist
exec 'sudo vim /opt/nginx/conf/nginx.conf'
end
end
def restart
stop
start
end
def stat
exec "ps aux| grep nginx| grep -v grep"
end
if %w{start stop conf restart stat}.include?(ARGV.first)
send ARGV.first
else
puts USAGE
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment