Skip to content

Commit

Permalink
adjusted Readme and added systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
NNTin committed Jan 25, 2019
1 parent 3f38430 commit bdcfb63
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ heroku create <your heroku app name>
cd <your heroku app name>
git remote add origin https://github.com/NNTin/discord-twitter-bot
git pull origin master
python3 launcher.py
python bot/launcher.py
git add .
git commit -am "updated configuration"
git push heroku
Expand All @@ -43,15 +43,16 @@ This will create a data.json and the bot will ignore any set environment variabl
Get Python >=3.5.3, <3.7

```coffeescript
python3 -m venv bot-env
source bot-env/bin/activate
git clone https://github.com/NNTin/discord-twitter-bot.git
python3 discord-twitter-bot/launcher.py
cd discord-twitter-bot # ^ download the project and cd into it
python3 -m venv venv # optional virtual environment, recommended
source venv/bin/activate # only run if you did venv
python3 -m pip install tox # optional used for testing/troubleshooting/contributing
python3 bot/launcher.py # configure the bot, this create a config.json
tox # only run if you did tox, run the test suite
python3 bot/main.py # run the bot
```

First two lines are skip-able but are recommended if you are relying on an older version of discord.py.
Third line clones the GitHub project. Fourth line executes launcher.py

Once you have set everything up you can run main.py directly. (Useful in combination with systemd, Upstart, PM2, etc.)

![](https://i.imgur.com/TdJahu9.png)
Expand Down
37 changes: 37 additions & 0 deletions etc/systemd/system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Prologue

Systemd is a nice tool to start, stop and restart scripts on your linu machine. If your script crashes or the VPS does a system reboot your scripts will come back online.
In order to use this you need to be on Linux, have systemd, the discord-twitter-bot has been properly installed and it has worked before.

# Setup

Copy the dtb.service file and put it to /etc/systemd/system
`cp dtb.service /etc/systemd/system/dtb.service`

Edit dtb.service
`nano /etc/systemd/system/dtb.service`

Adjust the `WorkingDirectory` to the path you git cloned the `discord-twitter-bot` folder/repository.

Adjust the path of your python executable (first parameter of `ExecStart`):
```coffeescript
tin@Riftshadow:~# which python3
/usr/bin/python3
tin@Riftshadow:~# which python3.5
/usr/bin/python3.5
```

Adjust the path to main.py (second parameter of `ExecStart`)
`<...>/discord-twitter-bot/bot/main.py`

# systemd commands

```coffeescript
sudo systemctl start dtb.service
sudo systemctl enable dtb.service
sudo systemctl disable dtb.service
sudo systemctl stop dtb.service
sudo systemctl restart dtb.service
```

`enable` means that the service is automatically started when your VPS boots up.
14 changes: 14 additions & 0 deletions etc/systemd/system/dtb.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=discord-twitter-bot
After=multi-user.target
[Service]
WorkingDirectory=/home/tin/discord-twitter-bot
User=tin
Group=tin
ExecStart=/usr/bin/python3 /home/tin/discord-twitter-bot/bot/main.py
Type=idle
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

0 comments on commit bdcfb63

Please sign in to comment.