A Discord Bot, that I'm not sure what it'll do yet - but I wanted to have something that:
- Powered by Rust
- Deployed via Systemctl
- To a locally running Raspberry Pi
The rest I don't really care about at the moment :shrug-dog:
For ArmV7 (eg Raspberry Pi) or x86_64
Linux (eg Linux Server).
- Github Actions
- Builds on the remote server whenever you push a tag. You can then download this from releases. See
.github/workflows
./bin/build_on_git {commit-sha} {message}
- Note: Running
./bin/deploy
will NOT build this for you, it'll just download the latest release from CI
- Builds on the remote server whenever you push a tag. You can then download this from releases. See
- Cross
- Only works on non-
aarch64
machines (Eg NOT M1 Macs).cross
, simply put:
cargo install cross cross build --release --target armv7-unknown-linux-gnueabihf
- Note: Running
./bin/deploy
WILL do this for you
- Only works on non-
- Native Toolchains (Eg from an aarch64 machine)
brew tap messense/macos-cross-toolchains brew install armv7-unknown-linux-gnueabihf x86_64-unknown-linux-gnu ./bin/build_for_arm ./bin/build_for_x86_64
- Native (Eg Machine matches host)
- When native hosts matches deploy host, can just run
cargo build --release
- When native hosts matches deploy host, can just run
- Define a
prod.env
file inside the root of this repo:
#prod.env
API_KEY=<Your Bot's Token Here>
APP_ID=<Your Bot's Application Id Here>
EMOTE_NAME=<your-emote || shrug_dog>
EMOTE_USERS=<csv of users || User1,User2,User3>
SERVER_MAC=<game-server-mac>
SERVER_IP=<game-server-ip>
SERVER_DOCKER_PORT=<docker-tcp-port-on-game-server>
SERVER_USER=<game-server-user>
LOG_LEVEL=INFO
TIMEOUT=600
#You can repeat this for dev.env as well
ARCH={armv7-unknown-linux-gnueabihf|x86_64-unknown-linux-gnu} ./deploy.sh {dev|prod} {server.local|raspberrypi.local}
- You can use github to download a release made in CI with
BUILD_GITHUB=1
- Otherwise this will detect the correct way to build from your host system
Install required dependencies for the songbird functionality to work:
apt install libopus-dev ffmpeg
sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
(If you need to update yt-dlp
use the -U
flag)
- Create a systemd service file like so (you might repeat for dev):
[Unit]
Description=Disbot Service File
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=<user>
ExecStart=/home/<user>/deploy/disbot-prod prod
WorkingDirectory=/home/<user>/deploy
[Install]
WantedBy=multi-user.target
systemctl start disbot
systemctl enable disbot
- logs:
journalctl -u disbot -b -f
(-b
is current boot filter)
For docker interactions to work over the local network you'll need to edit the systemd service to enable TCP access over the local network:
sudo vim /etc/systemd/system/snap.docker.dockerd.service
...
ExecStart=/usr/bin/snap run docker.dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
And then reload the daemon:
sudo systemctl daemon-reload
sudo systemctl restart snap.docker.dockerd.service
Validate: curl http://localhost:2375/v1.40/containers/json
. This will need to be repeated each time the snap is updated. Ideally this isn't a problem if the daemon can be configured from outside the snap, however it's unclear if that's plausible at this point in time.
- Ensure the
SERVER_USER
has sudo-er privileged to runshutdown
without a password. (Eg:sudo visudo -> [user]\tALL=NOPASSWD:[pathToBin1],[pathtoBin2],...
) - Equally, ensure the bot's host can run
ssh
without a password (eg setup it's SSH keys).