1

Similar issue to this post: Writing a systemd service to be executed at resume

I have a service that I want executed when the computer wakes from sleep. Here is the service:

[Unit]
Description=User resume actions - reload nightlight state
After=systemd-suspend.service
After=systemd-hibernate.service
After=systemd-suspend-then-hibernate.service

[Service]
Type=oneshot
# debugging for now
ExecStart=/usr/bin/bash -c 'date >> /home/alex/repos/scripts/log.txt'

[Install]
WantedBy=systemd-suspend.service
WantedBy=systemd-hibernate.service
WantedBy=systemd-suspend-then-hibernate.service

It is installed and works correctly if I manually execute sudo systemctl start nightlight.service. This service is almost identical to nvidia-resume.service, which was installed by my distro:

[Unit]
Description=NVIDIA system resume actions
After=systemd-suspend.service
After=systemd-hibernate.service
After=systemd-suspend-then-hibernate.service

[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t suspend -s "nvidia-resume.service"
ExecStart=/usr/bin/nvidia-sleep.sh "resume"

[Install]
WantedBy=systemd-suspend.service
WantedBy=systemd-hibernate.service
WantedBy=systemd-suspend-then-hibernate.service

Yet nightlight.service does not start on resume, but the nvidia service does. Why?

I can see this in journalctl -xeu nvidia-resume.service:

...
Nov 22 02:28:05 alex-z690mitxax systemd[1]: Starting nvidia-resume.service - NVIDIA system resume actions...
░░ Subject: A start job for unit nvidia-resume.service has begun execution
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit nvidia-resume.service has begun execution.
░░ 
░░ The job identifier is 11570.
Nov 22 02:28:05 alex-z690mitxax suspend[62410]: nvidia-resume.service
Nov 22 02:28:05 alex-z690mitxax logger[62410]: <13>Nov 22 02:28:05 suspend: nvidia-resume.service
Nov 22 02:28:05 alex-z690mitxax systemd[1]: nvidia-resume.service: Deactivated successfully.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit nvidia-resume.service has successfully entered the 'dead' state.
Nov 22 02:28:05 alex-z690mitxax systemd[1]: Finished nvidia-resume.service - NVIDIA system resume actions.
░░ Subject: A start job for unit nvidia-resume.service has finished successfully
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit nvidia-resume.service has finished successfully.
░░ 
░░ The job identifier is 11570.

When I run journalctl -xeu nightlight.service, my service did not start.

Here's the systemctl status nightlight.service (ignore the failed runs at 2:26 - I was messing with the unit file. The system suspended and resumed from suspend at 2:28):

sudo systemctl status nightlight.service
○ nightlight.service - User resume actions - reload nightlight state
     Loaded: loaded (/etc/systemd/system/nightlight.service; linked; preset: enabled)
     Active: inactive (dead)

Nov 22 02:25:28 alex-z690mitxax bash[59845]: /usr/bin/bash: line 1: /root/repos/scripts/log.txt: No such file or directory
Nov 22 02:25:28 alex-z690mitxax systemd[1]: nightlight.service: Main process exited, code=exited, status=1/FAILURE
Nov 22 02:25:28 alex-z690mitxax systemd[1]: nightlight.service: Failed with result 'exit-code'.
Nov 22 02:25:28 alex-z690mitxax systemd[1]: Failed to start nightlight.service - User resume actions - reload nightlight state.
Nov 22 02:26:13 alex-z690mitxax systemd[1]: Starting nightlight.service - User resume actions - reload nightlight state...
Nov 22 02:26:13 alex-z690mitxax systemd[1]: nightlight.service: Deactivated successfully.
Nov 22 02:26:13 alex-z690mitxax systemd[1]: Finished nightlight.service - User resume actions - reload nightlight state.
Nov 22 02:36:54 alex-z690mitxax systemd[1]: Starting nightlight.service - User resume actions - reload nightlight state...
Nov 22 02:36:54 alex-z690mitxax systemd[1]: nightlight.service: Deactivated successfully.
Nov 22 02:36:54 alex-z690mitxax systemd[1]: Finished nightlight.service - User resume actions - reload nightlight state.

and nvidia-resume.service:

○ nvidia-resume.service - NVIDIA system resume actions
     Loaded: loaded (/usr/lib/systemd/system/nvidia-resume.service; enabled; preset: enabled)
     Active: inactive (dead) since Sat 2025-11-22 02:28:05 PST; 13min ago
   Main PID: 62415 (code=exited, status=0/SUCCESS)
        CPU: 5ms

Nov 22 02:28:05 alex-z690mitxax systemd[1]: Starting nvidia-resume.service - NVIDIA system resume actions...
Nov 22 02:28:05 alex-z690mitxax suspend[62410]: nvidia-resume.service
Nov 22 02:28:05 alex-z690mitxax logger[62410]: <13>Nov 22 02:28:05 suspend: nvidia-resume.service
Nov 22 02:28:05 alex-z690mitxax systemd[1]: nvidia-resume.service: Deactivated successfully.
Nov 22 02:28:05 alex-z690mitxax systemd[1]: Finished nvidia-resume.service - NVIDIA system resume actions.
4
  • unix.stackexchange.com/questions/271541/… ? Commented Nov 22 at 14:32
  • 1
    Nov 22 02:25:28 alex-z690mitxax bash[59845]: /usr/bin/bash: line 1: /root/repos/scripts/log.txt: No such file or directory ... something in the logs doesn't gel with the supposed unit file ... /root != /home/alex Commented Nov 22 at 19:24
  • That was me messing with the unit file. Ignore the failed runs at 2:26. Commented Nov 23 at 6:09
  • > unix.stackexchange.com/questions/271541/… That worked. Thanks! Commented Nov 23 at 6:16

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.