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

Mint MATE autopoweroff.service is inactive (dead) on boot #26

Closed ktnlikeasmallcat closed 2 years ago

ktnlikeasmallcat commented 2 years ago

I use autopoweroff as a failsafe to shut down my laptop to conserve battery power on the road. It hasn't been powering it off for some time, and I can't seem to figure out why. systemctl status autopoweroff.service shows the following after a fresh reboot, asked both before and after idle time:

autopoweroff.service - LSB: Start daemon at boot time
     Loaded: loaded (/etc/init.d/autopoweroff; generated)
     Active: inactive (dead)
       Docs: man:systemd-sysv-generator(8)

I can manually do systemctl start autopoweroff, and that seems to work, but I reboot a lot and doing that after every boot is cumbersome and systemctl enable autopoweroff returns:

autopoweroff.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable autopoweroff
update-rc.d: error: no runlevel symlinks to modify, aborting!

I've tried with and without gui installed.

Both /etc/autopoweroff/autopoweroff.conf and /etc/autopoweroff.conf are identical to the example config, except I've made these changes in both:

[NO_ACTION_TIME_RANGE]
StartHour=0
EndHour=0

[TIMEOUTS]
StartupDelay=5
IdleTime=10

[ACTION]
Action=Shutdown
ActionCommand=None

I am running Linux Mint MATE Uma 20.2 x86_64 Kernel: 5.4.0-91-generic, using autopoweroff 4.0.0 from the deb package.

Here's /var/log/autopoweroff.log: autopoweroff.log

Is there any information I can give to help figure out why APO isn't doing the expected behavior?

ktnlikeasmallcat commented 2 years ago

Small update: I've been looking into the sysv error and tried update-rc.d autopoweroff enable which gave

Failed to enable unit: Unit /run/systemd/generator.late/autopoweroff.service is transient or generated.

Does autopoweroff need System V to tell it to run? I might be barking up the wrong tree.

I have /etc/init.d/autopoweroff that reads:

   1 #!/bin/bash
   2 
   3 # Autopoweroff init script.
   4 #
   5 # For further information on guides on how to write init scripts, see:
   6 #
   7 #   http://wiki.debian.org/LSBInitScripts
   8 #   http://www.debian.org/doc/debian-policy/ch-opersys.html
   9 
  10 ### BEGIN INIT INFO
  11 # Provides:          autopoweroff
  12 # Required-Start:    $local_fs $syslog
  13 # Required-Stop:     $local_fs $syslog
  14 # Default-Start:     2 3 4 5
  15 # Default-Stop:      0 1 6
  16 # Short-Description: Start daemon at boot time
  17 # Description:       Autopoweroff init script
  18 ### END INIT INFO
  19 
  20 
  21 test -f /lib/lsb/init-functions || exit 1
  22 . /lib/lsb/init-functions
  23 
  24 logfile="/var/log/autopoweroff.log"
  25 
  26 start()
  27 {
  28   log_begin_msg "Starting Autopoweroff..."
  29   start_daemon /usr/sbin/autopoweroffd >>${logfile} 2>&1
  30   log_end_msg $?
  31 }
  32 
  33 stop()
  34 {
  35   log_begin_msg "Stopping Autopoweroff..."
  36   killproc -p /var/run/autopoweroff/autopoweroff.pid autopoweroffd
  37   log_end_msg $?
  38 }
  39 
  40 
  41 case "$1" in
  42   start)          start;;
  43   stop)           stop;;
  44   restart)        stop; start;;
  45   reload)         stop; start;;
  46   force-reload)   stop; start;;
  47   *)              cat <<EOM
  48 Usage: $0 {start|stop|restart|reload|force-reload}
  49 Note:  reload and force-reload actually call restart.
  50 EOM
  51 ;;
  52 esac

The closest thing to /etc/rc.d/init.d/ is the following links to the above file:

/etc/rc0.d/K01autopoweroff 
/etc/rc1.d/K01autopoweroff 
/etc/rc2.d/S01autopoweroff 
/etc/rc3.d/S01autopoweroff 
/etc/rc4.d/S01autopoweroff 
/etc/rc5.d/S01autopoweroff 
/etc/rc6.d/K01autopoweroff

Are these the runlevel symlinks mentioned in that error?


On a different note, I'd add systemctl start autopoweroff to my startup applications as a stopgap, but it asks for a password, and I haven't been able to figure out what to write (using visudo) after ALL=(ALL) NOPASSWD in the file in sudoers.d.

deragon commented 2 years ago

Ugh... Autopoweroff needs to move one to systemd.... Unfortunately, at this moment, my personal life is full and I have no time for Autopoweroff, to my regret. Maybe during the holidays, I will attempt to work on it.

Obviously, something is different in your system. Autopoweroff's boot system used to work and still does in Ubuntu 20.04 LTS. Now, it is possible that the standard changed and on newer system, the System V booting system require different configuration. I do not know.

ktnlikeasmallcat commented 2 years ago

I put sudo systemctl start autopoweroff in my startup applications with a 60 second delay, and it doesn't prompt for a password (Mabye there's some keyring stuff going on?). This works as a stopgap for now.

ktnlikeasmallcat commented 2 years ago

New thing: No idea when this started but systemctl status autopoweroff.service now returns:

autopoweroff.service - LSB: Start daemon at boot time
     Loaded: loaded (/etc/init.d/autopoweroff; generated)
     Active: active (exited) since Fri 2021-12-31 12:17:03 PST; 7h ago
       Docs: man:systemd-sysv-generator(8)
    Process: 656 ExecStart=/etc/init.d/autopoweroff start (code=exited, status=0/SUCCESS)

Warning: journal has been rotated since unit was started, output may be incomplete.
~
~
deragon commented 2 years ago

Taking 1 minute to reread this bug report, is autopoweroff enabled in systemd?

$ sudo systemctl list-unit-files | fgrep autopoweroff
autopoweroff.service                                  generated       enabled     

If not, run:

$ sudo systemctl enable autopoweroff.service

and remove your stopgap. Autopoweroff should then start at bootup.

ktnlikeasmallcat commented 2 years ago

On a fresh install after reboot sudo systemctl list-unit-files | fgrep autopoweroff shows

autopoweroff.service
generated       enabled

and systemctl status autopoweroff.service returns

● autopoweroff.service - LSB: Start daemon at boot time
     Loaded: loaded (/etc/init.d/autopoweroff; generated)
     Active: active (running) since Mon 2022-01-03 12:49:55 PST; 3min 58s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 660 ExecStart=/etc/init.d/autopoweroff start (code=exited, status=0/SUCCESS)
      Tasks: 10 (limit: 3469)
     Memory: 15.7M
     CGroup: /system.slice/autopoweroff.service
             └─857 python3 /usr/sbin/autopoweroffd

Jan 03 12:49:50 ktn-CF-30 systemd[1]: Starting LSB: Start daemon at boot time...
Jan 03 12:49:52 ktn-CF-30 autopoweroff[660]:  * Starting Autopoweroff...
Jan 03 12:49:55 ktn-CF-30 autopoweroff[660]:    ...done.
Jan 03 12:49:55 ktn-CF-30 systemd[1]: Started LSB: Start daemon at boot time.
Jan 03 12:49:56 ktn-CF-30 autopoweroffd[857]: Autopoweroff started with PID '857'.
Jan 03 12:49:57 ktn-CF-30 autopoweroffd[857]: Reading configuration file:  /etc/autopoweroff/autopoweroff.conf
Jan 03 12:49:57 ktn-CF-30 autopoweroffd[857]: Command to execute when all conditions are met:  /sbin/shutdown -h now
Jan 03 12:49:57 ktn-CF-30 autopoweroffd[857]: Old alive:  ['server1', 'server2', 'server3']  Newly alive:  []  Newly dead:  ['server1', 'server3', 'server2']
Jan 03 12:50:00 ktn-CF-30 autopoweroffd[857]: Startup sleep of 5 minutes.

So it seems like this reinstall did the trick somehow. Thank you for your help.