rootkiwi / an2linuxserver

Sync Android notifications encrypted to a Linux desktop
Other
401 stars 43 forks source link

an2linuxserver.py cannot connect to notification daemon when run from systemd service unit #27

Open hashn0n opened 7 years ago

hashn0n commented 7 years ago

So here is the problem using proposed in README.md service unit And no notification is displayed, I do not use tmux, so a wrote service unit that used screen:

Description=AN2Linux server screen

[Service]
Type=forking
Restart=on-failure
ExecStart=/usr/bin/screen -dmS an2linux '/opt/bin/an2linuxserver.py'
ExecStop=/usr/bin/screen -X -S an2linux quit

[Install]
WantedBy=default.target

After that I was able to connect to screen session and what I tried to send test notification that is what I got:

[2017-02-08 20:34:37] (TCP) Failed to use IPv4/IPv6 dual stacking, fallbacks to IPv4 only
[2017-02-08 20:34:37] (TCP) Waiting for connections on port 46352
[2017-02-08 20:34:56] (Notification) Error showing notification: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files (2)
[2017-02-08 20:34:56] Please make sure you have a notification server installed on your system

Obviously if same thing executed in any X-term, all works fine. I can see same error in unit without screen usage without StandardOutput=null

[2017-02-08 22:03:00] (TCP) Failed to use IPv4/IPv6 dual stacking, fallbacks to IPv4 only
[2017-02-08 22:03:00] (TCP) Waiting for connections on port 46352
[2017-02-08 22:03:10] (Notification) Error showing notification: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files (2)
[2017-02-08 22:03:10] Please make sure you have a notification server installed on your system
rootkiwi commented 7 years ago

Maybe there could be a problem if you are using a systemwide unit file and not a --user file?

Do the service unit work without screen?

daradib commented 7 years ago

@hashn0n can you try exporting a DISPLAY variable by adding this under the [Service] section in your systemd unit config:

Environment=DISPLAY=:0

(Run echo $DISPLAY to see if you need to use something other than :0.)

hashn0n commented 7 years ago

Commands used: systemctl --user daemon-reload ; systemctl --user restart an2linux_screen exporting a DISPLAY: systemctl --user cat an2linux_screen Result:

# /home/hash/.config/systemd/user/an2linux_screen.service
[Unit]
Description=AN2Linux server screen

[Service]
Type=forking
Restart=on-failure
Environment=DISPLAY=:0
ExecStart=/usr/bin/screen -dmS an2linux '/opt/bin/an2linuxserver.py'
ExecStop=/usr/bin/screen -X -S an2linux quit

[Install]
WantedBy=default.target

Same error as before and no notifications displayed. Just a piece of maybe interesting info: LANG=C systemctl --user status an2linux_screen LANG=C Because system lang is ru_RU.utf8. Result:

* an2linux_screen.service - AN2Linux server screen
   Loaded: loaded (/home/<USERNAME>/.config/systemd/user/an2linux_screen.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-02-27 17:39:57 MSK; 8min ago
  Process: 3805 ExecStart=/usr/bin/screen -dmS an2linux /opt/bin/an2linuxserver.py (code=exited, status=0/SUCCESS)
 Main PID: 3806 (screen)
   CGroup: /user.slice/user-1000.slice/user@1000.service/an2linux_screen.service
           |-3806 /usr/bin/SCREEN -dmS an2linux /opt/bin/an2linuxserver.py
           `-3807 /usr/lib/python-exec/python3.4/python3 /opt/bin/an2linuxserver.py

Feb 27 17:39:57 <HOSTNAME> systemd[1100]: Starting AN2Linux server screen...
Feb 27 17:39:57 <HOSTNAME> systemd[1100]: Started AN2Linux server screen.
renekliment commented 7 years ago

Hey there. I have the same issue. I use i3 with dunst started on the i3 startup. Hit me up please if you have a solution. Thank you.

undermink commented 6 years ago

Just got the same error when starting an2linuxserver.py from inside tmux. No issues when running it outside of tmux though.

ghost commented 5 years ago

I found that, if I ran the server as a user service, it worked only if I add this to the service file:

Environment="DISPLAY=:0" "XAUTHORITY=/home/<my main user>/.Xauthority"

Running the server as a normal program worked. I imagine that running the server as a system service would not work, unless - yes? - one used the above fix.

ammgws commented 5 years ago

Strange. Mine is running fine with the below user service file:

[Unit]
Description=AN2Linux

[Service]
Type=simple
StandardOutput=null
Restart=on-failure
ExecStart=/usr/bin/an2linuxserver.py

[Install]
WantedBy=default.target
ghost commented 5 years ago

Hmm. My ExecStart path is to a folder within my home directory. Also, perhaps distro & DE make a difference? I'm on Mint Cinnamon.

ammgws commented 5 years ago

I don't think it makes a difference but I'm on Arch running swaywm (Wayland).

What are the file permissions to your ExecStart?

stat -c '%a' /usr/bin/an2linuxserver.py

755

ls -al /usr/bin/an2linuxserver.py

-rwxr-xr-x 1 root root 41077 Dec 24 16:30 /usr/bin/an2linuxserver.py