Mail Server DSM 7 Beta + Mail Relaxer

as_sa

Benutzer
Mitglied seit
24. Jan 2020
Beiträge
1
Punkte für Reaktionen
0
Punkte
1
Guten Abend,

weiss jemand wie ich den Mail Relaxer unter der 7er Beta installieren kann ?
Ich bekomme beim manuellen Installieren den Hinweis das Mail Relaxer nicht installieren kann da es mit root Rechten ausgeführt wird.
Weiss jemand Rat ß

Bild_2021-02-07_002403.png
 
  • Haha
Reaktionen: mayo007

hoewer

Benutzer
Mitglied seit
29. Nov 2016
Beiträge
15
Punkte für Reaktionen
6
Punkte
3
Mail Relaxer ist im Wesentlichen ein Bash-Script, welches bislang als Deamon gestartet wurde. Auch wenn es schon alt ist, läuft es einwandfrei und tut seinen Dienst ohne murren. Und: Ja - es braucht root-Rechte und wird als SPK vermutlich nicht mehr laufen können.

Aber man kann das Bash-Skript aus dem SPK extrahieren und ggf. einfach nach dem Booten aktivieren. In der Theorie sollte das funktionieren, auch wenn man dann kein schickes Paket mehr im Web-Interface hat (mit dem hübschen Symbol ;-)). Wenn man die Einträge im Changelog betrachtet, lief das Skript ursprünglich offenbar genau so, also ohne SPK.

Leider kann ich das selbst nicht testen, da ich noch längst nicht auf DSM 7 wechseln kann. Ich müsste hierzu noch diverse Anwendungen in Docker verschieben und habe hierzu im Moment nicht die Zeit. (BTW: Falls Docker-Images unter DSM 7 noch mit root-Rechten laufen dürfen, wäre auch eine Docker-Implementierung von Mail-Relaxer denkbar...)

Ich habe das Bash-Skript mal angehängt. Es ist unbedingt darauf zu achten, ob sich die Pfade zur Mailstation in DSM7 geändert habe - beim Umstieg von DSM5 zu DSM6 war genau das ein Problem. Falls jemand damit testet, bitte gerne hier eine Rückmeldung abgeben.

Bash:
#!/bin/sh
#=========================================================================
# Daemon to Relax the Mail processes
#
# Start/Stop some Mail processes depending on Mail client activity:
# 1) external Mail client: imap is running
# 2) webmail (roundcube) : "dovecot-auth -w" remains running
#
# This will allow your Syno to sleep during the quiet hours
#-------------------------------------------------------------------------
# 03may12 EB    First version
# 19apr13 EB    Changed into standard DSM 3rd party app
# 08jun13 EB    POP3FetchControl() changed, check on POP3Fetch_enabled
# 11aug14 EB    Aligned with Mail Server 1.3-0215, minor change:
#               POP3FetchControl() changed, changed POP3Fetch_enabled
# 08nov14 EB    Alignment with Mail Station 20141031-0213:
#               - WebMailConf: changed main.inc.php into config.inc.php
#               - POP3FetchControl(): POP3Fetch_enabled and popusers
#               main changed: try max 3 times to start or stop processes
#               main changed: check on auth instead of dovecot-auth
#               No changes needed for Mail Server 1.4-0281
# 16dec16 OH    Aligned with DSM6, Mail Server 1.6.1-0484
#               - Basic path infos changed
#               - Sed syntax changed to match current version
#=========================================================================
LOGINFO="/usr/bin/logger -sp user.warn -t relax INFO: "
LOGERROR="/usr/bin/logger -sp user.error -t relax ERROR: "

#=========================================================================
# Start/Stop Fetchmail
# Based on: /var/packages/MailStation/scripts/start-stop-status
#=========================================================================
WebMailDir="/var/packages/MailStation/target"
WebMailExt=${WebMailDir}/mail/ext
WebMailConf=${WebMailDir}/mail/config/config.inc.php
FetchBin=${WebMailDir}/bin/synofetch

POP3FetchControl()    # argument: -1=Start|-2=Stop
{
    if [ "$1" = "-1" ]; then
        POP3Fetch_enabled=`grep -E "config.*extmailallow" ${WebMailConf} | tr -d ' ' | cut -d '=' -f2`
        if [ "$POP3Fetch_enabled" != "true;" ]; then
                # Fetching with POP3 is not enabled
                return
        fi

        popusers=`/usr/bin/find ${WebMailExt} -name "*_fetch" | /usr/bin/cut -d'/' -f8 | sed 's/.\{6\}$//'`
        # To check if sed's syntax matches the sed version on your system, you may activate
        # $LOGINFO "PopUser is \"$popusers\""
        # The log entry in /var/log/messages should contain those users fetching mail via POP3
        for popusr in $popusers
        do
            if [ -e ${WebMailExt}/${popusr}_fetch ]; then
                ${FetchBin} ${popusr} $1
            #else No fetch configured, skip
            fi
        done
    else
        # Since Mail Station 20130129-0058 this command is used to stop
        # (previously, the for loop above was used for stop as well)
        killall fetchmail  
    fi
}

#=========================================================================
# Start/Stop Postfix
# Based on: /var/packages/MailServer/scripts/start-stop-status
# ...and:   /var/packages/MailServer/target/scripts/PostfixDaemon.sh
# Note that only the daemon is started/stopped here.
#=========================================================================
POSTFIX=/var/packages/MailServer/target/sbin/postfix
MAILCONF="/var/packages/MailServer/etc/mailserver.conf"

PostfixControl()    # argument: start|stop
{
    SmtpEnable=`/bin/get_key_value $MAILCONF smtp_enabled`
    if [ "$SmtpEnable" = "yes" ]; then
        $POSTFIX $1
    fi
}

#*************************************************************************
#    Main
#*************************************************************************
STOP_FLAG=$0_stop_flag

case "$1" in
    boot_start)
        rm -f $STOP_FLAG
        $LOGINFO "System boot process requested to start daemon=\"$0\", first sleep to ensure proper boot completion"
        sleep 60
        $LOGINFO "The daemon=\"$0\" is awake now"
        ;;
    manual_start)
        rm -f $STOP_FLAG
        $LOGINFO "Manual request to start daemon=\"$0\""
        ;;
    stop)
        touch $STOP_FLAG
        $LOGINFO "Requested daemon=\"$0\" to stop gracefully"
        exit 0
        ;;
    *)
        $LOGERROR "Invalid argument=\"$1\" to daemon=\"$0\""
        exit 1
        ;;
esac

IsActiveMailClient=0
IsRunningFetchMail=0
InactiveCounter=0
RetryCounter=0

while [ ! -f $STOP_FLAG ]
do
    #------------------------------------------------------------------
    # Check if fetchmail is running
    #------------------------------------------------------------------
    if [ -n "`pidof fetchmail`" ]
        then    IsRunningFetchMail=1
        else    IsRunningFetchMail=0
    fi

    #------------------------------------------------------------------
    # Check if mail clients are active
    #------------------------------------------------------------------
    if [ -n "`pidof imap`" ]; then
        IsActiveMailClient=1    # external Mail client active, e.g. Outlook
    else
        IsActiveMailClient=0
        # Look if dovecot authentication worker is active, that indicates webmail active
        # With `ps` this process shows up as "dovecot/auth -w"
        # (however, do not use `ps` since it wakes up Syno by reading nsswitch.conf)
        for process_id in `pidof auth`
        do
            # Check if this is a worker process, by reading cmdline switch in /proc
            grep -s -q /proc/$process_id/cmdline -i -e "-w$"
            if [ $? -eq 0 ]; then
                IsActiveMailClient=1    # Webmail active
            fi
        done
    fi

    if [ $IsActiveMailClient -ne $IsRunningFetchMail ]; then
        if [ $IsRunningFetchMail -ne 0 ]; then
            #------------------------------------------------------------------
            # Fetchmail is still running while no mail clients active anymore
            #------------------------------------------------------------------
            if [ $InactiveCounter -gt 20 ]; then
                if [ $RetryCounter -le 3 ]; then
                    $LOGINFO "Mail clients inactive, stopping mail processes"
                    POP3FetchControl -2
                    PostfixControl stop
                    let RetryCounter++
                    InactiveCounter=0
                else
                    $LOGERROR "Giving up: cannot stop mail processes."
                    touch $STOP_FLAG
                fi
            else
                # Check a few times first
                let InactiveCounter++
            fi
        else
            #------------------------------------------------------------------
            # Mail clients are active, while mail processes are not running yet
            #------------------------------------------------------------------
            if [ $RetryCounter -le 3 ]; then
                $LOGINFO "Mail clients active, restarting mail processes"
                POP3FetchControl -1
                PostfixControl start
                let RetryCounter++
                InactiveCounter=0
            else
                $LOGERROR "Giving up: cannot start mail processes."
                touch $STOP_FLAG
            fi
        fi
    else
        # Mail processes in sync with Mail client demands
        InactiveCounter=0
        RetryCounter=0
    fi
    sleep 3
done

#------------------------------------------------
# Daemon is stopping gracefully
# Make sure mail processes are running again
#------------------------------------------------
if [ $IsRunningFetchMail -eq 0 ]; then
    $LOGINFO "Daemon=\"$0\" is restarting the mail processes..."
    POP3FetchControl -1
    PostfixControl start
fi
$LOGINFO "Daemon=\"$0\" will exit now"
 
Zuletzt bearbeitet:


 

Kaffeautomat

Wenn du das Forum hilfreich findest oder uns unterstützen möchtest, dann gib uns doch einfach einen Kaffee aus.

Als Dankeschön schalten wir deinen Account werbefrei.

:coffee:

Hier gehts zum Kaffeeautomat