You are not logged in.
Pages: 1
Hi guys, I'm just wondering if there is any way that I could run a script on system suspend.
I already tried to make a file in /lib/systemd/system-sleep/ with this content (The lockscreen script is executable):
#!/bin/sh
if [ "${1}" == "pre" ]; then
sh /home/yan/.config/scripts/lockscreen
elif [ "${1}" == "post" ]; then
#Nothing
fiAnyone has any ideas, how can I do that??
Thanks for any kind of help.
Last edited by arch181 (2021-02-09 09:17:46)
Offline
Offline
Slithery
Can you please detail a bit because i think i tried everything that is written there maybe im doing something wrong idk...
I tried to make a suspend@.service file in /etc/systemd/system/ like this:
[Unit]
Description=User suspend actions
Before=suspend.target
[Service]
User=%I
ExecStart=/home/yan/.config/scripts/lockscreen
[Install]
WantedBy=suspend.targeti Started the service by typing sudo systemctl enable suspend@user rebooted the laptop and nothing worked.
I also tried to change my autostart.sh file in /usr/lib/systemd/system-sleep/ to see if it changes anything like this:
#!/bin/sh
case $1 in
pre/*)
/home/yan/.config/scripts/lockscreen
;;
post/*)
#Nothing
;;
esaAnd still nothing seems to work.
Last edited by arch181 (2021-02-08 21:13:13)
Offline
i Started the service by typing sudo systemctl enable suspend@user rebooted the laptop and nothing worked.
Your user has the login name user?
Offline
arch181 wrote:i Started the service by typing sudo systemctl enable suspend@user rebooted the laptop and nothing worked.
loqs
Your user has the login name user?
No, maybe that was the problrm that i need to change to my username??
Let me check and i'll be back
Offline
loqs
Still not working
Offline
Does the system journal the service started after you suspend the system?
Offline
loqs
Can you tell me please how can i do that or point me to any arch wiki that will give me the answer on how to check the journal?
Offline
Offline
loqs
I just found out that the new suspend service failed and this is the message systemctl status suspend@yan.service:
Loaded: loaded (/etc/systemd/system/suspend@.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2021-02-08 23:24:57 IST; 19min ago
Process: 1046 ExecStart=/home/yan/.config/i3/scripts/lockscreen (code=exited, status=1/FAILURE)
Main PID: 1046 (code=exited, status=1/FAILURE)
Feb 08 23:24:57 arch181 systemd[1]: Started User suspend actions.
Feb 08 23:24:57 arch181 lockscreen[1048]: i3lock: Could not connect to X11, maybe you need to set DISPLAY?
Feb 08 23:24:57 arch181 systemd[1]: suspend@yan.service: Main process exited, code=exited, status=1/FAILURE
Feb 08 23:24:57 arch181 systemd[1]: suspend@yan.service: Failed with result 'exit-code'.Last edited by arch181 (2021-02-08 21:47:57)
Offline
The first example from the wiki page used:
Environment=DISPLAY=:0Offline
i added Environment=DISPLAY=:0 to my suspend@.service file like this:
[Unit]
Description=User suspend actions
Before=suspend.target
[Service]
User=yan
Environment=DISPLAY=:0
ExecStart=/home/yan/.config/i3/scripts/lockscreen
[Install]
WantedBy=suspend.targetAnd it stopped failing but still the lockscreen script isnt executed.
Offline
The first example from the wiki page used:
Environment=DISPLAY=:0
loqs
already did that, i think im in the right path to get it working thanks ![]()
Last edited by arch181 (2021-02-08 22:24:08)
Offline
Updated status?
What makes you believe the script isn't executed when previously it ran but failed on the i3lock invocation because of the missing DISPLAY environment?
Do you still have/try the hook? Did you export the DISPLAY there as well?
Please also post the actual script.
Offline
Updated status?
What makes you believe the script isn't executed when previously it ran but failed on the i3lock invocation because of the missing DISPLAY environment?
Do you still have/try the hook? Did you export the DISPLAY there as well?Please also post the actual script.
seth
The script is the regular i3lock screen wrapped with another script that i got from github to costumaize the i3lock and it runs whenever i press the keybindings that have in the i3 config file.
Here is the script from github:
#!/bin/sh
B='#42424299' # blank
C='#42424299' # clear ish
D='#42424299' # default
T='#00838fB3' # text
W='#880000bb' # wrong
V='#424242' # verifying
/usr/bin/i3lock \
--insidevercolor=$C \
--ringvercolor=$V \
\
--insidewrongcolor=$C \
--ringwrongcolor=$W \
\
--insidecolor=$B \
--ringcolor=$D \
--linecolor=$B \
--separatorcolor=$D \
\
--verifcolor=$T \
--wrongcolor=$T \
--timecolor=$T \
--datecolor=$T \
--layoutcolor=$T \
--keyhlcolor=$W \
--bshlcolor=$W \
\
--screen 1 \
--blur 5 \
--clock \
--indicator \
--timestr="%H:%M:%S" \
--datestr="%A, %m %Y" \
#--keylayout 1 \
# --veriftext="Drinking verification can..."
# --wrongtext="Nope!"
# --textsize=20
# --modsize=10
# --timefont=comic-sans
# --datefont=monofur
# etcHere is my suspend@.service file:
[Unit]
Description=User suspend actions
Before=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
[Service]
User=yan
Environment=DISPLAY=:0
ExecStart=/home/yan/.config/i3/scripts/lockscreen
[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.targetNote: right now I have no fails in the systemctl services and whenever I suspend the laptop then wake it up the script gets executed and the lockscreen is displayed for like 1 second but after that it disappears and im automatically loged in.
Last edited by arch181 (2021-02-09 08:26:26)
Offline
That doesn't fork and you're also using the wrong "Before", see eg. https://www.jvt.me/posts/2019/12/03/loc … d-systemd/
Offline
That doesn't fork and you're also using the wrong "Before", see eg. https://www.jvt.me/posts/2019/12/03/loc … d-systemd/
seth
Thanks, really appreciate it. Everything is working perfect.
So here is my lock_suspend@.service file in /etc/systemd/system/ :
[Unit]
Description=i3lock screen after suspend
Before=suspend.target sleep.target
[Service]
User=yan
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/yan/.config/i3/scripts/lockscreen
[Install]
WantedBy=suspend.target sleep.targetAnd i just enabled it by typing sudo systemctl enable lock_suspend@yan, then i rebooted and suspended the laptop and it worked. Thank you ![]()
Offline
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Offline
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
seth
Done
Last edited by arch181 (2021-02-09 09:19:23)
Offline
Pages: 1