Skip to content

Commit 6ba05f0

Browse files
committed
docs: add systemd setup guide
1 parent 6009873 commit 6ba05f0

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ opencode-telegram stop
9999

100100
> Built-in daemon mode is intended for standalone npm installs without an external supervisor. For `systemd`, `pm2`, or Docker, keep using `opencode-telegram start` without `--daemon`.
101101
102+
For Linux `systemd` setup, see [`docs/LINUX_SYSTEMD_SETUP.md`](./docs/LINUX_SYSTEMD_SETUP.md).
103+
102104
To reconfigure at any time:
103105

104106
```bash

docs/LINUX_SYSTEMD_SETUP.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Linux systemd setup
2+
3+
## 1. Install and configure the bot
4+
5+
```bash
6+
npm install -g @grinev/opencode-telegram-bot@latest
7+
opencode-telegram config
8+
```
9+
10+
## 2. Get the required paths
11+
12+
```bash
13+
which node
14+
which opencode-telegram
15+
dirname "$(which node)"
16+
```
17+
18+
Use these values in the service file:
19+
20+
- `<USER>`: your Linux user
21+
- `<NODE_PATH>`: output of `which node`
22+
- `<OPENCODE_TELEGRAM_PATH>`: output of `which opencode-telegram`
23+
- `<NODE_BIN_DIR>`: output of `dirname "$(which node)"`
24+
25+
## 3. Create the service file
26+
27+
Create `/etc/systemd/system/opencode-telegram-bot.service`:
28+
29+
```ini
30+
[Unit]
31+
Description=OpenCode Telegram Bot
32+
After=network.target
33+
34+
[Service]
35+
Type=simple
36+
User=<USER>
37+
Environment=PATH=<NODE_BIN_DIR>:/usr/local/bin:/usr/bin:/bin
38+
ExecStart=<NODE_PATH> <OPENCODE_TELEGRAM_PATH> start
39+
Restart=on-failure
40+
RestartSec=5
41+
42+
[Install]
43+
WantedBy=multi-user.target
44+
```
45+
46+
Run the bot in foreground mode. Do not use `--daemon` under `systemd`.
47+
48+
## 4. Enable and start the service
49+
50+
```bash
51+
sudo systemctl daemon-reload
52+
sudo systemctl enable opencode-telegram-bot
53+
sudo systemctl start opencode-telegram-bot
54+
sudo systemctl status opencode-telegram-bot
55+
```
56+
57+
## 5. View logs
58+
59+
```bash
60+
sudo journalctl -u opencode-telegram-bot -f
61+
```
62+
63+
## Example
64+
65+
This is a working example for an `nvm`-based setup:
66+
67+
`ExecStart` does not include `start` here because `start` is the default CLI command.
68+
69+
```ini
70+
[Unit]
71+
Description=OpenCode Telegram Bot
72+
After=network.target
73+
74+
[Service]
75+
Type=simple
76+
User=admin
77+
Environment=PATH=/home/admin/.nvm/versions/node/v20.20.2/bin:/usr/local/bin:/usr/bin:/bin
78+
ExecStart=/home/admin/.nvm/versions/node/v20.20.2/bin/node /home/admin/.nvm/versions/node/v20.20.2/bin/opencode-telegram
79+
Restart=on-failure
80+
RestartSec=5
81+
82+
[Install]
83+
WantedBy=default.target
84+
```

0 commit comments

Comments
 (0)