lamps/init

71 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

2016-08-11 01:22:20 +00:00
#!/bin/bash
set -e
NO_DB=${NO_DB:-FALSE}
NO_SSH=${NO_SSH:-TRUE}
NO_MAIL=${NO_MAIL:-FALSE}
NO_HTTP=${NO_HTTP:-FALSE}
NAME="LAMPS"
function stop {
echo "Stopping ${NAME}"
[ "$NO_MAIL" != "TRUE" ] && kill $(cat /var/run/opendkim.pid) && kill $(cat /var/run/sendmail.pid|head -1)
[ "$NO_SSH" != "TRUE" ] && kill $(cat /var/run/sshd.pid)
[ "$NO_DB" != "TRUE" ] && kill $(cat /var/run/mariadb/mariadb.pid)
[ "$NO_HTTP" != "TRUE" ] && rm -f /var/run/httpd/authdigest_shm.$(cat /var/run/httpd/httpd.pid) && kill $(cat /var/run/httpd/httpd.pid)
}
trap 'stop' SIGTERM
if [ "$1" == "start" ]; then
if [ "$NO_MAIL" != "TRUE" ]; then
if [ -z `hostname --domain` ]; then
echo "You must start this container with --hostname= specifying a domain name"
exit 1
fi
echo "Starting OpenDKIM..."
[ ! -f /etc/opendkim/keys/default.private ] && /usr/sbin/opendkim-default-keygen
[ -x /usr/sbin/opendkim ] && /usr/sbin/opendkim -x /etc/opendkim.conf -P /var/run/opendkim.pid -f &
echo "Starting Sendmail..."
cd /etc/mail && make && m4 sendmail.mc > sendmail.cf && /usr/sbin/sendmail -q1h -bD &
else
echo "! NOT starting MAIL"
fi
if [ "$NO_SSH" != "TRUE" ]; then
echo "Starting SSHD..."
getent passwd lamp || useradd -c "Hosting Admin User" -m lamp
[ -x /usr/sbin/sshd-keygen ] && /usr/sbin/sshd-keygen
[ -x /usr/sbin/sshd ] && /usr/sbin/sshd
else
echo "! NOT starting SSH"
fi
if [ "$NO_DB" != "TRUE" ]; then
echo "Starting Maria DB..."
[ -x /usr/libexec/mariadb-prepare-db-dir ] && /usr/libexec/mariadb-prepare-db-dir
[ -x /usr/bin/mysqld_safe ] && /usr/bin/mysqld_safe --basedir=/usr &
else
echo "! NOT starting DB"
fi
if [ "$NO_HTTP" != "TRUE" ]; then
if [ -d /etc/awstats ]; then
find /etc/awstats/ -type l | xargs -n 5 rm -f
[ -e /var/www/sites/*/awstats/awstats*conf ] && find /var/www/sites/*/awstats/awstats*conf -type f -exec ln -sf {} /etc/awstats/ \;
fi
echo "Starting HTTP..."
find /etc/httpd/conf.d/ -type l | xargs -n 5 rm -f
find /etc/httpd/sites.d -type f -exec ln -sf {} /etc/httpd/conf.d/ \;
[ -x /usr/sbin/httpd ] && /usr/sbin/httpd -DFOREGROUND &
else
echo "! NOT starting HTTP"
fi
wait
else
exec $@
fi