Deploy on Ubuntu/Debian
After you have created your bot, you should deply it on a server (you can also run it locally, but that would require you to have your pc always on).
To deploy your bot on Ubuntu/Debian, please make sure you have installed the following dependencies:
python3.10 or higher (you can check your Python version by runningpython3 --version)pip(you can check yourpipversion by runningpip3 --version)
Not required, but recommended:
venv(you can check yourvenvversion by runningpython3 -m venv --version)git(you can check yourgitversion by runninggit --version)
Install Python 3.10 (if not available in the default repositories)
Python 3.10 is not available in the default Ubuntu repositories. You can install it by following the steps below:
- Add the deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa
- Update the package list:
sudo apt update
- Install Python 3.10:
sudo apt install python3.10
- Install
pipfor Python 3.10:
sudo apt install python3.10-distutils
curl https://bootstrap.pypa.io/get-pip.py | sudo python3.10
Install dependencies
To install the dependencies, run the following commands:
If you have a requirements.txt file:
pip3 install -r requirements.txt
If you don't have a requirements.txt file:
pip3 install swibots
Install other dependencies if you need them.
Run the bot
To run the bot, run the following command:
python3 <your bot file>.py
Run the bot on startup
To run the bot on startup, you can use systemd or supervisor.
Using systemd
To run the bot on startup using systemd, you can follow the steps below:
- Create a service file for your bot. You can use the following template:
[Unit]
Description=<your bot name>
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=<your user>
ExecStart=python3 /path/to/bot.py
[Install]
WantedBy=multi-user.target
-
Save the file as
/etc/systemd/system/<your bot name>.service. -
Reload the systemd daemon:
systemctl daemon-reload
Using supervisor
To run the bot on startup using supervisor, you can follow the steps below:
- Install
supervisor:
sudo apt install supervisor
- Create a configuration file for your bot. You can use the following template:
[program:<your bot name>]
command=/home/user/your-user/venv/bin/python /path/to/bot.py
directory=/path/to/bot/directory
autostart=true
autorestart=true
startsecs=10
stderr_logfile=/var/log/<your bot name>.err.log
stdout_logfile=/var/log/<your bot name>.out.log
-
Save the file as
/etc/supervisor/conf.d/<your bot name>.conf. -
Reload the supervisor configuration:
sudo supervisorctl reread
sudo supervisorctl update