[systemd-devel] How to create a systemd service?
Mantas Mikulėnas
grawity at gmail.com
Tue Dec 16 22:18:59 PST 2014
On Wed, Dec 17, 2014 at 4:34 AM, jenia.ivlev <jenia.ivlev at gmail.com> wrote:
>
> Hello.
>
> I want to start synapse (its a program that allows to run programs more
> easily) at login using systemd. So I created this systemd-service config
> file:
>
> [Unit]
> Description=Syanpse start up
> After=lxdm.service
>
> [Service]
> User=jenia
> ExecStart=/usr/bin/synapse
>
> [Install]
> WantedBy=multi-user.target
>
> I doesnt work neither automatically, nor by calling
> /usr/lib/systemd/system/synapse.service as so:
> systemctl start synapse
>
I see that Synapse is an X11 program, gtk-based. The system service
manager, whether it was systemd or another init, is not suitable for this
because it has no knowledge about the X11 sessions that might be active.
(Indeed, "After=lxdm.service" won't actually make it start _at login_, but
at the time the welcome screen shows up.)
<tldr>
Remember that by design there can be zero or several people running their
own X11 servers at once; programs therefore need to know environment
variables like $DISPLAY (and several others) to choose the right one.
That's why you get this:
> Dec 16 21:23:11 station1 synapse[8545]: [02:23:11.040620 Gtk-Warning]
> cannot open display:
>
Setting these variables statically in your .service would be a poor idea
since they can change (some of them _do_ change every time lxdm starts),
not to mention being exactly the kind of ugly hack that systemd tries to
avoid.
(And while systemd _is_ trying to eventually reach the point where simply
setting User= should be enough to discover all such information, it still
wouldn't help you, because your service still starts together with lxdm,
_before_ you actually log in.)
</tldr>
For now, it will be easiest to start such services from your desktop
environment, as it already runs inside your graphical login and therefore
knows all the necessary settings.
Whether you use GNOME or Enlightenment or LXDE or a custom-built
environment on top of a tiny tiling WM, they all have ways to autostart
programs. Most of them support the XDG Autostart
<http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html>
specification. Put this in ~/.config/autostart/synapse.desktop:
[Desktop Entry]
Type=Application
Name=Synapse
Exec=/usr/bin/synapse
--
Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20141217/2b876b0a/attachment-0001.html>
More information about the systemd-devel
mailing list