TS3Tools / TS3UpdateScript

Automate all update processes for your TeamSpeak 3 server instances
GNU General Public License v3.0
189 stars 22 forks source link

systemd restart teamspeak before updater finished #71

Closed Thumpxr closed 7 years ago

Thumpxr commented 7 years ago

I'm using a systemd service to start/stop/restart my ts3 server. Unfortunatly the script does not stop this service before updating. This results in an instant restart by systemd before the update-script can update...

Thumpxr commented 7 years ago

Would it work if i change:

function ts3server() {
    case $2 in
        start)
            RESULT=$(su -s "$(which bash)" -c "cd $1 && ./ts3server_startscript.sh start 2> /dev/null && cd - > /dev/null" - $(getOwnerOfTS3ServerFiles $1))

            if [[ "$RESULT" =~ 'TeamSpeak 3 server started, for details please view the log file' ]]; then
                return 0;
            else
                return 1;
            fi
        ;;

        status)
            RESULT=$(su -s "$(which bash)" -c "cd $1 && ./ts3server_startscript.sh status && cd - > /dev/null" - $(getOwnerOfTS3ServerFiles $1))

            if [[ "$RESULT" =~ 'Server is running' ]]; then
                return 0;
            else
                return 1;
            fi
        ;;

        stop)
            RESULT=$(su -s "$(which bash)" -c "cd $1 && ./ts3server_startscript.sh stop && cd - > /dev/null" - $(getOwnerOfTS3ServerFiles $1))

            if [[ "$RESULT" =~ 'Stopping the TeamSpeak 3 server\.+done' ]]; then
                return 0;
            else
                return 1;
            fi
        ;;

        *)
            return 1;
        ;;
    esac
}

to this


function ts3server() {
    case $2 in
        start)
            RESULT=$(service teamspeak start> /dev/null && cd - > /dev/null" - $(getOwnerOfTS3ServerFiles $1))

            if [[ "$RESULT" =~ 'TeamSpeak 3 server started, for details please view the log file' ]]; then
                return 0;
            else
                return 1;
            fi
        ;;

        status)
            RESULT=$(service teamspeak status && cd - > /dev/null" - $(getOwnerOfTS3ServerFiles $1))

            if [[ "$RESULT" =~ 'Server is running' ]]; then
                return 0;
            else
                return 1;
            fi
        ;;

        stop)
            RESULT=$(service teamspeak stop && cd - > /dev/null" - $(getOwnerOfTS3ServerFiles $1))

            if [[ "$RESULT" =~ 'Stopping the TeamSpeak 3 server\.+done' ]]; then
                return 0;
            else
                return 1;
            fi
        ;;

        *)
            return 1;
        ;;
    esac
}

or even this?

function ts3server() {
    case $2 in
        start)
            (service teamspeak start
                return 0
        ;;

        status)
            service teamspeak status
                return 0
        ;;

        stop)
            service teamspeak stop
                return 0
        ;;

        *)
            return 1;
        ;;
    esac
}
Sebbo94BY commented 7 years ago

I wouldn't change the script. You rather should improve / update your systemd script.

Always, when the TS3UpdateScript will update your TeamSpeak 3 server, it will create a lock file called .ts3updatescript.lock in the root directory of each TS3 server. You may check with systemd, if this file exists or not and if, systemd should not do anything.

Thumpxr commented 7 years ago

Ah, that makes sense.

Using this works. As i only start the teamspeak server as user teamspeak.


[Unit]
Description=Teamspeak 3 Server
After=network.target
ConditionPathExists=!/home/teamspeak/server/.ts3updatescript.lock
StartLimitInterval=600
StartLimitBurst=18

[Service]
User=teamspeak
WorkingDirectory=/home/teamspeak/server
Type=forking
ExecStartPre=/usr/bin/killall -u teamspeak
ExecStart=/home/teamspeak/server/ts3server_startscript.sh start
ExecStop=/home/teamspeak/server/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/server/ts3server_startscript.sh restart
PIDFile=/home/teamspeak/server/ts3server.pid
Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target