Build E5SubBot for E5 renewal under Linux

 wallpaper

preface

Some time ago, E5SubBot was used to renew 365 E5. After use, it was found that the E5SubBot project was indeed effective. Because the program was previously run in the background using nohup, the program will stop after running for a period of time. In order to solve this problem, I wrote a shell script myself, and then solved this problem with the help of the planned task. Later, I found that I had made a detour again. Wouldn't it be better to use systemd services?

However, I still need to record what I have written. It's meaningless to delete it directly. Here is my first script.

 #!/ bin/bash pid=`ps -aux | grep E5SubBot | grep -v 'grep' | awk '{print $2}'` if [ "$pid" != "" ]; then echo "running ..." else echo "$(date '+%Y/%m/%d %H:%M:%S'):no run,starting..." >> /root/e5cron.log echo "no run" cd /root/e5sub/ && nohup /root/e5sub/E5SubBot >> /root/e5sub/e5sub-$(date +%Y%m%d%H%M%S).log & fi

Then, in coordination with the scheduled task, execute the shell written by yourself every two hours to determine whether it has stopped running. If it has stopped, start it. If it has not stopped, ignore it.

 * */2 * * * /root/e5bot.sh

However, the above method is not a perfect solution. Later, I changed the scheme of scheduling tasks to the system d service mode. The operating system of the server I used is Centos 7. The specific process is as follows.

setup script

The following is my specific installation process in Centos 7 operating system.

Access E5SubBot project address

E5SubBot Project Github Address: https://github.com/iyear/E5SubBot/releases

Select the appropriate version

Select the corresponding version to download according to the specific situation of your server. Here I choose the E5SubBot_Linux_64bit version, which is currently used by most servers.

 wget  https://github.com/iyear/E5SubBot/releases/download/v0.2.1/E5SubBot_Linux_64bit.tar.gz

Unzip files

Unzip the file you just downloaded.

 tar xvf E5SubBot_Linux_64bit.tar.gz

The following four files are obtained, and we need to use the binary file E5SubBot.

 LICENSE README.md README_zhCN.md E5SubBot

Create folders and move files

Move the extracted file E5SubBot to the corresponding directory.

 #Create Folder mkdir /opt/e5sub #Move files mv E5SubBot /opt/e5sub/E5SubBot #Add execution permission to the file chmod a+x /opt/e5sub/E5SubBot

Configure E5Subbot

Create a config.yml file in the/opt/e5sub directory to configure the details of the telegram bot and mysql. If you don't know how to configure, please read the Configuration

 vim /opt/e5sub/config.yml

The configuration file contents are as follows:

 Bot_token: TOKEN of your TG robot Notice: "Here you can fill in the notification information of the robot" Admin: fill in your tg ID as administrator #socks5: 127.0.0.1:1080 errlimit: 15 cron: "1 */1 * * *" bindmax: 5 mysql: host: localhost port: 3306  user: e5sub password: e5sub database: e5sub

Of course, if you use a domestic server, you need to specify the socks5 attribute to use the proxy server. The following is a description of specific attributes.

attribute explain
bot_token The token of tg robot can be obtained through @ BotFather
socks5 [Optional] It is used to specify the socks5 proxy, for example, 127.0.0.1:1080
notice Announcement, displayed when using/help
admin Administrator tgid can be accessed through @userinfobot Get, used to manually execute/task tasks and get feedback on task execution in progress
errlimit The maximum number of errors in a single account. When the number of errors in a single account reaches the specified number, the system will automatically unbind and send a notification. If it is set to - 1, there is no limit
bindmax Maximum number of accounts bound to a single account
cron The frequency of calling the api, using cron expressions
mysql Connection information of MySQL database

Write Systemd unit file

Edit the cell file using the vim editor.

 vim /etc/systemd/system/e5sub.service

Copy the following contents into it.

 [Unit] Description=Telegram E5Sub Bot [Service] Type=simple WorkingDirectory=/opt/e5sub ExecStart=/opt/e5sub/E5SubBot Restart=always RestartSec=30 [Install] WantedBy=multi-user.target

Set automatic startup

After editing the systemd unit file, you need to reload the service configuration file.

 systemctl daemon-reload

Then start the service.

 systemctl start e5sub

View service status.

 systemctl status e5sub

Finally, set the service auto start.

 systemctl enable e5sub

Reference Documents

systemd.service — Service unit configuration

E5SubBot#configuration

Comment area
 head portrait