BafDyce / botamusique

Bot to play local music on Mumble (using pymumble). youtube;soundcloud,radio soon.
MIT License
1 stars 0 forks source link

Try to reconnect on connection loss #46

Open BafDyce opened 6 years ago

BafDyce commented 6 years ago

Currently when there's a connection issue between the bot and the connected mumble server (after successfully joining the server) the bot just quits. However, there are situations where it might be desired if the bot would try to reconnect:

In case the bot loses the connection to the server it should retry to connect a number of times (n) with some time (t) delay between each connection retry.

Each parameter should be configurable (command line and/or config file) with some meaningful default values if omitted.

azlux commented 6 years ago

botamusique stop if disconnect (https://github.com/azlux/botamusique/blob/master/mumbleBot.py#L315) You need to use a systemd service or the debian packet supervisor to manage the restart.

BafDyce commented 6 years ago

Yeah, I was also thinking about just using a custom script for me personally. Nevertheless I think it would be a great feature to have in the bot itself, don't you think? :)

thejustsoul commented 6 years ago

@BafDyce You can use the script to start the bot, with auto-restart in case of an error.

Example:

bot_stub.sh

#!/usr/bin/env bash

while [ 1 ]; do
    echo "[$(date +%Y-%m-%d-%H%M%S)] Starting..."
    #command to start a bot
    sleep 5
    echo "[$(date +%Y-%m-%d-%H%M%S)] Restarting..."
done

bot_start.sh

#!/usr/bin/env bash

cd "/path/to/bot"
screen -AmdS "bot" ./bot_stub.sh
azlux commented 6 years ago

please do a systemd service. I will write one in few days.

I personally use a Supervisor programm for now.

[program:bot]
command=/home/az/bot.py -s **** -u *****-c Channel
autostart=true
autorestart=true
startretries=10
startsecs=10
stopwaitsecs=5
user=azlux
azlux commented 6 years ago

For systemd I use :

[Unit]
Description=XANA

[Service]
ExecStart=/root/botamusique/mumbleBot.py -s mumble.*******.net -u XANA -c Bots
Restart=always
Type=simple
RestartSec=15s
WorkingDirectory=/root/botamusique

[Install]
WantedBy=multi-user.target