Add systemd service configuration

This commit is contained in:
Michaël
2025-12-25 15:30:31 -03:00
parent 19e2824538
commit ae281ead03
2 changed files with 103 additions and 0 deletions

74
SYSTEMD_SETUP.md Normal file
View File

@@ -0,0 +1,74 @@
# Systemd Service Setup
This guide explains how to set up the Button Refresh Bot as a systemd service on Linux.
## Prerequisites
- Linux system with systemd
- Node.js installed
- Bot configured with `.env` file
## Installation Steps
1. **Edit the service file**
Open `buttonrefreshbot.service` and update the following:
- `User`: Your Linux username (e.g., `michael`)
- `Group`: Your Linux group (usually same as username)
- `WorkingDirectory`: Full path to the project directory
- `EnvironmentFile`: Full path to your `.env` file
- `ExecStart`: Full path to `node` executable (find with `which node`)
Example:
```ini
User=michael
Group=michael
WorkingDirectory=/home/michael/Buttonrefreshbot
EnvironmentFile=/home/michael/Buttonrefreshbot/.env
ExecStart=/usr/bin/node /home/michael/Buttonrefreshbot/bot.js
```
2. **Copy the service file to systemd directory**
```bash
sudo cp buttonrefreshbot.service /etc/systemd/system/
```
3. **Reload systemd daemon**
```bash
sudo systemctl daemon-reload
```
4. **Enable the service (start on boot)**
```bash
sudo systemctl enable buttonrefreshbot.service
```
5. **Start the service**
```bash
sudo systemctl start buttonrefreshbot.service
```
6. **Check service status**
```bash
sudo systemctl status buttonrefreshbot.service
```
## Useful Commands
- **View logs**: `sudo journalctl -u buttonrefreshbot.service -f`
- **Stop service**: `sudo systemctl stop buttonrefreshbot.service`
- **Restart service**: `sudo systemctl restart buttonrefreshbot.service`
- **Disable auto-start**: `sudo systemctl disable buttonrefreshbot.service`
## Troubleshooting
- If the service fails to start, check logs: `sudo journalctl -u buttonrefreshbot.service -n 50`
- Ensure the `.env` file has correct permissions and contains `BOT_TOKEN`
- Verify Node.js path is correct: `which node`
- Check file permissions: the service user must have read access to all project files