Last active
April 16, 2016 09:46
-
-
Save znz/434293 to your computer and use it in GitHub Desktop.
/srv/www の雛形作成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -ex | |
SERVER_NAME=$1 | |
SRV_DIR="/srv/www/${SERVER_NAME}" | |
APACHE2_SITE="/srv/www/${SERVER_NAME}/${SERVER_NAME}.conf" | |
AWSTATS_CONF="${SRV_DIR}/awstats.${SERVER_NAME}.conf" | |
AWSTATS_DATA="${SRV_DIR}/awstats" | |
MAIL_DOMAIN=$(hostname -d) | |
mkdir -v "$SRV_DIR" | |
cat >"$APACHE2_SITE" <<EOF | |
# vim: set filetype=apache: | |
<VirtualHost *:80> | |
ServerAdmin webmaster@${MAIL_DOMAIN} | |
ServerName ${SERVER_NAME} | |
RedirectMatch permanent (.*) http://www.${MAIL_DOMAIN}/ | |
ErrorLog /var/log/apache2/${SERVER_NAME}_error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/${SERVER_NAME}_access.log combined | |
ServerSignature Off | |
<IfModule mod_userdir.c> | |
UserDir disabled | |
</IfModule> | |
<IfModule mod_dir.c> | |
DirectoryIndex index.html | |
</IfModule> | |
</VirtualHost> | |
EOF | |
ln -sv "${APACHE2_SITE}" "/etc/apache2/sites-available/${SERVER_NAME}.conf" | |
cat >"${AWSTATS_CONF}" <<EOF | |
Include "/etc/awstats/awstats.conf.common" | |
LogFile="/bin/cat /var/log/apache2/${SERVER_NAME}_access.log.1 /var/log/apache2/${SERVER_NAME}_access.log |" | |
SiteDomain="${SERVER_NAME}" | |
DirData="${AWSTATS_DATA}" | |
EOF | |
mkdir -v "${AWSTATS_DATA}" | |
chown www-data:www-data "${AWSTATS_DATA}" | |
touch "/var/log/apache2/${SERVER_NAME}_access.log.1" | |
cat >"${SRV_DIR}/.gitignore" <<EOF | |
awstats | |
EOF | |
cd "${SRV_DIR}" | |
git init | |
git add . | |
git commit -m "Initial commit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
usage () { | |
exec 1>&2 | |
echo "usage: $0 [OPTION]... SERVER_NAME" | |
echo " -h show this help" | |
echo " -b /srv/www create under" | |
echo " -m DOMAIN mail domain" | |
echo " -s /path/to/ssl-cert.conf use SSL" | |
exit 1 | |
} | |
MAIL_DOMAIN=$(hostname -d) | |
SRV_BASE=/srv/www | |
SSL_CONF="" | |
while getopts "b:hm:s:R" opt; do | |
case "$opt" in | |
b) | |
SRV_BASE=${OPTARG} | |
;; | |
m) | |
MAIL_DOMAIN=${OPTARG} | |
;; | |
s) | |
SSL_CONF=${OPTARG} | |
;; | |
[h?]) | |
usage | |
;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
SERVER_NAME=$1 | |
SRV_DIR="${SRV_BASE}/${SERVER_NAME}" | |
APACHE2_SITE="${SRV_BASE}/${SERVER_NAME}/${SERVER_NAME}.conf" | |
DOCROOT="${SRV_DIR}/htdocs" | |
AWSTATS_CONF="${SRV_DIR}/awstats.${SERVER_NAME}.conf" | |
AWSTATS_DATA="${SRV_DIR}/awstats" | |
if [ -z "$SERVER_NAME" ]; then | |
usage | |
fi | |
if [ -d "$SRV_DIR" ]; then | |
echo "already exists: $SRV_DIR" 1>&2 | |
exit 2 | |
fi | |
set -x | |
mkdir -v "$SRV_DIR" | |
if [ -f "$SSL_CONF" ]; then | |
cat >"$APACHE2_SITE" <<EOF | |
# vim: set filetype=apache: | |
<VirtualHost *:80> | |
ServerAdmin webmaster@${MAIL_DOMAIN} | |
ServerName ${SERVER_NAME} | |
RedirectPermanent / https://${SERVER_NAME}/ | |
ErrorLog /var/log/apache2/${SERVER_NAME}_error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/${SERVER_NAME}_access.log combined | |
ServerSignature Off | |
</VirtualHost> | |
<IfModule mod_ssl.c> | |
<VirtualHost *:443> | |
ServerAdmin webmaster@${MAIL_DOMAIN} | |
ServerName ${SERVER_NAME} | |
Include ${SSL_CONF} | |
DocumentRoot ${DOCROOT} | |
<Directory ${DOCROOT}> | |
Options FollowSymLinks | |
AllowOverride None | |
Require all granted | |
#AddHandler cgi-script .cgi | |
</Directory> | |
#RackBaseURI / | |
ErrorLog /var/log/apache2/${SERVER_NAME}_error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/${SERVER_NAME}_access.log combined | |
ServerSignature Off | |
<IfModule mod_userdir.c> | |
UserDir disabled | |
</IfModule> | |
<IfModule mod_dir.c> | |
DirectoryIndex index.html | |
</IfModule> | |
</VirtualHost> | |
EOF | |
else | |
cat >"$APACHE2_SITE" <<EOF | |
# vim: set filetype=apache: | |
<VirtualHost *:80> | |
ServerAdmin webmaster@${MAIL_DOMAIN} | |
ServerName ${SERVER_NAME} | |
DocumentRoot ${DOCROOT} | |
<Directory ${DOCROOT}> | |
Options FollowSymLinks | |
AllowOverride None | |
Require all granted | |
#AddHandler cgi-script .cgi | |
</Directory> | |
#RackBaseURI / | |
ErrorLog /var/log/apache2/${SERVER_NAME}_error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/${SERVER_NAME}_access.log combined | |
ServerSignature Off | |
<IfModule mod_userdir.c> | |
UserDir disabled | |
</IfModule> | |
<IfModule mod_dir.c> | |
DirectoryIndex index.html | |
</IfModule> | |
</VirtualHost> | |
EOF | |
fi | |
#ln -sv "${APACHE2_SITE}" "/etc/apache2/sites-available/${SERVER_NAME}" | |
cat >"${AWSTATS_CONF}" <<EOF | |
Include "/etc/awstats/awstats.conf.common" | |
LogFile="/bin/cat /var/log/apache2/${SERVER_NAME}_access.log.1 /var/log/apache2/${SERVER_NAME}_access.log |" | |
SiteDomain="${SERVER_NAME}" | |
DirData="${AWSTATS_DATA}" | |
EOF | |
mkdir -v "${AWSTATS_DATA}" | |
#chown www-data:www-data "${AWSTATS_DATA}" | |
#touch "/var/log/apache2/${SERVER_NAME}_access.log.1" | |
cat >"${SRV_DIR}/.gitignore" <<EOF | |
awstats | |
EOF | |
mkdir -v "${DOCROOT}" | |
touch "${DOCROOT}/favicon.ico" | |
echo "${SERVER_NAME}" >"${DOCROOT}/index.html" | |
cat >"${DOCROOT}/robots.txt" <<EOF | |
User-agent: * | |
Crawl-delay: 240 | |
EOF | |
cat >"${SRV_DIR}/acl.sh" <<'EOF' | |
#!/bin/sh | |
set -e | |
FILE_OWNER=root | |
FILE_GROUP=adm | |
AWSTATS_USER=www-data | |
AWSTATS_GROUP=adm | |
cd "$(dirname $0)" | |
SERVER_NAME=$(basename $(pwd)) | |
chown "${FILE_OWNER}:${FILE_GROUP}" . | |
chmod 2755 . | |
chown -R "${FILE_OWNER}:${FILE_GROUP}" .git | |
chmod 2750 .git | |
chown "${FILE_OWNER}:${FILE_GROUP}" .gitignore | |
chown -R "${AWSTATS_USER}:${AWSTATS_GROUP}" awstats || : | |
chmod 2750 awstats | |
chown "${FILE_OWNER}:${FILE_GROUP}" "awstats.${SERVER_NAME}.conf" | |
chmod 644 "awstats.${SERVER_NAME}.conf" | |
chown "${FILE_OWNER}:${FILE_GROUP}" *.sh | |
chmod 755 *.sh | |
chown -R "${FILE_OWNER}:${FILE_GROUP}" htdocs | |
chown "${FILE_OWNER}:${FILE_GROUP}" "${SERVER_NAME}.conf" | |
chmod 644 "${SERVER_NAME}.conf" | |
EOF | |
cd "${SRV_DIR}" | |
git init | |
sh ./acl.sh | |
git add . | |
git commit -m "Initial commit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
SERVER_NAME=$1 | |
if [ -z "$1" ]; then | |
echo "usage: $0 server-name" 1>&2 | |
exit 1 | |
fi | |
a2dissite "${SERVER_NAME}.conf" | |
if [ -h "/etc/apache2/sites-available/${SERVER_NAME}.conf" ]; then | |
rm -fv "/etc/apache2/sites-available/${SERVER_NAME}.conf" | |
fi | |
if [ -h "/etc/awstats/awstats.$SERVER_NAME.conf" ]; then | |
rm -fv "/etc/awstats/awstats.$SERVER_NAME.conf" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
SERVER_NAME=$1 | |
SRV_DIR="/srv/www/${SERVER_NAME}" | |
APACHE2_SITE="/srv/www/${SERVER_NAME}/${SERVER_NAME}.conf" | |
AWSTATS_CONF="${SRV_DIR}/awstats.${SERVER_NAME}.conf" | |
if [ -z "$1" ]; then | |
echo "usage: $0 server-name" 1>&2 | |
exit 1 | |
fi | |
if [ ! -d "$SRV_DIR" ]; then | |
echo "not found: $SRV_DIR" 1>&2 | |
exit 2 | |
fi | |
if [ -x "$SRV_DIR/dep.sh" ]; then | |
"$SRV_DIR/dep.sh" | |
fi | |
if [ ! -e "/etc/awstats/awstats.${SERVER_NAME}.conf" ]; then | |
ln -svnf "${AWSTATS_CONF}" "/etc/awstats/awstats.${SERVER_NAME}.conf" | |
fi | |
if [ ! -e "/etc/apache2/sites-available/${SERVER_NAME}.conf" ]; then | |
ln -svnf "${APACHE2_SITE}" "/etc/apache2/sites-available/${SERVER_NAME}.conf" | |
fi | |
a2ensite "${SERVER_NAME}.conf" | |
LOG_FILE="/var/log/apache2/${SERVER_NAME}_access.log.1" | |
if [ ! -f "${LOG_FILE}" ]; then | |
touch "${LOG_FILE}" | |
fi | |
LOG_FILE="/var/log/apache2/${SERVER_NAME}_access.log" | |
if [ ! -f "${LOG_FILE}" ]; then | |
touch "${LOG_FILE}" | |
chown root:adm "${LOG_FILE}" | |
chmod 640 "${LOG_FILE}" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -ex | |
if [ ! -f /etc/awstats/awstats.conf ]; then | |
echo "exec 'sudo apt-get install awstats', and run this script again." 1>&2 | |
exit 1 | |
fi | |
if id -nG www-data | grep -qw adm; then | |
: | |
else | |
gpasswd -a www-data adm | |
fi | |
if [ -f /usr/share/awstats/tools/update.sh ]; then | |
echo "updated by Debian specific script /usr/share/awstats/tools/update.sh" | |
elif [ ! -f /etc/cron.d/awstats-vhosts ]; then | |
cat >/etc/cron.d/awstats-vhosts <<EOF | |
49 * * * * www-data /etc/awstats/run-awstats.sh >/dev/null | |
EOF | |
fi | |
if [ ! -f /etc/awstats/awstats.conf.common ]; then | |
sed -e 's/^LogFormat=4/LogFormat=1/' -e 's/^Include /#&/' /etc/awstats/awstats.conf >/etc/awstats/awstats.conf.common | |
fi | |
if ! grep -q $(hostname) /etc/awstats/awstats.conf.local; then | |
cat >>/etc/awstats/awstats.conf.local <<EOF | |
LogFormat=1 | |
SiteDomain="$(hostname -f)" | |
HostAliases="$(hostname -s) $(hostname -i) localhost 127.0.0.1" | |
LogFile="/bin/cat /var/log/apache2/access.log.1 /var/log/apache2/access.log |" | |
EOF | |
fi | |
if [ -f /usr/share/awstats/tools/update.sh ]; then | |
echo "updated by Debian specific script /usr/share/awstats/tools/update.sh" | |
elif [ ! -f /etc/awstats/run-awstats.sh ]; then | |
cat >>/etc/awstats/run-awstats.sh <<'EOF' | |
#!/bin/sh | |
if [ `id -u www-data` != `id -u` ]; then | |
echo $0: must run as www-data 1>&2 | |
exit 1 | |
fi | |
if [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf.common ]; then | |
: | |
else | |
echo awstats error 1>&2 | |
exit 2 | |
fi | |
cd /srv/www | |
for VHOSTNAME in *; do | |
if [ -f "/etc/awstats/awstats.${VHOSTNAME}.conf" -a -r "/var/log/apache2/${VHOSTNAME}_access.log" ]; then | |
/usr/lib/cgi-bin/awstats.pl -config=$VHOSTNAME -update | |
fi | |
done | |
EOF | |
chmod +x /etc/awstats/run-awstats.sh | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment