You are not logged in.
Has anyone tried running a script before and after systemd session unit ?
I am trying to run a script that would fetch decryption keys from a key server and unlock home directory before the session and unmount the partition when session ends.
Last edited by coolgoose54 (2020-01-15 23:15:51)
Offline
ExecStartPre=, ExecStartPost=
...
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
How does one define ExecStartPre and ExecStartPost for session units ?
Offline
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
I am not sure what I am doing wrong.
[ ~]$ sudo cat /etc/systemd/system/user\@.service.d/override.conf
ExecStartPre=-/usr/bin/bash /etc/log.sh %i
ExecStartPort=-/usr/bin/bash /etc/log.sh %i
[ ~]$ sudo cat /etc/systemd/system/user\@service.service.d/override.conf
ExecStartPre=-/usr/bin/bash /etc/log.sh %i
[ ~]$ cat /etc/log.sh
#!/bin/bash
echo "" >> /tmp/pre.txt
date >> /tmp/pre.txt
env >> /tmp/pre.txt
ls /dev/mapper >> /tmp/pre.txt
echo "" >> /tmp/pre.txt
[~]$ sudo systemctl show 'user@service' | grep Exec
ExecMainStartTimestampMonotonic=0
ExecMainExitTimestampMonotonic=0
ExecMainPID=0
ExecMainCode=0
ExecMainStatus=0
ExecStart={ path=/usr/lib/systemd/systemd ; argv[]=/usr/lib/systemd/systemd --user ; ignore_errors=yes ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecStartEx={ path=/usr/lib/systemd/systemd ; argv[]=/usr/lib/systemd/systemd --user ; flags=ignore-failure ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
MemoryDenyWriteExecute=no
[ ~]$ sudo systemctl show 'user@.service' | grep Exec
Failed to get properties: Unit name user@.service is neither a valid invocation ID nor unit name.
[ ~]$ sudo systemctl daemon-reload
[ ~]$ sudo systemctl show 'user@service' | grep Exec
ExecMainStartTimestampMonotonic=0
ExecMainExitTimestampMonotonic=0
ExecMainPID=0
ExecMainCode=0
ExecMainStatus=0
ExecStart={ path=/usr/lib/systemd/systemd ; argv[]=/usr/lib/systemd/systemd --user ; ignore_errors=yes ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecStartEx={ path=/usr/lib/systemd/systemd ; argv[]=/usr/lib/systemd/systemd --user ; flags=ignore-failure ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
MemoryDenyWriteExecute=no
[ ~]$ sudo systemctl show 'user@.service' | grep Exec
Failed to get properties: Unit name user@.service is neither a valid invocation ID nor unit name.
And nothing gets logged to the log file if I login or logout.
Offline
[ ~]$ sudo cat /etc/systemd/system/user\@.service.d/override.conf ExecStartPre=-/usr/bin/bash /etc/log.sh %i ExecStartPort=-/usr/bin/bash /etc/log.sh %i [ ~]$ sudo cat /etc/systemd/system/user\@service.service.d/override.conf ExecStartPre=-/usr/bin/bash /etc/log.sh %i
You have one override for user@.service and one for user@service.service, you should delete the latter.
And I think you need to declare the relevant section in override.conf, like this:
[Service]
ExecStartPre=-/usr/bin/bash /etc/log.sh %i
ExecStartPort=-/usr/bin/bash /etc/log.sh %i
[ ~]$ sudo systemctl show 'user@.service' | grep Exec Failed to get properties: Unit name user@.service is neither a valid invocation ID nor unit name.
Try
systemctl cat user@.service
Offline
And I think you need to declare the relevant section in override.conf, like this:
[Service] ExecStartPre=-/usr/bin/bash /etc/log.sh %i ExecStartPort=-/usr/bin/bash /etc/log.sh %i
That works, thanks. I think was most likely the section declaration.
Offline
Fantastic, please mark the thread [SOLVED] for the benefit of others.
Offline