On Sun, 13 Aug 2023 22:12:23 +0100 Patrick O'Callaghan wrote:

> On Sun, 2023-08-13 at 18:49 +0200, francis.montag...@inria.fr wrote:
>> ExecStart=/bin/bash -c '/usr/sbin/swapon /SWAP/swapfile && /usr/sbin/swapoff 
>> /dev/zram0'

> I'll do that, but I don't understand why it sometimes works and
> sometimes doesn't.

The journal when it succeeds shows that /SWAP/swapfile was activated. That may
be due to hibernate-resume.service previously failed or was not called.

In addition swapon fails when the swapfile is already activated. A better
hibernate-preparation.service would be:

  ExecStart=/bin/bash -c ' \
      if ! swapon --show=NAME --noheadings | grep -q /SWAP/swapfile; then \
          swapon /SWAP/swapfile || exit; \
      fi; \
      swapoff /dev/zram0; \
      # Ignores the exit code of swapoff.
      exit 0; \
  '

To improve if needed to check also if /dev/zram0 is validated or not.

Note that systemd concatenates the lines ending with \ to a single line.
This make mandatory to end each bash commands, even the if, by ;

-- 
francis.montag...@inria.fr, DSI-SP, Tel: (33) 04 92 38 79 11, Bur: C111
INRIA Sophia, 2004, route des Lucioles - BP 93 06902 Sophia Antipolis Cedex
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to