Skip to content

Instantly share code, notes, and snippets.

@jhubert
Created July 9, 2009 22:26
Show Gist options
  • Save jhubert/144050 to your computer and use it in GitHub Desktop.
Save jhubert/144050 to your computer and use it in GitHub Desktop.
#!/bin/sh
echo 'This script adds a slave to bind9'
echo ''
echo -n 'What is the TLD?: '
read tld
echo -n 'What is the IP of the master server?: '
read masterip
echo "zone \"$tld\" {
type slave;
file \"zones/slave/slave.$tld\";
masters { $masterip; };
allow-notify { $masterip; };
};
" >> /etc/bind/named.conf
#!/bin/sh
echo "This script creates a new virtual host for lighttpd."
echo ""
echo -n "What is the vhost pattern to match?"
read pattern
echo -n "What is the username?"
read username
echo -n "What is the folder/domain name?"
read domain
echo -n "What is the project shortname?"
read shortname
echo "\$HTTP[\"host\"] =~ \"$pattern\" {
accesslog.filename = \"/var/www/$username/$domain/log/access_log\"
url.rewrite = ( \"^/$\" => \"index.html\", \"^([^.]+)$\" => \"$1.html\" )
server.indexfiles = (\"dispatch.fcgi\")
server.document-root = \"/var/www/$username/$domain/public/\"
server.error-handler-404 = \"/dispatch.fcgi\"
server.errorlog = \"/var/www/$username/$domain/log/error_log\"
fastcgi.server = ( \".fcgi\" =>
( \"fcgi\" =>
(
\"socket\" => \"/tmp/$shortname-$username-fcgi.socket\",
\"bin-path\" => \"/var/www/$username/$domain/public/dispatch.fcgi\",
\"bin-environment\" => ( \"RAILS_ENV\" => \"production\" ),
\"min-procs\" => 1,
\"max-procs\" => 2, \"idle-timeout\" => 120
)
)
)
}" >> /etc/lighttpd.conf
#!/usr/bin/env ruby
require 'timeout'
require 'net/smtp'
require 'optparse'
require 'yaml'
ARGV.options do |opts|
opts.on("-c", "--config=FILE", String) {|val| @userfile = val }
opts.parse!
end
CONFIG_LOC = @userfile ? @userfile : ENV['HOME'] + "/.uptime_config.yml"
CONFIG = YAML::load(File::read(CONFIG_LOC))
failures = []
def email(message)
puts "sending email..."
msg = "Error Scanning Sites\n\n"
msg += message
Net::SMTP.start( CONFIG['smtp']['server'],
CONFIG['smtp']['port'],
'localhost.localdomain',
CONFIG['smtp']['user'],
CONFIG['smtp']['pass'], :login) do |smtp|
smtp.send_message(msg, CONFIG['smtp']['from'], CONFIG['notify'])
end
puts "sent!"
end
begin
Timeout.timeout(CONFIG['wait']) do
CONFIG['heads'].each do |uri|
print "requesting HEAD for #{uri} ..."
result = `curl #{CONFIG['curl'].join(' ')} -I #{uri}`
if result.match(/^HTTP\/1\.\d+ 2\d{2}/)
puts "success!"
else
response = result.split("\r\n").first
failures << "*** #{uri} returned response #{response} (2xx expected)"
puts "failure! (#{response} -- 2xx expected)"
end
end
true
end
rescue Timeout::Error
failures << "*** Failed to retrieve all pages in #{CONFIG['wait']} seconds."
end
email(failures.join("\n")) unless failures.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment