Setting bot as service allows you to run it in backrgound and easily control.
- Pick folder where you want your bot to be stored:
root/example_folder
(for example) - Open terminal and navigate to this folder:
cd root/example_folder
- Clone bot using git:
git clone https://github.com/shamhi/GangstaMonkeyBot.git
- Navigate to clonned repository:
cd root/example_folder/GangstaMonkeyBot
- Create a virtual enviroment:
python3 -m venv venv
- Activates the virtual environment:
source venv/bin/activate
- Install all Python dependencies:
pip3 install -r requirements.txt
- Create enviroment file from template:
cp .env-example .env
- Setup your needed parameters in
.env
file using any code editor:nano .env
(nano as example) - Run
main.py
and init session.
- Navigate to system folder where every service is stored using terminal:
cd /etc/systemd/system/
- Create service file with any name you want:
sudo touch monkeybot.service
- Fill
.service
file with content using any code editor:sudo nano monkeybot.service
(nano for example) Content:[Unit] Description=GangstaMonkeyBotService After=network.target [Service] User=root WorkingDirectory=/root/example/GangstaMonkeyBot/ Environment=PATH=/root/example/GangstaMonkeyBot/venv/bin/ ExecStart=/root/example/GangstaMonkeyBot/venv/bin/python3 /root/example/GangstaMonkeyBot/main.py -a 2 Restart=always [Install] WantedBy=multi-user.target
User=
- user u running this service fromWorkingDirectory=
- path to cloned repository folderEnviroment=
- enviroment folder / venv value insertsExecStart=
- runner command
- Reload system manager config using terminal:
sudo systemctl daemon-reload
- Enable service, setting it as autostart:
sudo systemctl enable monkeybot.service
Now we are done.
Stop service:
sudo systemctl stop monkeybot.service
Start service:
sudo systemctl start monkeybot.service
Restart service:
sudo systemctl restart monkeybot.service
Check status:
sudo systemctl status monkeybot.service
Check logs:
sudo journalctl -u monkeybot.service
Check logs in real time:
sudo journalctl -u monkeybot.service -f