DigiMoon 맘대로 닦고 조이고 기름치는 재미가 있는 DigiMoon만의 기억 저장소

Posted
Filed under 컴퓨터 탐구/리눅스
작성자: 주인장 디지문
(http://www.digimoon.net/)


 개인적으로 작년에 제작하여 조금씩 업데이트를 거듭하며 실무에서도 사용하였던 Qmail + Vpopmail 연동 설치 스크립트를 공개합니다.




#!/bin/bash
#####################################################################################
#                                                                                   #
#  본 스크립트는 Fedora, CentOS, Ubuntu를 기준으로 작성되었습니다.                  #
#                                                                                   #
#####################################################################################

# 설치 권한(root) 체크
if [ "$(whoami)" != "root" ] ; then
  echo "Error: 본 스크립트는 root 권한의 쉘에서만 실행 가능합니다." >&2
  exit 1
fi

TODAY=`date +%y-%m-%d`

#UCSPI_TCP_SOURCE="http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz"
#DAEMONTOOLS_SOURCE="http://cr.yp.to/daemontools/daemontools-0.76.tar.gz"
#QMAIL_SOURCE="ftp://ftp.eu.uu.net/pub/unix/mail/qmail/qmail-1.03.tar.gz"
#VPOPMAIL_SOURCE="http://nchc.dl.sourceforge.net/sourceforge/vpopmail/vpopmail-5.4.25.tar.gz"
#libdomainkeys_SOURCE="http://shupp.org/software/libdomainkeys-0.68.tar.gz"
#libdomainkeys_diff_SOURCE="http://shupp.org/patches/libdomainkeys.diff"
#KNETQMAIL_SOURCE="http://mail.linuxstudy.pe.kr/download/knetqmail-1.06-20090303.tar.bz2"

UCSPI_TCP_SOURCE="http://source.digimoon.net/Mail/qmail/ucspi-tcp-0.88.tar.gz"
DAEMONTOOLS_SOURCE="http://source.digimoon.net/Mail/qmail/daemontools-0.76.tar.gz"
QMAIL_SOURCE="http://source.digimoon.net/Mail/qmail/qmail-1.03/qmail-1.03.tar.gz"
VPOPMAIL_SOURCE="http://source.digimoon.net/Mail/vpopmail/vpopmail-5.4.25.tar.gz"
libdomainkeys_SOURCE="http://source.digimoon.net/Mail/knetqmail-1.06/libdomainkeys-0.68.tar.gz"
libdomainkeys_diff_SOURCE="http://source.digimoon.net/Mail/knetqmail-1.06/libdomainkeys.diff"
KNETQMAIL_SOURCE="http://source.digimoon.net/Mail/knetqmail-1.06/knetqmail-1.06-20090303.tar.bz2"

PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/local/mysql/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

## 로고 및 스크립트 정보 출력
echo ""
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃                                                                    ┃"
echo "┃  Qmail + Vpopmail install Script                                   ┃"
echo "┃                                                                    ┃"
echo "┃  Last Upated 2011.04.04                                            ┃"
echo "┃                                                                    ┃"
echo "┃  제  작  자   : 문경윤(디지문) : admin@digimoon.net                ┃"
echo "┃  메인사이트   : www.digimoon.net                                   ┃"
echo "┃  주배포사이트 : www.digimoon.net                                   ┃"
echo "┃                                                                    ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
echo ""
echo ""
echo ""
echo ""
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃  Default Packages Version                                          ┃"
echo "┃--------------------------------------------------------------------┃"
echo "┃  ucspi-tcp 0.88                                                    ┃"
echo "┃  daemontools 0.76                                                  ┃"
echo "┃  qmail 1.03                                                        ┃"
echo "┃  vpopmail 5.4.25                                                   ┃"
echo "┃  knetqmail 1.06                                                    ┃"
echo "┃  ※ tcp 587 포트를 이용한 mail submission 지원                     ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
echo ""
echo ""
echo ""
echo -n "▶▶▶!!주의!!◀◀◀

TCP 25 포트를 쓰는 SMTP(sendmail, postfix 등) 데몬과
TCP 110 포트를 쓰는 POP3(dovecot, courier imap 등) 데몬이 이미 있다면
Ctrl + c 입력하여 본 스크립트 실행을 취소하고
기존 메일자료를 필히 백업하고 먼저 삭제, 데몬을 종료한 뒤 본 스크립트를 다시 구동하기 바랍니다.
sendmail, postfix, dovecot의 경우 기존 설치된 것이 있다면 자동 삭제됩니다.
"
echo ""
echo ""
echo ""

## Vpopmail에 MySQL 연동할 지 여부 질문
echo "Vpopmail 설치 타입을 선택하세요."
echo "======================================================================"
echo "1) with MySQL"
echo "2) cdb (without MySQL)"
stty -echo
read VPOPMAIL_TYPE
stty echo
if [ "$VPOPMAIL_TYPE" = "1" ] || [ "$VPOPMAIL_TYPE" = "2" ] ; then
  echo
else
  echo "입력이 잘못되었습니다."
  exit 1
fi

if [ "$VPOPMAIL_TYPE" = "1" ] ; then

## MySQL 관리자(root) 패스워드입력
echo ""
echo ""
stty -echo
echo "MySQL 관리자(root) 패스워드를 확인합니다."
echo "======================================================================"
echo "MySQL 관리자(root) 패스워드 입력 :"
read MYSQL_ROOT_PASSWD
stty echo

stty -echo
echo "한 번 더 입력 :"
read MYSQL_ROOT_PASSWD_CONFIRM
stty echo

if [ "$MYSQL_ROOT_PASSWD" != "$MYSQL_ROOT_PASSWD_CONFIRM" ] ; then
  echo "입력이 잘못되었습니다. "
  exit 1
else
 mysqladmin -u root -p$MYSQL_ROOT_PASSWD reload >& /dev/null
 if [ "$?" == "1" ] ; then
   echo "MySQL 관리자(root) 패스워드가 맞지 않거나 MySQL이 설치되어 있지 않습니다!! "
   exit 1
 fi
fi

# vpopamil 디비/유저가 이미 생성되어 있는지 검사
echo "select * from db" > /tmp/mysql_db_temp
echo "select * from user" > /tmp/mysql_user_temp
if [ \( -n "`mysql -uroot -p$MYSQL_ROOT_PASSWD mysql < /tmp/mysql_db_temp | awk '{print $2}' | grep vpopmail`" \) -o \( -n "`mysql -uroot -p$MYSQL_ROOT_PASSWD mysql < /tmp/mysql_user_temp | awk '{print $2}' | grep vpopmail`" \) ] ; then
echo -n "
vpopmail DB가 이미 존재합니다.
qmail이나 vpopmail이 이미 설치되어 있다면 백업 후 삭제하고 본 스크립트를 다시 구동하기 바랍니다
스크립트 실행을 종료합니다...
"
rm -f /tmp/mysql_db_temp /tmp/mysql_user_temp >& /dev/null
  exit 1
else
rm -f /tmp/mysql_db_temp /tmp/mysql_user_temp >& /dev/null
fi

# vpopmail db 패스워드 설정
echo ""
echo ""
echo "vpopmail db 패스워드를 설정합니다."
echo "======================================================================"
stty -echo
echo "vpopmail db 패스워드 입력 :"
read VPOPMAIL_DB_PASSWD
stty echo

stty -echo
echo "한 번 더 입력 :"
read VPOPMAIL_DB_PASSWD_CONFIRM
stty echo

if [ "$VPOPMAIL_DB_PASSWD" != "$VPOPMAIL_DB_PASSWD_CONFIRM" ] ; then
   echo -n "입력이 잘못되었습니다."     
   exit 1     
fi

else
echo
fi

# 도메인 설정
echo ""
echo ""
echo "사용하고자 하는 defaultdomain을 입력하세요."
echo "(호스트네임을 제외한 도메인네임만 입력)"
echo "======================================================================"
read DOMAIN

# postmaster 계정 패스워드 설정
echo ""
echo ""
echo "postmaster@${DOMAIN} 패스워드를 설정합니다."
echo "======================================================================"
stty -echo
echo "postmaster@${DOMAIN} 패스워드 입력 :"
read POSTMASTER_PASSWD
stty echo

stty -echo
echo "한 번 더 입력 :"
read POSTMASTER_PASSWD_CONFIRM
stty echo

if [ "$POSTMASTER_PASSWD" != "$POSTMASTER_PASSWD_CONFIRM" ] ; then
   echo -n "입력이 잘못되었습니다."
   exit 1     
fi

echo ""
echo ""
# 타임서버 동기화
rdate -s time.bora.net && date && clock -r && clock -w > /dev/null 2>&1

# 기존 sendmail, postfix 패키지 삭제
if [ -f /etc/redhat-release ] ; then
 rpm -qa | grep sendmail* >& /tmp/rpm_tmp
  if [ -n "`cat /tmp/rpm_tmp | grep 'sendmail'`" ] ; then      
   echo -n "기존 설치되어 있는 sendmail 관련 패키지를 삭제하고
   /etc/mail 디렉토리를 /etc/mail_${TODAY} 로 백업합니다.
   "
   cp -arp /etc/mail /etc/mail_${TODAY}.bak
    if [ -n "`netstat -ntlp | grep sendmail`" ] ; then
     /etc/rc.d/init.d/sendmail stop
    fi
   for i in `cat /tmp/rpm_tmp` ; do
    rpm -e --nodeps $i
    echo "$i 패키지를 삭제하였습니다."
   done
  fi 
 rm -f /tmp/rpm_tmp
 yum -y install openssl
 yum -y install openssl-devel
 yum -y install groff
else
 if [ -f /etc/lsb-release ] ; then
  if [ d /etc/mail ] ; then
    echo -n "기존 설치되어 있는 sendmail 관련 패키지를 삭제하고
/etc/mail 디렉토리를 /etc/mail_${TODAY} 로 백업합니다."
    cp -arp /etc/mail /etc/mail_${TODAY}.bak
  fi        
  apt-get -y purge m4 make sendmail sendmail-base sendmail-bin sendmail-cf sensible-mda
  apt-get -y purge postfix
  apt-get -y purge dovecot-common
  apt-get -y install openssl*
  apt-get -y install groff
  apt-get -y install gcc build-essential make automake
 fi        
fi

# 설치 시작
mkdir -p /usr/local/src/qmail

# ucspi-tcp setup
cd /usr/local/src/qmail
wget $UCSPI_TCP_SOURCE
tar xvfz ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
sed -i "1i #include <errno.h>" error.h
make
make setup check

# daemontools setup
cd /usr/local/src/qmail
wget $DAEMONTOOLS_SOURCE
mkdir /package
tar xvfz daemontools-0.76.tar.gz -C /package
cd /package/admin/daemontools-0.76
sed -i "3i #include <errno.h>" src/error.h
package/install
if [ -s /etc/redhat-release ] ; then
 if [ ! -n "`tail -n 1 /etc/inittab | grep 'SV:123456:respawn:\/command\/svscanboot'`" ] ; then
  echo -n "daemontools 설치 과정에서 문제가 생겼습니다. 설치를 중단합니다.
  /etc/inittab 파일 최하단부에 SV:123456:respawn:/command/svscanboot 행이 추가되어 있지 않은지,
  또는 /command 디렉토리가 생성되어 있지 않은지 확인 바랍니다."
  exit 1
 fi
else
  if [ -f /etc/lsb-release ] ; then
   if [ ! -f /etc/inittab ] ; then
   echo "# svscanboot
#

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5

stop on runlevel 0
stop on runlevel 1
stop on runlevel 6

respawn
exec \/command\/svscanboot" > /etc/event.d/svscanboot
   fi
   /command/svscanboot & > /dev/null
  fi
fi

# qmail setup
cd /usr/local/src/qmail
wget $QMAIL_SOURCE 
tar xvfpz qmail-1.03.tar.gz
cd qmail-1.03
sed -i "1i #include <errno.h>" error.h
groupadd -r nofiles
useradd -r -g nofiles -s /bin/false -d /var/qmail/alias alias
useradd -r -g nofiles -s /bin/false -d /var/qmail qmaild
useradd -r -g nofiles -s /bin/false -d /var/qmail qmaill
useradd -r -g nofiles -s /bin/false -d /var/qmail qmailp
groupadd -r qmail
useradd -r -g qmail -s /bin/false -d /var/qmail qmailq
useradd -r -g qmail -s /bin/false -d /var/qmail qmailr
useradd -r -g qmail -s /bin/false -d /var/qmail qmails
make
make setup check

./config-fast mail.$DOMAIN

echo "$DOMAIN" > /var/qmail/control/defaultdomain
echo "$DOMAIN" > /var/qmail/control/rcpthosts
echo "$DOMAIN" > /var/qmail/control/me
echo "$DOMAIN:$DOMAIN" > /var/qmail/control/virtualdomains
cat /dev/null > /var/qmail/control/locals

echo -n "#!/bin/sh
exec env - PATH=\"/var/qmail/bin:\$PATH\" \\
qmail-start ./Maildir/" > /var/qmail/rc

chmod 755 /var/qmail/rc
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir -p /var/qmail/supervise/qmail-smtpd-sub/log
chmod 1755 /var/qmail/supervise/qmail-send
chmod 1755 /var/qmail/supervise/qmail-smtpd
chmod 1755 /var/qmail/supervise/qmail-smtpd-sub

echo -n "#!/bin/sh
exec /var/qmail/rc" > /var/qmail/supervise/qmail-send/run

echo -n "#!/bin/sh
exec /usr/local/bin/setuidgid qmaill \\
/usr/local/bin/multilog t /var/log/qmail/qmail-send" > /var/qmail/supervise/qmail-send/log/run

echo "#!/bin/sh
Q_UID=\`id -u vpopmail\`
Q_GID=\`id -g vpopmail\`
exec /usr/local/bin/softlimit -m 200000000 \\
/usr/local/bin/tcpserver -vRHl 0 -x /etc/tcp.smtp.cdb \\
-u \$Q_UID -g \$Q_GID 0 25 \\
/var/qmail/bin/qmail-smtpd /home/vpopmail/bin/vchkpw /bin/true 2>&1" > /var/qmail/supervise/qmail-smtpd/run

echo "#!/bin/sh
exec /usr/local/bin/setuidgid qmaill \\
/usr/local/bin/multilog t /var/log/qmail/qmail-smtpd" > /var/qmail/supervise/qmail-smtpd/log/run

echo "#!/bin/sh
Q_UID=\`id -u vpopmail\`
Q_GID=\`id -g vpopmail\`
exec /usr/local/bin/softlimit -m 200000000 \\
/usr/local/bin/tcpserver -vRHl 0 -x /etc/tcp.smtp.cdb \\
-u \$Q_UID -g \$Q_GID 0 587 \\
/var/qmail/bin/qmail-smtpd /home/vpopmail/bin/vchkpw /bin/true 2>&1" > /var/qmail/supervise/qmail-smtpd-sub/run

echo "#!/bin/sh
exec /usr/local/bin/setuidgid qmaill \\
/usr/local/bin/multilog t /var/log/qmail/qmail-smtpd-sub" > /var/qmail/supervise/qmail-smtpd-sub/log/run

chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd-sub/run
chmod 755 /var/qmail/supervise/qmail-smtpd-sub/log/run

mkdir -p /var/log/qmail/qmail-send
mkdir -p /var/log/qmail/qmail-smtpd
mkdir -p /var/log/qmail/qmail-smtpd-sub
chown qmaill /var/log/qmail /var/log/qmail/qmail-send
chown qmaill /var/log/qmail /var/log/qmail/qmail-smtpd
chown qmaill /var/log/qmail /var/log/qmail/qmail-smtpd-sub

echo "127.0.0.1:allow,RELAYCLIENT=\"\"" > /etc/tcp.smtp
/usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp

echo postmaster@$DOMAIN > /var/qmail/alias/.qmail-root
echo postmaster@$DOMAIN > /var/qmail/alias/.qmail-postmaster
echo postmaster@$DOMAIN > /var/qmail/alias/.qmail-mailer-daemon
chmod 644 /var/qmail/alias/.qmail-*

if [ -n "`ls -l /usr/lib | grep sendmail`" ] ; then
unlink /usr/lib/sendmail
fi
ln -sf /var/qmail/bin/sendmail /usr/lib
if [ -n "`ls -l /usr/sbin | grep sendmail`" ] ; then
unlink /usr/sbin/sendmail
fi
ln -sf /var/qmail/bin/sendmail /usr/sbin

# vpopmail setup
groupadd -r vchkpw
useradd -r -g vchkpw -s /bin/false vpopmail
cd /usr/local/src/qmail
wget $VPOPMAIL_SOURCE
tar xvfz vpopmail-5.4.25.tar.gz
cd vpopmail-5.4.25

if [ "$VPOPMAIL_TYPE" = "1"  ] ; then
./configure --enable-tcprules-prog=/usr/local/bin/tcprules --enable-tcpserver-file=/etc/tcp.smtp --enable-auth-module=mysql --enable-logging=y
else
./configure --enable-tcprules-prog=/usr/local/bin/tcprules --enable-tcpserver-file=/etc/tcp.smtp --enable-logging=y
fi
make
make install-strip
chmod 755 /home/vpopmail/etc
chown vpopmail.vchkpw /home/vpopmail/etc
echo "$DOMAIN" > /home/vpopmail/etc/defaultdomain
chown vpopmail.vchkpw /home/vpopmail/etc/defaultdomain
chmod 640 /home/vpopmail/etc/defaultdomain

if [ "$VPOPMAIL_TYPE" = "1"  ] ; then
echo "create database vpopmail;" > /tmp/mysql_dbusersetup_temp
echo "grant all privileges on vpopmail.* to vpopmail@localhost identified by '$VPOPMAIL_DB_PASSWD';" >> /tmp/mysql_dbusersetup_temp
echo "flush privileges;" >> /tmp/mysql_dbusersetup_temp
#$MYSQL_BIN_DIR/mysql -u root -p$MYSQL_ROOT_PASSWD mysql < /tmp/mysql_dbusersetup_temp
mysql -u root -p$MYSQL_ROOT_PASSWD mysql < /tmp/mysql_dbusersetup_temp
rm -f /tmp/mysql_dbusersetup_temp
sed -i s/secret/$VPOPMAIL_DB_PASSWD/g /home/vpopmail/etc/vpopmail.mysql
sed -i s/'0|root'/'0|vpopmail'/g /home/vpopmail/etc/vpopmail.mysql
chmod 640 /home/vpopmail/etc/vpopmail.mysql
else
echo
fi

mkdir /var/qmail/supervise/vpop
chmod 1755 /var/qmail/supervise/vpop
echo -n "#!/bin/sh
VPOP_UID=\`id -u vpopmail\`
VPOP_GID=\`id -g vpopmail\`
exec /usr/local/bin/softlimit -m 20000000 \\
/usr/local/bin/tcpserver -vRHl 0 -u \$VPOP_UID -g \$VPOP_GID 0 110 \\
/var/qmail/bin/qmail-popup $DOMAIN \\
/home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1" > /var/qmail/supervise/vpop/run
chmod 755 /var/qmail/supervise/vpop/run
mkdir /var/qmail/supervise/vpop/log
echo -n "#!/bin/sh
exec /usr/local/bin/setuidgid qmaill \\
/usr/local/bin/multilog t /var/log/qmail/vpop" > /var/qmail/supervise/vpop/log/run
chmod 755 /var/qmail/supervise/vpop/log/run
mkdir /var/log/qmail/vpop
chown qmaill /var/log/qmail/vpop

# knetqmail patch setup
cd /usr/local/src/qmail
wget $libdomainkeys_SOURCE
wget $libdomainkeys_diff_SOURCE
wget $KNETQMAIL_SOURCE
tar xvfz libdomainkeys-0.68.tar.gz 
cd libdomainkeys-0.68 
patch -p0 < ../libdomainkeys.diff
make
cd ..
mkdir tmp
cd tmp
tar xfj ../knetqmail-1.06-20090303.tar.bz2
cd knetqmail-1.06-20090303

# gcc 4.3.2 이상 버전에서 open 함수 에러 문제 수정
gcc -v >& /tmp/gcc_temp
if [ \( 4 -le `cat /tmp/gcc_temp | tail -n 1 | awk '{print $3}' | cut -f1 -d"."` \) -a \( 3 -le `cat /tmp/gcc_temp | tail -n 1 | awk '{print $3}' | cut -f2 -d"."` \) ] ; then
  sed -i s/'O_CREAT'/'O_CREAT,0644'/g open_rw.c
fi
rm -f /tmp/gcc_temp

make
make setup check

# init script setup

# 페도라/CentOS용
if [ -f /etc/redhat-release ] ; then
echo -n "#!/bin/sh

# For Red Hat chkconfig
# chkconfig: - 80 30
# description: the qmail MTA

PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

case \"\$1\" in
  start)
    echo \"Starting qmail\"
  if [ -e /service/qmail-send ] ; then
   if svok /service/qmail-send ; then
   svc -u /service/qmail-send
  else
   echo qmail-send supervise not running
  fi
  else
   ln -s /var/qmail/supervise/qmail-send /service/
  fi

  if [ -e /service/qmail-smtpd ] ; then
   if svok /service/qmail-smtpd ; then
   svc -u /service/qmail-smtpd
  else
   echo qmail-smtpd supervise not running
  fi
  else
   ln -s /var/qmail/supervise/qmail-smtpd /service/
  fi

   if [ -e /service/qmail-smtpd-sub ] ; then
    if svok /service/qmail-smtpd-sub ; then
      svc -u /service/qmail-smtpd-sub
    else
      echo qmail-smtpd-sub supervise not running
    fi
   else
    ln -s /var/qmail/supervise/qmail-smtpd-sub /service/
   fi

    if [ -e /service/vpop ] ; then
     if svok /service/vpop ; then
       svc -u /service/vpop
     else
       echo vpop supervise not running
    fi
   else
       ln -s /var/qmail/supervise/vpop /service/
   fi
  
    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
    ;;
  stop)
    echo \"Stopping qmail...\"
    echo \"  qmail-smtpd\"
    svc -dx /service/qmail-smtpd /service/qmail-smtpd/log
  rm -f /service/qmail-smtpd
    echo \"  qmail-smtpd-sub\"
    svc -dx /service/qmail-smtpd-sub /service/qmail-smtpd-sub/log
  rm -f /service/qmail-smtpd-sub
    echo \"  qmail-send\"
    svc -dx /service/qmail-send /service/qmail-send/log
  rm -f /service/qmail-send
    echo \"  vpop\"
    svc -dx /service/vpop /service/vpop/log
         rm -f /service/vpop
    if [ -f /var/lock/subsys/qmail ]; then
      rm /var/lock/subsys/qmail
    fi
    ;;
  stat)
    svstat /service/qmail-send
    svstat /service/qmail-send/log
    svstat /service/qmail-smtpd
    svstat /service/qmail-smtpd/log
    svstat /service/qmail-smtpd-sub
    svstat /service/qmail-smtpd-sub/log
    svstat /service/vpop
    svstat /service/vpop/log
    qmail-qstat
    ;;
  doqueue|alrm|flush)
    echo \"Flushing timeout table and sending ALRM signal to qmail-send.\"
    /var/qmail/bin/qmail-tcpok
    svc -a /service/qmail-send
    ;;
  queue)
    qmail-qstat
    qmail-qread
    ;;
  reload|hup)
    echo \"Sending HUP signal to qmail-send.\"
    svc -h /service/qmail-send
    ;;
  pause)
    echo \"Pausing qmail-send\"
    svc -p /service/qmail-send
    echo \"Pausing qmail-smtpd\"
    svc -p /service/qmail-smtpd
    echo \"Pausing qmail-smtpd-sub\"
    svc -p /service/qmail-smtpd-sub
    echo \"Pausing vpop\"
    svc -p /service/vpop
    ;;
  cont)
    echo \"Continuing qmail-send\"
    svc -c /service/qmail-send
    echo \"Continuing qmail-smtpd\"
    svc -c /service/qmail-smtpd
    echo \"Continuing qmail-smtpd-sub\"
    svc -c /service/qmail-smtpd-sub
    echo \"Continuing vpop\"
    svc -c /service/vpop
    ;;
  restart)
    echo \"Restarting qmail:\"
    echo \"* Stopping qmail-smtpd.\"
    svc -d /service/qmail-smtpd
    echo \"* Stopping qmail-smtpd-sub.\"
    svc -d /service/qmail-smtpd-sub
    echo \"* Sending qmail-send SIGTERM and restarting.\"
    svc -t /service/qmail-send
    echo \"* Restarting qmail-smtpd.\"
    svc -u /service/qmail-smtpd
    echo \"* Restarting qmail-smtpd-sub.\"
    svc -u /service/qmail-smtpd-sub
    echo \"* Restarting vpop.\"
    svc -u /service/vpop
    ;;
  cdb)
    tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
    chmod 644 /etc/tcp.smtp.cdb
    echo \"Reloaded /etc/tcp.smtp.\"
    ;;
  help)
    cat <<HELP
   stop -- stops mail service (smtp connections refused, nothing goes out)
  start -- starts mail service (smtp connection accepted, mail can go out)
  pause -- temporarily stops mail service (connections accepted, nothing leaves)
   cont -- continues paused mail service
   stat -- displays status of mail service
    cdb -- rebuild the tcpserver cdb file for smtp
restart -- stops and restarts smtp, sends qmail-send a TERM & restarts it
doqueue -- schedules queued messages for immediate delivery
 reload -- sends qmail-send HUP, rereading locals and virtualdomains
  queue -- shows status of queue
   alrm -- same as doqueue
  flush -- same as doqueue
    hup -- same as reload
HELP
    ;;
  *)
    echo \"Usage: \$0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}\"
    exit 1
    ;;
esac

exit 0" > /etc/rc.d/init.d/qmail
chmod 700 /etc/rc.d/init.d/qmail
chkconfig --add qmail
chkconfig --level 35 qmail on
/etc/rc.d/init.d/qmail start
else
# 우분투용        
 if [ -f /etc/lsb-release ] ; then
echo "#!/bin/sh

set -e

. /lib/lsb/init-functions

PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

case \"\$1\" in
  start)
    log_daemon_msg \"Starting qmail\"
     if [ -e /service/qmail-send ] ; then
        if svok /service/qmail-send ; then
            svc -u /service/qmail-send
        else
            echo qmail-send supervise not running
        fi
     else
        ln -s /var/qmail/supervise/qmail-send /service/
     fi

     if [ -e /service/qmail-smtpd ] ; then
        if svok /service/qmail-smtpd ; then
            svc -u /service/qmail-smtpd
        else
            echo qmail-smtpd supervise not running
        fi
     else
        ln -s /var/qmail/supervise/qmail-smtpd /service/
     fi

     if [ -e /service/qmail-smtpd-sub ] ; then
        if svok /service/qmail-smtpd-sub ; then
            svc -u /service/qmail-smtpd-sub
        else
            echo qmail-smtpd-sub supervise not running
        fi
     else
        ln -s /var/qmail/supervise/qmail-smtpd-sub /service/
     fi

         if [ -e /service/vpop ] ; then
                if svok /service/vpop ; then
                        svc -u /service/vpop
                else
                        echo vpop supervise not running
                fi
         else
                ln -s /var/qmail/supervise/vpop /service/
         fi

    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
    log_end_msg 0
    ;;
  stop)
    log_daemon_msg \"Stopping qmail...\"
    echo \"  qmail-smtpd\"
    svc -dx /service/qmail-smtpd /service/qmail-smtpd/log
    echo \"  qmail-smtpd-sub\"
    svc -dx /service/qmail-smtpd-sub /service/qmail-smtpd-sub/log
     rm -f /service/qmail-smtpd-sub
    echo \"  qmail-send\"
    svc -dx /service/qmail-send /service/qmail-send/log
     rm -f /service/qmail-send
    echo \"  vpop\"
    svc -dx /service/vpop
         rm -f /service/vpop
    if [ -f /var/lock/subsys/qmail ]; then
      rm /var/lock/subsys/qmail
    fi
    log_end_msg 0
    ;;
  stat)
    svstat /service/qmail-send
    svstat /service/qmail-send/log
    svstat /service/qmail-smtpd
    svstat /service/qmail-smtpd/log
    svstat /service/qmail-smtpd-sub
    svstat /service/qmail-smtpd-sub/log
    svstat /service/vpop
    qmail-qstat
    ;;
  doqueue|alrm|flush)
    echo \"Flushing timeout table and sending ALRM signal to qmail-send.\"
    /var/qmail/bin/qmail-tcpok
    svc -a /service/qmail-send
    ;;
  queue)
    qmail-qstat
    qmail-qread
    ;;
  reload|hup)
    echo \"Sending HUP signal to qmail-send.\"
    svc -h /service/qmail-send
    ;;
  pause)
    echo \"Pausing qmail-send\"
    svc -p /service/qmail-send
    echo \"Pausing qmail-smtpd\"
    svc -p /service/qmail-smtpd
    echo \"Pausing qmail-smtpd-sub\"
    svc -p /service/qmail-smtpd-sub
    echo \"Pausing vpop\"
    svc -p /service/vpop
    ;;
  cont)
    echo \"Continuing qmail-send\"
    svc -c /service/qmail-send
    echo \"Continuing qmail-smtpd\"
    svc -c /service/qmail-smtpd
    echo \"Continuing qmail-smtpd-sub\"
    svc -c /service/qmail-smtpd-sub
    echo \"Continuing vpop\"
    svc -c /service/vpop
    ;;
  restart)
  log_daemon_msg \"Restarting qmail\"
    echo \"* Stopping qmail-smtpd.\"
    svc -d /service/qmail-smtpd
    echo \"* Stopping qmail-smtpd-sub.\"
    svc -d /service/qmail-smtpd-sub
    echo \"* Sending qmail-send SIGTERM and restarting.\"
    svc -t /service/qmail-send
    echo \"* Restarting qmail-smtpd.\"
    svc -u /service/qmail-smtpd
    echo \"* Restarting qmail-smtpd-sub.\"
    svc -u /service/qmail-smtpd-sub
    log_end_msg 0
    ;;
  cdb)
    tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
    chmod 644 /etc/tcp.smtp.cdb
    echo \"Reloaded /etc/tcp.smtp.\"
    ;;
  help)
    cat <<HELP
   stop -- stops mail service (smtp connections refused, nothing goes out)
  start -- starts mail service (smtp connection accepted, mail can go out)
  pause -- temporarily stops mail service (connections accepted, nothing leaves)
   cont -- continues paused mail service
   stat -- displays status of mail service
    cdb -- rebuild the tcpserver cdb file for smtp
restart -- stops and restarts smtp, sends qmail-send a TERM & restarts it
doqueue -- schedules queued messages for immediate delivery
 reload -- sends qmail-send HUP, rereading locals and virtualdomains
  queue -- shows status of queue
   alrm -- same as doqueue
  flush -- same as doqueue
    hup -- same as reload
HELP
    ;;
  *)
    echo \"Usage: \$0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}\"
    exit 1
    ;;
esac

exit 0" > /etc/init.d/qmail
  chmod 700 /etc/init.d/qmail
  update-rc.d qmail defaults
  /etc/init.d/qmail start
 fi
fi

/home/vpopmail/bin/vadddomain $DOMAIN $POSTMASTER_PASSWD
echo ""
echo ""
echo ""
echo "★★★설치 완료★★★"
exit 0
 
 http://www.digimoon.net/blog/323
 위 링크에 소개한 설치 과정을 스크립트화하였습니다.
 IMAP 설치 과정은 제외하였습니다. POP3만 지원합니다.

 http://linuxstudy.pe.kr 의 김경민님께서 제작하여 배포하고 계신 knetqmail 패치가 적용됩니다. knetqmail 패키지를 이미 srpm 버전으로도 배포하고 계시지만 rpm 빌드 시 의존성 에러 등을 몇 번 겪어서 소스 컴파일 설치 방식이 불가피한 경우에 대비한 스크립트를 따로 제작하여 사용하게 되었고 이번에 이렇게 공개합니다.
 euckr 쉘환경에서 설치 과정 텍스트가 정상적으로 출력되므로 utf-8 환경의 경우엔 iconv 커맨드로 변환하여 사용하시기 바랍니다.
 CentOS, Fedora, Ubuntu 등에서 사용 가능합니다. 최신 버전에서는 테스트해 보지 않아서 결과가 어떨지는 잘 모르겠습니다. 얼마나 많은 분들이 사용하실지는 모르지만 사용해 보시고 덧글로 피드백 남겨 주시면 감사하겠습니다.
 스크립트 돌리기 전 시스템에 각종 개발 도구를 필히 설치해 둔 뒤 사용하시기 바랍니다.

Creative Commons License
2010/08/21 12:54 2010/08/21 12:54

qmail 설치 문서들 대부분이 daemontools와 연동하는 방법을 많이 소개하고 있는데 이 daemontools와 연동한 qmail을 운영하면서 적잖이 만난 에러 메시지 중의 하나가 아래와 같이 ps 커맨드로 확인되는 qmail multilog error이다. readproctitle service errors: ...multilog: fatal: unable to lock directory /var/log/qmail/smtpd: tempor...