[GH-ISSUE #76] Run as service via systemd #26

Closed
opened 2026-05-05 22:04:55 -06:00 by gitea-mirror · 17 comments
Owner

Originally created by @CupricReki on GitHub (Jan 15, 2024).
Original GitHub issue: https://github.com/feschber/lan-mouse/issues/76

Here is an example service file. Connection still needs to be activated via GUI until #70 is sorted.

/usr/lib/systemd/user/lan-mouse.service
[Unit]
Description=Mouse & keyboard sharing via LAN
Wants=network-pre.target
After=network-pre.target NetworkManager.service systemd-resolved.service

[Service]
ExecStart=/usr/bin/lan-mouse -d
Restart=on-failure

[Install]
WantedBy=multi-user.target

Start now and on boot

systemclt --user daemon-reload
systemctl --user enable --now lan-mouse.service
Originally created by @CupricReki on GitHub (Jan 15, 2024). Original GitHub issue: https://github.com/feschber/lan-mouse/issues/76 Here is an example service file. Connection still needs to be activated via GUI until #70 is sorted. ``` /usr/lib/systemd/user/lan-mouse.service ``` ``` [Unit] Description=Mouse & keyboard sharing via LAN Wants=network-pre.target After=network-pre.target NetworkManager.service systemd-resolved.service [Service] ExecStart=/usr/bin/lan-mouse -d Restart=on-failure [Install] WantedBy=multi-user.target ``` Start now and on boot ``` systemclt --user daemon-reload systemctl --user enable --now lan-mouse.service ```
Author
Owner

@alison-solsoft commented on GitHub (Jan 15, 2024):

This lines up with what I had created on my own end for a user daemon unit. Do we also want to consider the option of a system daemon unit, which would require both a global config path (/etc/lan-mouse/config.toml) and dedicated daemon user (lanmouse)?

I have a specific use case that will require either enabling lingering on my user session on one of my systems, or running the service under the system daemon. Using session lingering isn't a terrible solution, but it isn't obvious to less-experienced Linux users that lingering is even an option.

<!-- gh-comment-id:1892633102 --> @alison-solsoft commented on GitHub (Jan 15, 2024): This lines up with what I had created on my own end for a user daemon unit. Do we also want to consider the option of a system daemon unit, which would require both a global config path (/etc/lan-mouse/config.toml) and dedicated daemon user (lanmouse)? I have a specific use case that will require either enabling lingering on my user session on one of my systems, or running the service under the system daemon. Using session lingering isn't a terrible solution, but it isn't obvious to less-experienced Linux users that lingering is even an option.
Author
Owner

@feschber commented on GitHub (Jan 15, 2024):

A system service will not work because lan-mouse does not wait for a session to come online and simply falls back to the dummy backend. I would need to implement a way to wait for a session first. (Using systemd?)

I have been thinking about how that could be done but it will definitely take some effort. Maybe something similar to how rkvm works.

<!-- gh-comment-id:1892655941 --> @feschber commented on GitHub (Jan 15, 2024): A system service will not work because lan-mouse does not wait for a session to come online and simply falls back to the dummy backend. I would need to implement a way to wait for a session first. (Using systemd?) I have been thinking about how that could be done but it will definitely take some effort. Maybe something similar to how rkvm works.
Author
Owner

@alison-solsoft commented on GitHub (Jan 15, 2024):

Upon further review, I have an additional thought:

Is there a reason you used "network-pre.target " rather than simply "network.target"? I think it would be better to avoid tying service ordering to specific network management services, as that can potentially lead to issues for users of other network daemons (e.g. netctl in my case). If it's a startup delay concern, I don't think ordering against network.target would drastically increase startup times, at least not as much as network-online.target.

<!-- gh-comment-id:1892719014 --> @alison-solsoft commented on GitHub (Jan 15, 2024): Upon further review, I have an additional thought: Is there a reason you used "network-pre.target <network services>" rather than simply "network.target"? I think it would be better to avoid tying service ordering to specific network management services, as that can potentially lead to issues for users of other network daemons (e.g. netctl in my case). If it's a startup delay concern, I don't think ordering against network.target would drastically increase startup times, at least not as much as network-online.target.
Author
Owner

@feschber commented on GitHub (Jan 15, 2024):

Upon further review, I have an additional thought:

Is there a reason you used "network-pre.target " rather than simply "network.target"? I think it would be better to avoid tying service ordering to specific network management services, as that can potentially lead to issues for users of other network daemons (e.g. netctl in my case). If it's a startup delay concern, I don't think ordering against network.target would drastically increase startup times, at least not as much as network-online.target.

Network should actually not be necessary at all, as lan-mouse is connection less and simply starts working as soon as a network is connected. It should however be ensured that a graphical session is running. I'm guessing graphical-session.target would be the right choice. Aside from that, there may still be a race condition between dbus an the lan-mouse service. I will need to look into that.

<!-- gh-comment-id:1892731828 --> @feschber commented on GitHub (Jan 15, 2024): > Upon further review, I have an additional thought: > > Is there a reason you used "network-pre.target " rather than simply "network.target"? I think it would be better to avoid tying service ordering to specific network management services, as that can potentially lead to issues for users of other network daemons (e.g. netctl in my case). If it's a startup delay concern, I don't think ordering against network.target would drastically increase startup times, at least not as much as network-online.target. Network should actually not be necessary at all, as lan-mouse is connection less and simply starts working as soon as a network is connected. It should however be ensured that a graphical session is running. I'm guessing `graphical-session.target` would be the right choice. Aside from that, there may still be a race condition between dbus an the lan-mouse service. I will need to look into that.
Author
Owner

@feschber commented on GitHub (Jan 15, 2024):

Same goes for DNS. We probably should not assume that systemd-resolved is used either way.

<!-- gh-comment-id:1892736484 --> @feschber commented on GitHub (Jan 15, 2024): Same goes for DNS. We probably should not assume that systemd-resolved is used either way.
Author
Owner

@CupricReki commented on GitHub (Jan 15, 2024):

All good reasoning. Makes sense to exclude all the Wants/After. It was mostly there based on the example I was using.

<!-- gh-comment-id:1892737672 --> @CupricReki commented on GitHub (Jan 15, 2024): All good reasoning. Makes sense to exclude all the Wants/After. It was mostly there based on the example I was using.
Author
Owner

@feschber commented on GitHub (Jan 16, 2024):

It should now be possible to automate everything. Tell me if you notice any bugs :) And also feel free to open a PR for the user service.

<!-- gh-comment-id:1893621188 --> @feschber commented on GitHub (Jan 16, 2024): It should now be possible to automate everything. Tell me if you notice any bugs :) And also feel free to open a PR for the user service.
Author
Owner

@CupricReki commented on GitHub (Jan 16, 2024):

Great news! I'll give it a go this evening. Have you thought about adding a daemon option to the GUI and/or a tray icon?

<!-- gh-comment-id:1894232642 --> @CupricReki commented on GitHub (Jan 16, 2024): Great news! I'll give it a go this evening. Have you thought about adding a daemon option to the GUI and/or a tray icon?
Author
Owner

@feschber commented on GitHub (Jan 16, 2024):

My latest commit broke it again. Have to fix asap

<!-- gh-comment-id:1894292129 --> @feschber commented on GitHub (Jan 16, 2024): My latest commit broke it again. Have to fix asap
Author
Owner

@feschber commented on GitHub (Jan 16, 2024):

fixed

<!-- gh-comment-id:1894326934 --> @feschber commented on GitHub (Jan 16, 2024): fixed
Author
Owner

@feschber commented on GitHub (Jan 16, 2024):

Have you thought about adding a daemon option to the GUI and/or a tray icon?

I initially had a (non functional) switch as a mockup and removed that. Technically I could add that back but that would break the "normal" way of running lan-mouse where the service is started as a child process and terminated when the gui exits. I also want to eventually implement the service functionality with the background / autostart portal which is probably more userfriendly, would work with flatkap and also would not require a toggle.

As for the system tray: I have not thought about it yet. I will add it to my list.

<!-- gh-comment-id:1894338251 --> @feschber commented on GitHub (Jan 16, 2024): > Have you thought about adding a daemon option to the GUI and/or a tray icon? I initially had a (non functional) switch as a mockup and removed that. Technically I could add that back but that would break the "normal" way of running lan-mouse where the service is started as a child process and terminated when the gui exits. I also want to eventually implement the service functionality with the [background / autostart portal](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Background.html) which is probably more userfriendly, would work with flatkap and also would not require a toggle. As for the system tray: I have not thought about it yet. I will add it to my list.
Author
Owner

@feschber commented on GitHub (Jan 16, 2024):

[Unit]
Description=Mouse & keyboard sharing via LAN
After=graphical-session.target

[Service]
ExecStart=/usr/bin/lan-mouse --daemon
Restart=on-failure

[Install]
WantedBy=graphical-session.target

Did some testing my self. The above seems to work for me. After=graphical-session.target must be specified as After, if it were Required it does not work (because lan-mouse would start at the same time).

<!-- gh-comment-id:1894561501 --> @feschber commented on GitHub (Jan 16, 2024): ```ini [Unit] Description=Mouse & keyboard sharing via LAN After=graphical-session.target [Service] ExecStart=/usr/bin/lan-mouse --daemon Restart=on-failure [Install] WantedBy=graphical-session.target ``` Did some testing my self. The above seems to work for me. `After=graphical-session.target` must be specified as `After`, if it were `Required` it does not work (because lan-mouse would start at the same time).
Author
Owner

@feschber commented on GitHub (Jan 16, 2024):

There was one final bug that prevented it from working (forgot to do an initial dns request ...)

<!-- gh-comment-id:1894679199 --> @feschber commented on GitHub (Jan 16, 2024): There was one final bug that prevented it from working (forgot to do an initial dns request ...)
Author
Owner

@CupricReki commented on GitHub (Jan 17, 2024):

Works perfectly for me with the activate_on_startup = true option in the config.

Much appreciated!

<!-- gh-comment-id:1894827138 --> @CupricReki commented on GitHub (Jan 17, 2024): Works perfectly for me with the `activate_on_startup = true` option in the config. Much appreciated!
Author
Owner

@feschber commented on GitHub (Jan 21, 2024):

If you want, you could update the AUR packages @CupricReki

<!-- gh-comment-id:1902747165 --> @feschber commented on GitHub (Jan 21, 2024): If you want, you could update the AUR packages @CupricReki
Author
Owner

@CupricReki commented on GitHub (Feb 17, 2024):

So I'm thinking, install the systemd unit but don't enable it.

<!-- gh-comment-id:1949580478 --> @CupricReki commented on GitHub (Feb 17, 2024): So I'm thinking, install the systemd unit but don't enable it.
Author
Owner

@feschber commented on GitHub (Feb 18, 2024):

Yeah, it should not be enabled by default. Especially since the Input Capture / Emulation popups show up every restart on e.g. Gnome Desktop.

<!-- gh-comment-id:1951056219 --> @feschber commented on GitHub (Feb 18, 2024): Yeah, it should not be enabled by default. Especially since the Input Capture / Emulation popups show up every restart on e.g. Gnome Desktop.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/lan-mouse#26
No description provided.