systemd service starting without user login
September 26, 2019
I needed a systemd service to start at boot without any user being logged in. The problem: the WiFi connection was tied to a user session, so the network wasn't up when the service started.
Here's the full setup for Manjaro/ArchLinux.
1. Create the service file
/etc/systemd/system/myService.service:
[Unit]
Description=myService
After=network-online.target
Wants=network-online.target
AssertFileNotEmpty=/opt/myService/config.json
[Service]
Type=simple
SyslogIdentifier=myService
WorkingDirectory=/opt/myService
ExecStart=/opt/MyService/myexecutable
RemainAfterExit=true
Restart=always
Nice=-20
[Install]
WantedBy=multi-user.target
2. Enable and start the service
sudo systemctl enable myService.service
sudo systemctl daemon-reload
sudo systemctl restart myService.service
3. Check logs
journalctl -u myService.service
journalctl -u myService.service -b
4. Make WiFi available without login
Edit the connection file in /etc/NetworkManager/system-connections/:
[connection]
id=MyHotspot
uuid=exxxxxxxx-xxxxxxxxx
type=wifi
permissions=
[wifi]
mac-address=00:XX:XX:XX:DF:ED
mac-address-blacklist=
mode=infrastructure
ssid=My SSID
[wifi-security]
auth-alg=open
key-mgmt=wpa-psk
psk=MYPASSWORD
[ipv4]
dns-search=
method=auto
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
The key is permissions= (empty). Previously it listed specific users, meaning WiFi only came up at login time. With permissions= empty, the connection starts at boot regardless of who is logged in.