Skip to content

Commit f5248cd

Browse files
Merge pull request #9 from pschmitt/systemd-user-service
2 parents f08343b + 6945a05 commit f5248cd

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

README.md

+22-10
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,28 @@ use your default NIC and listen on port `8080`.
5555

5656
If your system is using Systemd, you can use the following unit file to run the companion on system boot:
5757

58-
```ini
59-
# sudo vi /etc/systemd/system/hacompanion.service
58+
```shell
59+
mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user
60+
${EDITOR:-vi} "${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/hacompanion.service"
61+
```
6062

63+
```ini
6164
[Unit]
6265
Description=Home Assistant Desktop Companion
66+
Documentation=https://github.com/tobias-kuendig/hacompanion
67+
# Uncomment the line below if you are using NetworkManager to ensure hacompanion
68+
# only starts after your host is online
69+
# After=NetworkManager-wait-online.service
6370

6471
[Service]
65-
User=user-username # Change this
66-
Group=user-username # Change this
67-
ExecStart=/path/to/hacompanion -config=/home/yourname/.config/hacompanion.toml # Change this
68-
Type=simple
72+
# Load ~/.config/hacompanion/env where you can for example set
73+
# HASS_TOKEN, HASS_DEVICE_NAME etc.
74+
EnvironmentFile=%E/hacompanion/env
75+
# Make sure to set the absolute path to hacompanion correctly below
76+
ExecStart=%h/.local/bin/hacompanion -config=%E/hacompanion.toml
6977
Restart=on-failure
70-
RuntimeMaxSec=604800
78+
RestartSec=5
79+
Type=simple
7180

7281
[Install]
7382
WantedBy=multi-user.target
@@ -76,9 +85,12 @@ WantedBy=multi-user.target
7685
Start the companion by running:
7786

7887
```bash
79-
sudo service hacompanion start
80-
# check status with
81-
# sudo service hacompanion status
88+
systemctl --user daemon-reload
89+
systemctl --user enable --now hacompanion
90+
# check status with:
91+
# systemctl --user status hacompanion
92+
# and logs with:
93+
# journalctl --user -xlf -u hacompanion
8294
```
8395

8496
## Custom scripts

0 commit comments

Comments
 (0)