Przeglądaj źródła

add systemd unit file, describe install in readme.

Thomas Buck 2 lat temu
rodzic
commit
5f6f52e10e
2 zmienionych plików z 40 dodań i 2 usunięć
  1. 24
    2
      README.md
  2. 16
    0
      lights-telegram.service

+ 24
- 2
README.md Wyświetl plik

@@ -3,11 +3,11 @@
3 3
 Simple MQTT bridge in the form of a Telegram Bot.
4 4
 And also my first attempt at doing something with Go.
5 5
 
6
-## Getting Started
6
+## Configuration
7 7
 
8 8
 First register a new Bot with the Telegram, as [described in the docs](https://core.telegram.org/bots#6-botfather), to get your API key.
9 9
 
10
-Then simply run lights-telegram once manually.
10
+Then simply run lights-telegram once manually using `go run .`.
11 11
 This will create a `config.yaml` file in the same directory.
12 12
 Your API key goes in there, as well as the MQTT credentials.
13 13
 
@@ -20,10 +20,32 @@ Now this admin account can add further user authorizations using chat messages t
20 20
 As an admin use `/register` to add new MQTT topics and their possible values to the menu.
21 21
 Finally run `/commandlist` on the bot to get a nicely formatted command list which you can then give to the `/setcommands` command of BotFather.
22 22
 
23
+## Installation
24
+
25
+Run `go build` to produce an executable in the project directory.
26
+
27
+You now need to decide on an installation location for both the executable as well as the configuration file.
28
+As an example, I'll be using `~/bin/lights-telegram/` as the install directory.
29
+
30
+You also need to decide which user will run the server.
31
+It needs write access to the directory / config file.
32
+In this example we'll also be using the current user, `thomas` in my case.
33
+
34
+Modify the username and paths in `lights-telegram.service` and the commands below as required.
35
+
36
+    CGO_ENABLED=0 go build
37
+    mkdir ~/bin/lights-telegram
38
+    cp lights-telegram ~/bin/lights-telegram/lights-telegram
39
+    cp config.yaml ~/bin/lights-telegram/config.yaml
40
+    cp lights-telegram.service /etc/systemd/system/lights-telegram.service
41
+    systemctl daemon-reload
42
+    systemctl enable --now lights-telegram
43
+
23 44
 ## Dependencies
24 45
 
25 46
  * [tgbotapi](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5)
26 47
  * [mqtt](https://pkg.go.dev/github.com/eclipse/paho.mqtt.golang)
48
+ * [yaml](https://pkg.go.dev/gopkg.in/yaml.v3)
27 49
 
28 50
 ## License
29 51
 

+ 16
- 0
lights-telegram.service Wyświetl plik

@@ -0,0 +1,16 @@
1
+[Unit]
2
+Description=Telegram bot MQTT interface
3
+Requires=network.target
4
+After=network.target
5
+After=syslog.target
6
+
7
+[Service]
8
+Type=simple
9
+Restart=always
10
+RestartSec=3
11
+User=thomas
12
+WorkingDirectory=/home/thomas/bin/lights-telegram
13
+ExecStart=/home/thomas/bin/lights-telegram/lights-telegram
14
+
15
+[Install]
16
+WantedBy=multi-user.target

Ładowanie…
Anuluj
Zapisz