Commits

Zhang Huangbin  committed 975af2a

Fixed: cannot start MySQL on FreeBSD.
Code cleanup.

  • Participants
  • Parent commits 3755fba

Comments (0)

Files changed (16)

File iRedMail/conf/core

     done
 }
 
-# TODO
-enable_service_freebsd()
-{
-    :
-}
-
-# TODO
-disable_service_freebsd()
-{
-    :
-}
-
 service_control()
 {
     service="$1"
     fi
 }
 
+freebsd_enable_service_in_rc_conf()
+{
+    # USAGE: freebsd_enable_service_in_rc_conf VAR VALUE
+    if [ X"${DISTRO}" == X'FREEBSD' ]; then
+        [ -f /etc/rc.conf ] || touch /etc/rc.conf
+        if [ X"$#" == X'2' ]; then
+            var="${1}"
+            value="${2}"
+            final_option="${1}='${2}'"
+            comment_mark="# ${PROG_NAME}-${var}"
+            if ! grep "^${comment_mark}$" /etc/rc.conf &>/dev/null; then
+                ECHO_DEBUG "Add setting in /etc/rc.conf: ${final_option}"
+                echo "${comment_mark}" >> /etc/rc.conf
+                echo "${final_option}" >> /etc/rc.conf
+            else
+                ECHO_DEBUG "Skip adding setting in /etc/rc.conf: ${final_option}"
+            fi
+        fi
+    fi
+}
+

File iRedMail/conf/dovecot

 export SIEVE_RULE_FILENAME='dovecot.sieve'
 export DOVECOT_GLOBAL_SIEVE_FILE="${SIEVE_DIR}/${SIEVE_RULE_FILENAME}"
 
+# Dovecot config files
+export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
+export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
+export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
+export DOVECOT_PGSQL_CONF='/etc/dovecot/dovecot-pgsql.conf'
+export DOVECOT_REALTIME_QUOTA_CONF='/etc/dovecot/dovecot-used-quota.conf'
+export DOVECOT_SHARE_FOLDER_CONF='/etc/dovecot/dovecot-share-folder.conf'
+
+# Path to Dovecot deliver agant
+export DOVECOT_DELIVER='/usr/libexec/dovecot/deliver'
+
 if [ X"${DISTRO}" == X"RHEL" ]; then
-    export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
-    export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
-    export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
-    export DOVECOT_PGSQL_CONF='/etc/dovecot/dovecot-pgsql.conf'
-    export DOVECOT_REALTIME_QUOTA_CONF='/etc/dovecot/dovecot-used-quota.conf'
-    export DOVECOT_SHARE_FOLDER_CONF='/etc/dovecot/dovecot-share-folder.conf'
-
     if [ X"${DISTRO_VERSION}" == X"5" ]; then
         export DOVECOT_VERSION='1.2'
         export DOVECOT_CONF='/etc/dovecot.conf'
         export DOVECOT_REALTIME_QUOTA_CONF='/etc/dovecot-used-quota.conf'
         export DOVECOT_SHARE_FOLDER_CONF='/etc/dovecot-share-folder.conf'
     fi
-    export DOVECOT_DELIVER='/usr/libexec/dovecot/deliver'
 elif [ X"${DISTRO}" == X"SUSE" ]; then
-    export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
-    export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
-    export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
-    export DOVECOT_PGSQL_CONF='/etc/dovecot/dovecot-pgsql.conf'
-    export DOVECOT_REALTIME_QUOTA_CONF='/etc/dovecot/dovecot-used-quota.conf'
-    export DOVECOT_SHARE_FOLDER_CONF='/etc/dovecot/dovecot-share-folder.conf'
     export DOVECOT_DELIVER='/usr/lib/dovecot/deliver'
+
 elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
     if [ X"${DISTRO}" == X"DEBIAN" ]; then
         export DOVECOT_VERSION='1.2'
         fi
     fi
 
-    export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
-    export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
-    export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
-    export DOVECOT_PGSQL_CONF='/etc/dovecot/dovecot-pgsql.conf'
-    export DOVECOT_REALTIME_QUOTA_CONF='/etc/dovecot/dovecot-used-quota.conf'
-    export DOVECOT_SHARE_FOLDER_CONF='/etc/dovecot/dovecot-share-folder.conf'
     export DOVECOT_DELIVER='/usr/lib/dovecot/deliver'
 
-elif [ X"${DISTRO}" == X"GENTOO" ]; then
-    export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
-    export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
-    export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
-    export DOVECOT_PGSQL_CONF='/etc/dovecot/dovecot-pgsql.conf'
-    export DOVECOT_REALTIME_QUOTA_CONF='/etc/dovecot/dovecot-used-quota.conf'
-    export DOVECOT_SHARE_FOLDER_CONF='/etc/dovecot/dovecot-share-folder.conf'
-    export DOVECOT_DELIVER='/usr/libexec/dovecot/deliver'
-
 elif [ X"${DISTRO}" == X"FREEBSD" ]; then
-    export DOVECOT_CONF='/usr/local/etc/dovecot.conf'
-    export DOVECOT_LDAP_CONF='/usr/local/etc/dovecot-ldap.conf'
-    export DOVECOT_MYSQL_CONF='/usr/local/etc/dovecot-mysql.conf'
-    export DOVECOT_PGSQL_CONF='/usr/local/etc/dovecot-pgsql.conf'
-    export DOVECOT_REALTIME_QUOTA_CONF='/usr/local/etc/dovecot-used-quota.conf'
-    export DOVECOT_SHARE_FOLDER_CONF='/usr/local/etc/dovecot-share-folder.conf'
+    export DOVECOT_CONF='/usr/local/etc/dovecot/dovecot.conf'
+    export DOVECOT_LDAP_CONF='/usr/local/etc/dovecot/dovecot-ldap.conf'
+    export DOVECOT_MYSQL_CONF='/usr/local/etc/dovecot/dovecot-mysql.conf'
+    export DOVECOT_PGSQL_CONF='/usr/local/etc/dovecot/dovecot-pgsql.conf'
+    export DOVECOT_REALTIME_QUOTA_CONF='/usr/local/etc/dovecot/dovecot-used-quota.conf'
+    export DOVECOT_SHARE_FOLDER_CONF='/usr/local/etc/dovecot/dovecot-share-folder.conf'
     export DOVECOT_DELIVER='/usr/local/libexec/dovecot/deliver'
 fi
 

File iRedMail/conf/mysql

     export MYSQL_SOCKET='/var/run/mysqld/mysql.sock'
 
 elif [ X"${DISTRO}" == X"FREEBSD" ]; then
+    export MYSQL_RC_SCRIPT_NAME='mysql-server'
     export MYSQL_SOCKET='/tmp/mysql.sock'
     export MYSQL_MY_CNF="/var/db/mysql/my.cnf"
 fi

File iRedMail/functions/amavisd.sh

     fi
 
     # FreeBSD: Start amavisd when system start up.
-    [ X"${DISTRO}" == X"FREEBSD" ] && cat >> /etc/rc.conf <<EOF
-# Start amavisd, disable amavis-milter.
-amavisd_enable="YES"
-amavisd_pidfile="/var/amavis/amavisd.pid"
-amavis_milter_enable="NO"
-amavis_p0fanalyzer_enable="NO"
-#amavis_p0fanalyzer_p0f_filter="tcp dst port 25"
-EOF
+    freebsd_enable_service_in_rc_conf 'amavisd_enable' 'YES'
+    freebsd_enable_service_in_rc_conf 'amavisd_pidfile' '/var/amavis/amavisd.pid'
+    freebsd_enable_service_in_rc_conf 'amavis_milter_enable' 'NO'
+    freebsd_enable_service_in_rc_conf 'amavis_p0fanalyzer_enable' 'NO'
 
     check_status_before_run amavisd_config_general
     check_status_before_run amavisd_import_sql

File iRedMail/functions/apache_php.sh

         mkdir -p /usr/local/www/proxy/ 2>/dev/null
 
         # Start apache when system start up.
-        cat >> /etc/rc.conf <<EOF
-# Start apache web server.
-apache22_enable="YES"
-htcacheclean_enable="NO"
-EOF
+        freebsd_enable_service_in_rc_conf 'apache22_enable' 'YES'
+        freebsd_enable_service_in_rc_conf 'htcacheclean_enable' 'NO'
     fi
 
     ##############

File iRedMail/functions/clamav.sh

     fi
 
     # FreeBSD: Start clamd & freshclamd when system start up.
-    [ X"${DISTRO}" == X"FREEBSD" ] && cat >> /etc/rc.conf <<EOF
-# Start clamd and freshclamd.
-clamav_clamd_enable="YES"
-clamav_freshclam_enable="YES"
-EOF
+    freebsd_enable_service_in_rc_conf 'clamav_clamd_enable' 'YES'
+    freebsd_enable_service_in_rc_conf 'clamav_freshclam_enable' 'YES'
 
     cat >> ${TIP_FILE} <<EOF
 ClamAV:

File iRedMail/functions/dovecot1.sh

         check_status_before_run dovecot_config
     fi
 
-    # FreeBSD.
     if [ X"${DISTRO}" == X"FREEBSD" ]; then
         # It seems there's a bug in Dovecot port, it will try to invoke '/usr/lib/sendmail'
         # to send vacation response which should be '/usr/sbin/mailwrapper'.
         [ ! -e /usr/lib/sendmail ] && ln -s /usr/sbin/mailwrapper /usr/lib/sendmail 2>/dev/null
 
         # Start dovecot when system start up.
-        cat >> /etc/rc.conf <<EOF
-# Start dovecot IMAP/POP3 server.
-dovecot_enable="YES"
-EOF
+        freebsd_enable_service_in_rc_conf 'dovecot_enable' 'YES'
     fi
 
     echo 'export status_enable_dovecot1="DONE"' >> ${STATUS_FILE}

File iRedMail/functions/dovecot2.sh

         check_status_before_run dovecot2_config
     fi
 
+    if [ X"${DISTRO}" == X"FREEBSD" ]; then
+        # It seems there's a bug in Dovecot port, it will try to invoke '/usr/lib/sendmail'
+        # to send vacation response which should be '/usr/sbin/mailwrapper'.
+        [ ! -e /usr/lib/sendmail ] && ln -s /usr/sbin/mailwrapper /usr/lib/sendmail 2>/dev/null
+
+        # Start dovecot when system start up.
+        freebsd_enable_service_in_rc_conf 'dovecot_enable' 'YES'
+    fi
+
     echo 'export status_enable_dovecot2="DONE"' >> ${STATUS_FILE}
 }

File iRedMail/functions/fail2ban.sh

 EOF
 
     # FreeBSD: Start fail2ban when system start up.
-    if [ X"${DISTRO}" == X"FREEBSD" ]; then
-        cat >> /etc/rc.conf <<EOF
-# Start fail2ban.
-fail2ban_enable="YES"
-EOF
-    fi
+    freebsd_enable_service_in_rc_conf 'fail2ban_enable' 'YES'
 
     echo 'export status_fail2ban_config="DONE"' >> ${STATUS_FILE}
 }

File iRedMail/functions/iredapd.sh

     ECHO_INFO "Configure iRedAPD (postfix policy daemon)."
 
     # Create a low privilege user as daemon user.
-    if [ X"${DISTRO}" == X'FreeBSD' ]; then
+    if [ X"${DISTRO}" == X'FREEBSD' ]; then
         pw useradd -m -d ${IREDAPD_HOME_DIR} -s ${SHELL_NOLOGIN} -c "iRedAPD daemon user" -n ${IREDAPD_DAEMON_USER}
     elif [ X"${DISTRO}" == X"SUSE" ]; then
         groupadd ${IREDAPD_DAEMON_GROUP}
         perl -pi -e 's#^(plugins).*#${1} = sql_alias_access_policy#' iredapd.ini
     fi
 
-    # FreeBSD.
-    if [ X"${DISTRO}" == X"FREEBSD" ]; then
-        # Start iredapd when system start up.
-        cat >> /etc/rc.conf <<EOF
-# Start iredapd.
-iredapd_enable="YES"
-EOF
-    fi
+    # FreeBSD: Start iredapd when system start up.
+    freebsd_enable_service_in_rc_conf 'iredapd_enable' 'YES'
 
     cat >> ${TIP_FILE} <<EOF
 iRedAPD - Postfix Policy Daemon:

File iRedMail/functions/mysql.sh

 # -------------------------------------------------------
 mysql_initialize()
 {
-    ECHO_DEBUG "Configure MySQL database server." 
+    ECHO_INFO "Configure MySQL database server." 
 
     ECHO_DEBUG "Starting MySQL."
 
 
     # FreeBSD: Start mysql when system start up.
     # Warning: We must have 'mysql_enable=YES' before start/stop mysql daemon.
-    [ X"${DISTRO}" == X"FREEBSD" ] && cat >> /etc/rc.conf <<EOF
-# Start mysql server.
-mysql_enable="YES"
-EOF
+    freebsd_enable_service_in_rc_conf 'mysql_enable' 'YES'
 
-    ${MYSQLD_RC_SCRIPT} restart >/dev/null 2>&1
+    ${MYSQLD_RC_SCRIPT} restart &>/dev/null
 
     ECHO_DEBUG -n "Sleep 5 seconds for MySQL daemon initialize:"
     sleep 5

File iRedMail/functions/openldap.sh

 
     # FreeBSD: Start openldap when system start up.
     # Warning: Make sure we have 'slapd_enable=YES' before start/stop openldap.
-    [ X"${DISTRO}" == X"FREEBSD" ] && cat >> /etc/rc.conf <<EOF
-# Start openldap server.
-slapd_enable="YES"
-slapd_flags='-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://127.0.0.1/ ldaps://127.0.0.1/"'
-slapd_sockets="/var/run/openldap/ldapi"
-EOF
+    freebsd_enable_service_in_rc_conf 'slapd_enable' 'YES'
+    freebsd_enable_service_in_rc_conf 'slapd_flags' '-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://127.0.0.1/ ldaps://127.0.0.1/"'
+    freebsd_enable_service_in_rc_conf 'slapd_sockets' '/var/run/openldap/ldapi'
 
     echo 'export status_openldap_config="DONE"' >> ${STATUS_FILE}
 }

File iRedMail/functions/packages_freebsd.sh

     for i in m4 libiconv cyrus-sasl2 perl openslp mysql openldap24 dovecot2 \
         ca_root_nss libssh2 curl libusb pth gnupg p5-IO-Socket-SSL \
         p5-Archive-Tar p5-Net-DNS p5-Mail-SpamAssassin p5-Authen-SASL \
-        amavisd-new clamav apr python26 apache22 php5 php5-extensions \
+        amavisd-new clamav apr python27 apache22 php5 php5-extensions \
         php5-gd roundcube postfix MySQLdb p7zip; do
         mkdir -p /var/db/ports/${i} 2>/dev/null
     done
 WITHOUT_PGSQL=true
 EOF
 
-    # Python v2.6. REQUIRED.
-    cat > /var/db/ports/python26/options <<EOF
+    # Python v2.7
+    cat > /var/db/ports/python27/options <<EOF
 WITH_THREADS=true
-WITH_HUGE_STACK_SIZE=true
+WITHOUT_SEM=true
+WITHOUT_PTH=true
 WITH_UCS4=true
 WITH_PYMALLOC=true
 WITH_IPV6=true

File iRedMail/functions/policy_server.sh

     fi
 
     # FreeBSD: Start policyd when system start up.
-    [ X"${DISTRO}" == X"FREEBSD" ] && cat >> /etc/rc.conf <<EOF
-# Start policyd.
-postfix_policyd_sf_enable="YES"
-EOF
+    freebsd_enable_service_in_rc_conf 'postfix_policyd_sf_enable' 'YES'
 
     echo 'export status_policy_server_config="DONE"' >> ${STATUS_FILE}
 }

File iRedMail/functions/postfix.sh

 newaliases  /usr/local/sbin/sendmail
 EOF
 
-        cat >> /etc/rc.conf <<EOF
-# Start postfix.
-postfix_enable="YES"
-# Disable sendmail.
-sendmail_enable="NO"
-sendmail_submit_enable="NO"
-sendmail_outbound_enable="NO"
-sendmail_msp_queue_enable="NO"
-daily_clean_hoststat_enable="NO"
-daily_status_mail_rejects_enable="NO"
-daily_status_include_submit_mailq="NO"
-daily_submit_queuerun="NO"
-EOF
+        freebsd_enable_service_in_rc_conf 'postfix_enable' 'YES'
+        freebsd_enable_service_in_rc_conf 'sendmail_enable' 'NO'
+        freebsd_enable_service_in_rc_conf 'sendmail_submit_enable' 'NO'
+        freebsd_enable_service_in_rc_conf 'sendmail_outbound_enable' 'NO'
+        freebsd_enable_service_in_rc_conf 'sendmail_msp_queue_enable' 'NO'
+        freebsd_enable_service_in_rc_conf 'daily_clean_hoststat_enable' 'NO'
+        freebsd_enable_service_in_rc_conf 'daily_status_mail_rejects_enable' 'NO'
+        freebsd_enable_service_in_rc_conf 'daily_status_include_submit_mailq' 'NO'
+        freebsd_enable_service_in_rc_conf 'daily_submit_queuerun' 'NO'
     fi
 
     # Create directory, used to store lookup files.

File iRedMail/functions/postgresql.sh

     # FreeBSD: Start pgsql when system start up.
     # Warning: We must have 'postgresql_enable=YES' before start/stop mysql daemon.
     if [ X"${DISTRO}" == X"FREEBSD" ]; then
-        cat >> /etc/rc.conf <<EOF
-# Start PostgreSQL server.
-postgresql_enable="YES"
-EOF
+        freebsd_enable_service_in_rc_conf 'postgresql_enable' 'YES'
 
         su - ${PGSQL_SYS_USER} -c "${PGSQL_RC_SCRIPT} initdb" >/dev/null
     fi