Browse Source

add systemd unit file, describe install in readme.

Thomas Buck 2 years ago
parent
commit
5f6f52e10e
2 changed files with 40 additions and 2 deletions
  1. 24
    2
      README.md
  2. 16
    0
      lights-telegram.service

+ 24
- 2
README.md View File

3
 Simple MQTT bridge in the form of a Telegram Bot.
3
 Simple MQTT bridge in the form of a Telegram Bot.
4
 And also my first attempt at doing something with Go.
4
 And also my first attempt at doing something with Go.
5
 
5
 
6
-## Getting Started
6
+## Configuration
7
 
7
 
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.
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
 This will create a `config.yaml` file in the same directory.
11
 This will create a `config.yaml` file in the same directory.
12
 Your API key goes in there, as well as the MQTT credentials.
12
 Your API key goes in there, as well as the MQTT credentials.
13
 
13
 
20
 As an admin use `/register` to add new MQTT topics and their possible values to the menu.
20
 As an admin use `/register` to add new MQTT topics and their possible values to the menu.
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.
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
 ## Dependencies
44
 ## Dependencies
24
 
45
 
25
  * [tgbotapi](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5)
46
  * [tgbotapi](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5)
26
  * [mqtt](https://pkg.go.dev/github.com/eclipse/paho.mqtt.golang)
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
 ## License
50
 ## License
29
 
51
 

+ 16
- 0
lights-telegram.service View File

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

Loading…
Cancel
Save