Scheduling caffeine

Bug #1838901 reported by Chris Graham
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Caffeine
Fix Released
Undecided
Unassigned

Bug Description

I need to be able to prevent sleep during certain hours of the day, so that my Plex media player can work.

However:
1) caffeine doesn't support any clock-based scheduling options.
2) activating for a time period on Cron (e.g. 9am cronjob to caffeinate for 12 hours) doesn't seem to work, something inside Caffeine seems to be silently failing and the process doesn't stick. My Cron command is...
/usr/bin/caffeinate /usr/bin/sleep 13h &

I think if you can fix '2', you don't need to support '1'. But I've tried logging stdio and stderr to a file during Cron to see what's happening, and it's blank -- and nothing is inside my syslog except confirmation of the Cron command running without errors.

From personal experience I know Cron scripts can be problematic due to different environment variables and no PATH setting. Perhaps this is the cause.

description: updated
Revision history for this message
Reuben Thomas (rrt) wrote :

I suspect the problem is with caffeine getting access to the X server, though I'm a bit surprised that in that case it doesn't give an error. Have you tried setting `DISPLAY=:0` in your cron job's environment? See e.g. https://askubuntu.com/questions/471479/cannot-run-a-gui-app-from-cron

Revision history for this message
Chris Graham (chrisgraham) wrote :

Your suggestion works :). So if you can document this and give it a proper error message, I guess you can consider the issue fixed.

Revision history for this message
Reuben Thomas (rrt) wrote :

Thanks for confirming. I'll document this problem. But I already get an error:

$ unset DISPLAY
ecls 08:57:00 ~$ caffeine
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Traceback (most recent call last):
  File "/usr/bin/caffeine", line 38, in <module>
    ewmh = EWMH()
  File "/usr/lib/python3/dist-packages/ewmh/ewmh.py", line 50, in __init__
    self.display = _display or display.Display()
  File "/usr/lib/python3/dist-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/usr/lib/python3/dist-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/usr/lib/python3/dist-packages/Xlib/protocol/display.py", line 85, in __init__
    name, host, displayno, screenno = connect.get_display(display)
  File "/usr/lib/python3/dist-packages/Xlib/support/connect.py", line 72, in get_display
    return mod.get_display(display)
  File "/usr/lib/python3/dist-packages/Xlib/support/unix_connect.py", line 61, in get_display
    raise error.DisplayNameError(display)
Xlib.error.DisplayNameError: Bad display name ""

Revision history for this message
Reuben Thomas (rrt) wrote :

I've documented the problem and released 2.9.6. Thanks again!

Changed in caffeine:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.