Skip to content

cozmopics.de

Tag: login

systemd service starting without login of user

I recently had to start a systemd process without having a user being logged in. The systemd process was starting, but unfortunately the network was not up and running. The issue was that the wifi was linked to the user. In this case I used ArchLinux (Manjaro)

Here are the steps to start a service fully automatically.
Create a service-file in the location /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 (or script)
RemainAfterExit=true
Restart=always
Nice=-20

[Install]
WantedBy=multi-user.target


Once created enable the service. This will enable the service startup of the system.

sudo systemctl enable myService.service
sudo systemctl daemon-reload
sudo systemctl restart myService.service

In order to check the logs of your service use the following command:

# Just use the journalctl command, as in:
journalctl -u service-name.service

# Or, to see only log messages for the current boot:
journalctl -u service-name.service -b

Adjust the following script /etc/NetworkManager/system-connections
Change the connection of your linux.

[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

Important here is thepermissions=.In a previous version of the file it was mentioning a few users. So the wifi only came up at login time of the users. With permissions=  it starts even without anybody logging in.

Author augeresPosted on 26. September 201926. September 2019Categories LinuxTags autostart, connection, daemon, journalctl, linux, login, manjaro, NetworkManager, service, systemd, wifi, wlanLeave a comment on systemd service starting without login of user

Recent Posts

  • Deactivate Wordfence OTP
  • Recover FreeOTP Codes
  • adb full backup Android
  • systemd service starting without login of user
  • Keep processes running after ending ssh session

Recent Comments

  • augeres on Pi-Backup automation
  • augeres on Pi-Backup automation
  • augeres on Pi-Backup automation
  • Antonis on Pi-Backup automation
  • augeres on Pi-Backup automation

Archives

  • November 2024
  • September 2021
  • September 2019

Categories

  • Android
  • Linux
  • Raspberry Pi
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
cozmopics.de Proudly powered by WordPress