services: Reorganize services, detect X

Detect X autostart a bit better with a separate service. The service
relies on a shell script which searches for a socket which X creates on
startup and only finishes when it finds the socket succesfully.

This makes services which need X to start successfully a bit more
robust, and while it can still break if X takes too long, it should be
more stable now.

Finally, services can restart more quickly when ended since they don't
require the 2+ `RestartSec` option to be present anymore to successfully
start.
This commit is contained in:
Marty Oehme 2020-09-24 16:24:42 +02:00
parent 3fa7f8a6db
commit 7bee413323
Signed by: Marty
GPG key ID: B7538B8F50A1C800
24 changed files with 145 additions and 11 deletions

View file

@ -0,0 +1 @@
../x-started-confirm.service

View file

@ -0,0 +1,8 @@
[Unit]
Description=GnuPG network certificate management daemon
Documentation=man:dirmngr(8)
Requires=dirmngr.socket
[Service]
ExecStart=/usr/bin/dirmngr --supervised
ExecReload=/usr/bin/gpgconf --reload dirmngr

View file

@ -0,0 +1,11 @@
[Unit]
Description=GnuPG network certificate management daemon
Documentation=man:dirmngr(8)
[Socket]
ListenStream=%t/gnupg/S.dirmngr
SocketMode=0600
DirectoryMode=0700
[Install]
WantedBy=sockets.target

View file

@ -1,13 +1,13 @@
[Unit]
Description=Alacritty window hidden on i3 scratchpad
After=display-manager.service
Requires=x-started-confirm.service
After=x-started-confirm.service
[Service]
Type=simple
# workaround to allow relative executable invocation (i.e. current users' home dir)
ExecStart=/bin/bash -c 'alacritty --title "dropdown-terminal" --class Alacritty,scratchpad'
Restart=always
RestartSec=2
[Install]
WantedBy=default.target

View file

@ -1,13 +1,13 @@
[Unit]
Description=Todo.md floating vim instance
After=display-manager.service
Requires=x-started-confirm.service
After=x-started-confirm.service
[Service]
Type=simple
# workaround to allow relative executable invocation (i.e. current users' home dir)
ExecStart=/bin/bash -c 'alacritty --title "dropdown-todo" --class "Alacritty,scratchpad" -e nvim -c ":set nonumber norelativenumber noshowmode noruler laststatus=0 noshowcmd shortmess=F | :Limelight" %h/documents/records/todo.md'
Restart=always
RestartSec=2
[Install]
WantedBy=default.target

View file

@ -1,12 +1,12 @@
[Unit]
Description=Perform windows animations on focus
PartOf=graphical-session.target
After=graphical-session.target
Requires=x-started-confirm.service
After=x-started-confirm.service
[Service]
ExecStart=/usr/bin/flashfocus
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target

View file

@ -0,0 +1,13 @@
[Unit]
Description=GnuPG cryptographic agent and passphrase cache (access for web browsers)
Documentation=man:gpg-agent(1)
[Socket]
ListenStream=%t/gnupg/S.gpg-agent.browser
FileDescriptorName=browser
Service=gpg-agent.service
SocketMode=0600
DirectoryMode=0700
[Install]
WantedBy=sockets.target

View file

@ -0,0 +1,13 @@
[Unit]
Description=GnuPG cryptographic agent and passphrase cache (restricted)
Documentation=man:gpg-agent(1)
[Socket]
ListenStream=%t/gnupg/S.gpg-agent.extra
FileDescriptorName=extra
Service=gpg-agent.service
SocketMode=0600
DirectoryMode=0700
[Install]
WantedBy=sockets.target

View file

@ -0,0 +1,13 @@
[Unit]
Description=GnuPG cryptographic agent (ssh-agent emulation)
Documentation=man:gpg-agent(1) man:ssh-add(1) man:ssh-agent(1) man:ssh(1)
[Socket]
ListenStream=%t/gnupg/S.gpg-agent.ssh
FileDescriptorName=ssh
Service=gpg-agent.service
SocketMode=0600
DirectoryMode=0700
[Install]
WantedBy=sockets.target

View file

@ -0,0 +1,8 @@
[Unit]
Description=GnuPG cryptographic agent and passphrase cache
Documentation=man:gpg-agent(1)
Requires=gpg-agent.socket
[Service]
ExecStart=/usr/bin/gpg-agent --supervised
ExecReload=/usr/bin/gpgconf --reload gpg-agent

View file

@ -0,0 +1,12 @@
[Unit]
Description=GnuPG cryptographic agent and passphrase cache
Documentation=man:gpg-agent(1)
[Socket]
ListenStream=%t/gnupg/S.gpg-agent
FileDescriptorName=std
SocketMode=0600
DirectoryMode=0700
[Install]
WantedBy=sockets.target

View file

@ -1 +0,0 @@
/home/marty/.config/systemd/user/flashfocus.service

View file

@ -1,2 +1,3 @@
[Service]
RestartSec=5
[Unit]
Requires=x-started-confirm.service
After=x-started-confirm.service

View file

@ -0,0 +1,8 @@
[Unit]
Description=Mailbox synchronization service
Wants=network-online.target gpg-agent.socket
After=network.target network-online.target dbus.socket gpg-agent.socket
[Service]
Type=oneshot
ExecStart=/home/marty/.local/bin/mail-check

View file

@ -0,0 +1,10 @@
[Unit]
Description=Mailbox synchronization timer
[Timer]
OnBootSec=1m
OnUnitActiveSec=1h
Unit=mbsync.service
[Install]
WantedBy=timers.target

View file

@ -1,2 +1,3 @@
[Service]
RestartSec=10
[Unit]
Requires=x-started-confirm.service
After=x-started-confirm.service

View file

@ -0,0 +1 @@
../dirmngr.socket

View file

@ -0,0 +1 @@
../gpg-agent-browser.socket

View file

@ -0,0 +1 @@
../gpg-agent-extra.socket

View file

@ -0,0 +1 @@
../gpg-agent-ssh.socket

View file

@ -0,0 +1 @@
../gpg-agent.socket

View file

@ -0,0 +1 @@
../mbsync.timer

View file

@ -0,0 +1,10 @@
[Unit]
Description=Monitor status of X server start
[Service]
Type=oneshot
ExecStart=/bin/bash -c '%h/.local/share/services/x-started-confirm.sh'
RestartSec=2
[Install]
WantedBy=default.target

View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# from: https://superuser.com/questions/759759/writing-a-service-that-depends-on-xorg/1351489#1351489
COUNTER=0
while true; do
# Check whether or not socket exists
if [ -S /tmp/.X11-unix/X0 ]; then
exit 0
fi
((++COUNTER))
if [ $COUNTER -gt 20 ]; then
printf "X did not start in time\n"
exit 1
fi
printf "X not yet started, counter at %s\n" "$COUNTER"
sleep 1
done