3 # creates a new apache website for a specified domain.
5 # some convenient defaults for our current usage.
8 SHADOWPATH="/srv/users/serverpilot/apps"
9 STORAGESUFFIX="/public"
11 # this function writes out the new configuration file for the site.
12 function write_apache_config()
14 local appname="$1"; shift
15 local sitename="$1"; shift
16 local site_config="/etc/apache2/sites-available/${sitename}.conf"
18 # check if config file already exists and bail if so.
19 if [ -f "$site_config" ]; then
20 echo "The apache configuration file already exists at:"
22 echo "Please remove this file before proceeding, if it is junk. For example:"
23 echo " sudo rm $site_config"
27 echo "Creating a new apache2 site for $sitename with config file:"
30 local fullpath="${BASEPATH}/${appname}${STORAGESUFFIX}"
32 # make the storage directory if it's not already present.
33 if [ ! -d "$fullpath" ]; then
36 echo "Failed to create the storage directory for $appname in"
37 echo "the folder: $fullpath"
44 ServerName ${sitename}
45 # ServerAlias ${sitename} *.${sitename}
46 DocumentRoot ${fullpath}
47 ErrorLog ${APACHE_LOG_DIR}/${sitename}-error.log
48 CustomLog ${APACHE_LOG_DIR}/${sitename}-access.log combined
49 Include /etc/apache2/conf-library/basic-options.conf
50 Include /etc/apache2/conf-library/rewrite-enabling.conf
58 function enable_site()
60 local sitename="$1"; shift
61 local site_config="/etc/apache2/sites-available/${sitename}.conf"
63 a2ensite "$(basename $site_config)"
65 echo "There was a problem enabling the apache config file in:"
67 echo "Please consult the apache error logs for more details."
72 function restart_apache()
74 service apache2 restart
76 echo "There was a problem restarting the apache2 service."
77 echo "Please consult the apache error logs for more details."
82 # main body of script.
84 if (( $EUID != 0 )); then
85 echo "This script must be run as root or sudo."
92 if [ -z "$appname" -o -z "$site" ]; then
93 echo "This script needs to know (1) the appname (application name) for the new"
94 echo "site and (2) the DNS name for the apache virtual host."
95 echo "The appname should work as a file-system compatible folder name."
99 # make sure there is a symbolic link from the shadow path (that mimics the serverpilot
100 # storage set up) to the real storage directory.
101 if [ ! -l "$SHADOWPATH" ]; then
102 ln -s "$BASEPATH" "$SHADOWPATH"
103 #hmmm: should we be okay with it if it's a real dir, and assume people are happy?
104 # this wouldn't work too well if we go plunk down the new thing in /var/www,
105 # if they are expecting this tool to totally meld with serverpilot.
106 if [ $? -ne 0 ]; then
107 echo "The shadow path for mimicking serverpilot could not be created."
108 echo "Is there a real directory present for this already?"
109 echo "Path in question is: $SHADOWPATH"
114 write_apache_config "$appname" "$site"