Example Script for Adding a Website

The following script shows how you can use serveradmin to add a website to the server’s Web service configuration. The script uses two files:

addsite The actual script you run. It accepts values for the site’s IP address, port number, server name, and root directory and uses sed to substitute these values in the settings it reads from the second file (addsite.in) feeds to serveradmin.

addsite.in Contains the actual settings (with placeholders for values you provide when you run addsite) used to create the website.

The addsite File

sed -es#_ipaddr#$1#g -es#_port#$2#g -es#_servername#$3#g -es#_docroot#$4#g ./addsite.in /usr/sbin/serveradmin --set -i

The addsite.in File

web:Sites:_array_id:_ipaddr\:_port__servername = create

web:Sites:_array_id:_ipaddr\:_port__servername:Listen:_array_index:0 = "_ipaddr:_port"

web:Sites:_array_id:_ipaddr\:_port__servername:ServerName = _servername

web:Sites:_array_id:_ipaddr\:_port__servername:ServerAdmin = admin@_servername

web:Sites:_array_id:_ipaddr\:_port__servername:DirectoryIndex:_array_index:0 = "index.html"

web:Sites:_array_id:_ipaddr\:_port__servername:DirectoryIndex:_array_index:1 = "index.php"

web:Sites:_array_id:_ipaddr\:_port__servername:WebMail = yes

web:Sites:_array_id:_ipaddr\:_port__servername:CustomLog:_array_index:0: Format = "%{User-agent}i"

web:Sites:_array_id:_ipaddr\:_port__servername:CustomLog:_array_index:0: enabled = yes

web:Sites:_array_id:_ipaddr\:_port__servername:CustomLog:_array_index:0: ArchiveInterval = 0

web:Sites:_array_id:_ipaddr\:_port__servername:CustomLog:_array_index:0: Path = "/private/var/log/httpd/access_log"

web:Sites:_array_id:_ipaddr\:_port__servername:CustomLog:_array_index:0: Archive = yes

web:Sites:_array_id:_ipaddr\:_port__servername:Directory:_array_id: /Library/WebServer/Documents:Options:Indexes = yes

web:Sites:_array_id:_ipaddr\:_port__servername:Directory:_array_id: /Library/WebServer/Documents:Options:ExecCGI = no

web:Sites:_array_id:_ipaddr\:_port__servername:Directory:_array_id: /Library/WebServer/Documents:AuthName = "Test Site"

web:Sites:_array_id:_ipaddr\:_port__servername:ErrorLog:ArchiveInterval = 0

web:Sites:_array_id:_ipaddr\:_port__servername:ErrorLog:Path = "/private/var/log/httpd/error_log"

web:Sites:_array_id:_ipaddr\:_port__servername:ErrorLog:Archive = no

web:Sites:_array_id:_ipaddr\:_port__servername:Include:_array_index:0 = "/etc/httpd/httpd_squirrelmail.conf"

web:Sites:_array_id:_ipaddr\:_port__servername:enabled = yes

Chapter 12 Working With Web Technologies

127

Page 127
Image 127
Apple oxs manual Example Script for Adding a Website, Addsite File, Addsite.in File