deragon / autopoweroff

Manage automatic poweroff and other actions (suspend / custom) when specific conditions are reunited.
GNU General Public License v2.0
52 stars 7 forks source link

seems not making server sleep on Ubuntu Server 18.04 #22

Closed ww2283 closed 2 years ago

ww2283 commented 3 years ago

I successfully installed .deb, but I monitored my server for several days and didn't notice it went into sleep mode. At least whenever I want to connect to it I can, and the fans are spinning. Is it because the headless server version of Ubuntu?

deragon commented 3 years ago

Should work. Can you send me the logs of Autopoweroff (/var/log/autopoweroff.log)? You may want to edit that file for any sensitive data (like hostnames) before sending it here though.

ww2283 commented 3 years ago

Sorry for the delay! here it is:

2021-08-20 18:40:17,006 - Autopoweroff - INFO - 鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲 2021-08-20 18:40:17,009 - Autopoweroff - INFO - Autopoweroff started with PID '32002'. 2021-08-20 18:40:17,009 - Autopoweroff - INFO - Logging configuration file used: /etc/autopoweroff/autopoweroff-logging.conf 2021-08-20 18:40:17,010 - Autopoweroff - INFO - Reading configuration file: /etc/autopoweroff/autopoweroff.conf 2021-08-20 18:40:17,010 - Autopoweroff - INFO - Command to execute when all conditions are met: echo -n mem >/sys/power/state 2021-08-20 18:40:17,012 - apo.observer.hosts.alive - INFO - Initializing. 2021-08-20 18:40:17,013 - apo.observer.hosts.alive - INFO - ApoObserverHostsAlive.run(): Check on [] started. 2021-08-20 18:40:17,013 - apo.observer.noaction.timerange - INFO - ApoObserverNoActionTimeRange.run(): started. 2021-08-22 11:53:34,911 - Autopoweroff - INFO - Ending. Traceback (most recent call last): File "/usr/sbin/autopoweroffd", line 164, in import ApoObserverResources File "/usr/share/python/modules/ApoObserverResources.py", line 4, in import psutil ModuleNotFoundError: No module named 'psutil' Exception ignored in: <module 'threading' from '/usr/lib/python3.6/threading.py'> Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 1294, in _shutdown t.join() File "/usr/lib/python3.6/threading.py", line 1056, in join self._wait_for_tstate_lock() File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock elif lock.acquire(block, timeout): File "/usr/sbin/autopoweroffd", line 95, in sigtermHandler sys.exit(0) SystemExit: 0

tjmcewan commented 3 years ago

I'm also having this same issue on Ubuntu 18.04 LTS. I believe I've finally got it configured correctly, but it's still not actually shutting down.

Here's the config:

[NO_ACTION_TIME_RANGE]
StartHour=0
EndHour=0
[TIMEOUTS]
StartupDelay=5
IdleTime=1
[DEPENDANTS]
Hosts=
[RESOURCES]
CpuPercentage=2
[ACTION]
Action=shutdown
ActionCommand=None

Here's the most recent section of the log:

2021-09-16 11:07:56,053 - Autopoweroff - INFO - ══════════════════════════════════════════════════════════
2021-09-16 11:07:56,056 - Autopoweroff - INFO - Autopoweroff started with PID '3054'.
2021-09-16 11:07:56,056 - Autopoweroff - INFO - Logging configuration file used:  /etc/autopoweroff/autopoweroff-logging.conf
2021-09-16 11:07:56,057 - Autopoweroff - INFO - Reading configuration file:  /etc/autopoweroff/autopoweroff.conf
2021-09-16 11:07:56,057 - Autopoweroff - INFO - Command to execute when all conditions are met:  /sbin/shutdown -h now
2021-09-16 11:07:56,058 - apo.observer.hosts.alive - INFO - Initializing.
2021-09-16 11:07:56,058 - apo.observer.hosts.alive - INFO - ApoObserverHostsAlive.run():  Check on [] started.
2021-09-16 11:07:56,059 - apo.observer.noaction.timerange - INFO - ApoObserverNoActionTimeRange.run():  started.

The use case is that we have large, expensive (12xl) EC2 instances for ad hoc data processing & we keep accidentally leaving them on. I want the server to automatically shut down once the processing is done. There's negligible activity & no one is logged in (will active SSH sessions prevent shutdown?), so I'd be expecting it to shut down.

I do also see that psutil error, but it appears to only happen when I restart the service.

2021-09-16 12:03:43,679 - Autopoweroff - INFO - Ending.
Traceback (most recent call last):
  File "/usr/sbin/autopoweroffd", line 164, in <module>
    import ApoObserverResources
  File "/usr/share/python/modules/ApoObserverResources.py", line 4, in <module>
    import psutil
ModuleNotFoundError: No module named 'psutil'
Exception ignored in: <module 'threading' from '/usr/lib/python3.6/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 1294, in _shutdown
    t.join()
  File "/usr/lib/python3.6/threading.py", line 1056, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
  File "/usr/sbin/autopoweroffd", line 95, in sigtermHandler
    sys.exit(0)
SystemExit: 0

How can I get the server to shutdown please? 🙏🏻

deragon commented 2 years ago

Argh... Sorry for the sooo late response...

psutil is missing as a dependency....

As a workaround, please run:

sudo apt install python3-psutil
deragon commented 2 years ago

Greetings @tjmcewan and @ww2283. With python3-psutil installed, is the problem resolved?

ww2283 commented 2 years ago

Dear Hans,

It worked on my end! Thanks for checking!

Regards, Wei On Mar 3, 2022, 13:49 -0500, Hans Deragon @.***>, wrote:

Greetings @tjmcewan and @ww2283. With python3-psutil installed, is the problem resolved? — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

deragon commented 2 years ago

Fixed with commit 1f5ab7f5cc16556ecd98347d804cca35a23b3210.