</listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>HibernateOnACPower=</varname></term>
+
+ <listitem>
+ <para>Whether to allow hibernation when the system has AC power. Only used by
+ <citerefentry><refentrytitle>systemd-suspend-then-hibernate.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ when <varname>HibernateDelaySec=</varname> is set.</para>
+
+ <para>If this option is disabled, the countdown of <varname>HibernateDelaySec=</varname> starts only
+ after AC power is disconnected, keeping the system in the suspend state otherwise.</para>
+
+ <para>This option is only effective on systems with a battery.</para>
+
+ <xi:include href="version-info.xml" xpointer="v257"/>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><varname>SuspendEstimationSec=</varname></term>
return log_oom();
*sc = (SleepConfig) {
- .hibernate_delay_usec = USEC_INFINITY,
+ .hibernate_delay_usec = USEC_INFINITY,
+ .hibernate_on_ac_power = true,
};
const ConfigTableItem items[] = {
{ "Sleep", "MemorySleepMode", config_parse_sleep_mode, 0, &sc->mem_modes },
{ "Sleep", "HibernateDelaySec", config_parse_sec, 0, &sc->hibernate_delay_usec },
+ { "Sleep", "HibernateOnACPower", config_parse_bool, 0, &sc->hibernate_on_ac_power },
{ "Sleep", "SuspendEstimationSec", config_parse_sec, 0, &sc->suspend_estimation_usec },
{}
};
char **mem_modes; /* /sys/power/mem_sleep */
usec_t hibernate_delay_usec;
+ bool hibernate_on_ac_power;
usec_t suspend_estimation_usec;
} SleepConfig;
}
}
- /* Do not suspend more than HibernateDelaySec= */
+ /* Do not suspend more than HibernateDelaySec= unless HibernateOnACPower=no and currently on AC power */
+ if (!sleep_config->hibernate_on_ac_power) {
+ /* Do not allow "decay" to suspend if the system has no battery. */
+ if (hashmap_isempty(last_capacity))
+ log_once(LOG_WARNING, "HibernateOnACPower=no was ignored because the system does not have a battery.");
+ else if (on_ac_power() > 0)
+ hibernate_timestamp = usec_add(now(CLOCK_BOOTTIME), sleep_config->hibernate_delay_usec);
+ }
+
usec_t before_timestamp = now(CLOCK_BOOTTIME);
suspend_interval = MIN(suspend_interval, usec_sub_unsigned(hibernate_timestamp, before_timestamp));
if (suspend_interval <= 0)
#HibernateMode=platform shutdown
#MemorySleepMode=
#HibernateDelaySec=
+#HibernateOnACPower=yes
#SuspendEstimationSec=60min