- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 777
systemd configuration
The systemd-version used for this setup is 219
, we'll be using a venv
for python and nano
for text-operations, the sample user is called ec2-user
and the bot is cloned to /home/ec2-user/bot
.
Paste code in nano = mouse-rightclick
SAVE file in nano = CTRL + O followed by ENTER
EXIT file in nano = CTRL + X
Create the service config file via opening the texteditor 'nano'
sudo nano /lib/systemd/system/binancebot.service
Paste the following code into the file, edit paths and user in WorkingDirectory, User and ExecStart to suite your settings, SAVE and EXIT
[Unit]
Description=Binance Bot Service
After=multi-user.target
[Service]
Type=idle
WorkingDirectory=/home/ec2-user/bot
User=ec2-user
ExecStart=/home/ec2-user/bot/.venv/bin/python3 -u '/home/ec2-user/bot/Binance Detect Moonings.py'
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=binance-bot
[Install]
WantedBy=multi-user.target
Create the rsyslog configuration via opening the texteditor 'nano'
sudo nano /etc/rsyslog.d/binancebot.conf
Paste the following code into the file (rightclick), SAVE and EXIT
template(name="bot-tmplt" type="string"
string="%msg:1:$%\n"
)
if $programname == "binance-bot" then /var/log/binancebot/bot.log;bot-tmplt
& stop
Create the logfile folder
sudo mkdir /var/log/binancebot
Just to be on the safe side: Create the logfile in the folder, SAVE and EXIT
sudo nano /var/log/binancebot/bot.log
Refresh services list
sudo systemctl daemon-reload
Restart rsyslog service (i think this could be skipped as we are rebooting soon)
sudo systemctl restart rsyslog
Enable the Binance Bot service to run at system boot
sudo systemctl enable binancebot
Reboot the machine
sudo reboot
Now we have setup the bot as a service and it autostarts with the machine.
We can manually start, stop, restart and view the status of the service with the following commands:
sudo systemctl start binancebot
sudo systemctl stop binancebot
sudo systemctl restart binancebot
sudo systemctl status binancebot
To view the log file we can use e.g. tail or mutlitail (if installed)
tail -f -n 100 /var/log/binancebot/bot.log
Any changes to the config files of either of the services will need to be applied with at least:
sudo systemctl daemon-reload
sudo systemctl restart SERVICENAME
Changing the config.yml of the bot requires sudo systemctl restart binancebot
to be applied.