Neue Unit für systemd erstellen

Dieses Forum dient der grundlegenden Hilfe und Unterstützung :

Stelle hier Deine Fragen zur Grundinstallation und zur Benutzung von Mageia. Beispielsweise gehören hierhin Fragen zum Download der ISOs und deren Installation, zur Einrichtung des Druckers, Benutzung der Textbearbeitung, usw.

Bitte versuche, Deine Fragen im richtigen Subforum zu stellen und gib dabei so viele Informtionen wie möglich. Je präziser die Frage gestellt wird, um so eher bekommst Du eine hilfreiche Antwort.

Neue Unit für systemd erstellen

Beitragvon Diddi » Jul 3rd, '15, 17:40

Liebe Mitmagier,

da ich neben meiner Mageia 4.1 Installation noch eine Partition mit Windows habe und ich in Mageia stets den Tiefschlaf-Modus anstatt des Herunterfahrens verwende, gibt es regelmäßig Probleme, wenn ich also Mageia in den Tiefschlaf versetze und am nächsten Tag Windows starte, denn beim Tiefschlaf wird die Partition nicht ausgehängt.
Daher habe ich folgende Unit für systemd geschrieben:
Code: Alles auswählen
/etc/systemd/system/unmount-windows.service
-------------------------------------

[Unit]
Description=Un- and remount NTFS file system at sleep
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/usr/bin/umount /mnt/windows; /usr/bin/touch /root/unmount.debug
ExecStop=-/usr/bin/mount /mnt/windows; /usr/bin/touch /root/remount.debug

[Install]
WantedBy=sleep.target

Diese Datei mit zusätzlichen touch-Kommandos zu Debug-Zwecken habe ich weitgehend von https://wiki.archlinux.org/index.php/Power_management übernommen.
Anschließend habe ich folgende Befehle ausgeführt:
Code: Alles auswählen
systemctl enable unmount-windows.service
systemctl daemon-reload

Nach zahlreichen hibernates und anschließendem Hochfahren habe ich festgestellt, daß nie eines der angegebenen Kommandos unter ExecStart und ExecStop ausgeführt wird. Wer weiß Abhilfe?

Wenn ich systemctl --all aufrufe erhalte ich übrigens
Code: Alles auswählen
...
unmount-windows.service                                  loaded    inactive dead      Un- and remount NTFS file system at sleep
...
hibernate.target                                         loaded    active   active    Hibernate
...
sleep.target                                             loaded    inactive dead      Sleep
...

Muß bei unmount-windows.serviec etwa "active" stehen, obwohl die Unit während des normalen Betriebs ja nich laufen soll?

Beste Grüße
Diddi
Diddi
 
Beiträge: 43
Registriert: Jan 16th, '12, 22:44

Re: Neue Unit für systemd erstellen

Beitragvon doktor5000 » Jul 3rd, '15, 18:04

Zeig doch mal die Ausgabe von
Code: Alles auswählen
systemctl -al status unmount-windows.service


Ich vermute es liegt am Exit-code und dem Befehl den du ausführen willst.
man systemd.service hat geschrieben:ExecStart=
Commands with their arguments that are executed when this service is started. The value is split into zero or more command lines is according to the rules described below (see section "Command Lines" below).

When Type is not oneshot, only one command may and must be given. When Type=oneshot is used, zero or more commands may be specified. This can be specified by providing multiple command lines in the same directive, or alternatively, this directive may be specified more than once with the same effect. If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect. If no ExecStart= is specified, then the service must have RemainAfterExit=yes set.

For each of the specified commands, the first argument must be an absolute path to an executable. Optionally, if this file name is prefixed with "@", the second token will be passed as "argv[0]" to the executed process, followed by the further arguments specified. If the absolute filename is prefixed with "-", an exit code of the command normally considered a failure (i.e. non-zero exit status or abnormal exit due to signal) is ignored and considered success. If both "-" and "@" are used, they can appear in either order.

If more than one command is specified, the commands are invoked sequentially in the order they appear in the unit file. If one of the commands fails (and is not prefixed with "-"), other lines are not executed, and the unit is considered failed.

Unless Type=forking is set, the process started via this command line will be considered the main process of the daemon.

Das heißt egal ob der Befehl erfolgreich ausgeführt wird oder nicht, das ist dem Dienst egal.
Ich bin nicht böse, sondern nur ehrlich. Und wer lesen kann, ist klar im Vorteil.
----
Mageia - the magic continues
Benutzeravatar
doktor5000
 
Beiträge: 6055
Registriert: Jun 2nd, '11, 09:39

Re: Neue Unit für systemd erstellen

Beitragvon Diddi » Jul 6th, '15, 10:03

doktor5000 hat geschrieben:Zeig doch mal die Ausgabe von
Code: Alles auswählen
systemctl -al status unmount-windows.service


Danke, das hat mich schon mal auf die richtige Spur gebracht. Die Ausgabe hat gezeigt, daß das Semikolon nicht interpretiert wurde. ExecStart ist ja schließlich keine Shell. Ich habe nun doch zwei Units aus der Angelegenheit gemacht, das ist leichter zu überblicken:
Code: Alles auswählen
/etc/systemd/system/unmount-windows.service
-------------------------
[Unit]
Description=Unmount NTFS file system at sleep
Before=suspend.target hibernate.target hybrid-sleep.target

[Service]
Type=simple
ExecStart=-/usr/bin/umount /mnt/windows

[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target

und
Code: Alles auswählen
/etc/systemd/system/remount-windows.service
-----------------------
[Unit]
Description=Remount NTFS file system after sleep
After=suspend.target hibernate.target hybrid-sleep.target

[Service]
Type=simple
ExecStart=/usr/bin/mount /mnt/windows

[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target

Das Minuszeichen in der ersten Datei ist übrigens Absicht, denn falls das Laufwerk schon ausgehängt ist, soll es keine Probleme geben. Könnte man aber auch weglassen.

Mit journalctl habe ich nachgewiesen, daß die Kommandos tatsächlich ausgeführt werden. Nun drückt der Schuh aber an anderer Stelle: Nach dem Hochfahren aus dem Tiefschlaf wird zwar eingehängt wie gewünscht, jedoch sofort wieder ein umount ausgeführt. Hier ist die Ausgabe von journalctl für den gesamten Vorgang vom Einfrieren bis zum Hochfahren des Systems:
Code: Alles auswählen
Jul 05 22:30:17 pc500 systemd-logind[780]: Delay lock is active but inhibitor timeout is reached.
Jul 05 22:30:17 pc500 systemd[1]: Starting Unmount NTFS file system at sleep...
Jul 05 22:30:17 pc500 systemd[1]: Started Unmount NTFS file system at sleep.
Jul 05 22:30:17 pc500 systemd[1]: Starting Sleep.
Jul 05 22:30:17 pc500 systemd[1]: Reached target Sleep.
Jul 05 22:30:17 pc500 systemd[1]: Starting Hibernate...
Jul 05 22:30:17 pc500 kernel: PM: Hibernation mode set to 'platform'
Jul 05 22:30:17 pc500 systemd-sleep[21597]: Suspending system...
Jul 05 22:30:17 pc500 ntfs-3g[21588]: Unmounting /dev/sda1 ()
Jul 05 22:31:20 pc500 kernel: PM: Syncing filesystems ... done.
Jul 05 22:31:20 pc500 kernel: Freezing user space processes ... (elapsed 0.004 seconds) done.
Jul 05 22:31:20 pc500 systemd[1]: Time has been changed
Jul 05 22:31:20 pc500 kernel: PM: Marking nosave pages: [mem 0x00091000-0x000fffff]
Jul 05 22:31:20 pc500 kernel: PM: Marking nosave pages: [mem 0xcfe90000-0xffffffff]
Jul 05 22:31:20 pc500 kernel: PM: Marking nosave pages: [mem 0xc4000000-0xc7ffffff]
Jul 05 22:31:20 pc500 kernel: PM: Basic memory bitmaps created
Jul 05 22:31:20 pc500 kernel: PM: Preallocating image memory... done (allocated 1197075 pages)
Jul 05 22:31:20 pc500 kernel: PM: Allocated 4788300 kbytes in 0.48 seconds (9975.62 MB/s)
Jul 05 22:31:20 pc500 kernel: Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
Jul 05 22:31:20 pc500 kernel: Suspending console(s) (use no_console_suspend to debug)
Jul 05 22:31:20 pc500 acpid[797]: client 879[0:0] has disconnected
Jul 05 22:31:20 pc500 acpid[797]: client connected from 879[0:0]
Jul 05 22:31:20 pc500 acpid[797]: 1 client rule loaded
Jul 05 22:31:20 pc500 systemd[2415]: Time has been changed
Jul 05 22:31:20 pc500 systemd-sleep[21597]: System resumed.
Jul 05 22:31:20 pc500 systemd[1]: Started Hibernate.
Jul 05 22:31:20 pc500 systemd[1]: Requested transaction contradicts existing jobs: File exists
Jul 05 22:31:20 pc500 systemd[1]: Service sleep.target is not needed anymore. Stopping.
Jul 05 22:31:20 pc500 systemd[1]: Stopping Sleep.
Jul 05 22:31:20 pc500 systemd[1]: Stopped target Sleep.
Jul 05 22:31:20 pc500 systemd[1]: Reached target Hibernate.
Jul 05 22:31:20 pc500 systemd[1]: Starting Remount NTFS file system after sleep...
Jul 05 22:31:20 pc500 systemd[1]: Started Remount NTFS file system after sleep.
Jul 05 22:31:20 pc500 systemd-logind[780]: Operation finished.
Jul 05 22:31:20 pc500 kernel: i8042 aux 00:09: System wakeup disabled by ACPI
Jul 05 22:31:20 pc500 kernel: i8042 kbd 00:08: System wakeup enabled by ACPI
Jul 05 22:31:20 pc500 kernel: PM: freeze of devices complete after 154.665 msecs
Jul 05 22:31:20 pc500 kernel: PM: late freeze of devices complete after 0.448 msecs
Jul 05 22:31:20 pc500 kernel: PM: noirq freeze of devices complete after 0.738 msecs
Jul 05 22:31:20 pc500 kernel: ACPI: Preparing to enter system sleep state S4
Jul 05 22:31:20 pc500 kernel: PM: Saving platform NVS memory
Jul 05 22:31:20 pc500 kernel: Disabling non-boot CPUs ...
Jul 05 22:31:20 pc500 kernel: kvm: disabling virtualization on CPU1
Jul 05 22:31:20 pc500 kernel: smpboot: CPU 1 is now offline
Jul 05 22:31:20 pc500 kernel: PM: Creating hibernation image:
Jul 05 22:31:20 pc500 kernel: PM: Need to copy 790860 pages
Jul 05 22:31:20 pc500 kernel: PM: Normal pages needed: 790860 + 1024, available pages: 1223740
Jul 05 22:31:20 pc500 kernel: PM: Restoring platform NVS memory
Jul 05 22:31:20 pc500 kernel: PCI-DMA: Resuming GART IOMMU
Jul 05 22:31:20 pc500 kernel: PCI-DMA: Restoring GART aperture settings
Jul 05 22:31:20 pc500 kernel: LVT offset 1 assigned for vector 0x400
Jul 05 22:31:20 pc500 kernel: IBS: LVT offset 1 assigned
Jul 05 22:31:20 pc500 kernel: Enabling non-boot CPUs ...
Jul 05 22:31:20 pc500 kernel: x86: Booting SMP configuration:
Jul 05 22:31:20 pc500 kernel: smpboot: Booting Node 0 Processor 1 APIC 0x1
Jul 05 22:31:20 pc500 kernel: kvm: enabling virtualization on CPU1
Jul 05 22:31:20 pc500 kernel: process: Switch to broadcast mode on CPU1
Jul 05 22:31:20 pc500 kernel: CPU1 is up
Jul 05 22:31:20 pc500 kernel: ACPI: Waking up from system sleep state S4
Jul 05 22:31:20 pc500 kernel: PM: noirq restore of devices complete after 21.970 msecs
Jul 05 22:31:20 pc500 kernel: PM: early restore of devices complete after 0.278 msecs
Jul 05 22:31:20 pc500 kernel: i8042 kbd 00:08: System wakeup disabled by ACPI
Jul 05 22:31:20 pc500 kernel: [drm] PCIE GART of 512M enabled (table at 0x00000000C0040000).
Jul 05 22:31:20 pc500 kernel: radeon 0000:01:05.0: WB enabled
Jul 05 22:31:20 pc500 kernel: radeon 0000:01:05.0: fence driver on ring 0 use gpu addr 0x00000000a0000c00 and cpu addr 0xffff8800cf9dcc00
Jul 05 22:31:20 pc500 kernel: [drm] ring test on 0 succeeded in 1 usecs
Jul 05 22:31:20 pc500 kernel: [drm] ib test on ring 0 succeeded in 0 usecs
Jul 05 22:31:20 pc500 kernel: usb usb5: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: usb usb4: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: usb usb3: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: usb usb2: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: usb usb1: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: usb usb7: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: usb usb6: root hub lost power or was reset
Jul 05 22:31:20 pc500 kernel: r8169 0000:02:00.0 enp2s0: link down
Jul 05 22:31:20 pc500 kernel: ata6: SATA link down (SStatus 0 SControl 300)
Jul 05 22:31:20 pc500 kernel: ata4: SATA link down (SStatus 0 SControl 300)
Jul 05 22:31:20 pc500 kernel: ata3: SATA link down (SStatus 0 SControl 300)
Jul 05 22:31:20 pc500 kernel: ata5: SATA link down (SStatus 0 SControl 300)
Jul 05 22:31:20 pc500 kernel: usb 4-2: reset full-speed USB device number 3 using ohci-pci
Jul 05 22:31:20 pc500 kernel: ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Jul 05 22:31:20 pc500 kernel: ata1.00: configured for UDMA/133
Jul 05 22:31:20 pc500 kernel: sd 0:0:0:0: [sda] Starting disk
Jul 05 22:31:20 pc500 kernel: ata2: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
Jul 05 22:31:20 pc500 kernel: ata2.00: configured for UDMA/100
Jul 05 22:31:20 pc500 kernel: usblp0: removed
Jul 05 22:31:20 pc500 kernel: PM: restore of devices complete after 619.467 msecs
Jul 05 22:31:20 pc500 kernel: usblp 4-2:1.0: usblp0: USB Bidirectional printer dev 3 if 0 alt 0 proto 2 vid 0x03F0 pid 0x3404
Jul 05 22:31:20 pc500 kernel: PM: Image restored successfully.
Jul 05 22:31:20 pc500 kernel: PM: Basic memory bitmaps freed
Jul 05 22:31:20 pc500 kernel: Restarting tasks ... done.
Jul 05 22:31:20 pc500 ifplugd(enp2s0)[1220]: Link beat lost.
Jul 05 22:31:20 pc500 ntfs-3g[21616]: Version 2013.1.13 external FUSE 29
Jul 05 22:31:20 pc500 ntfs-3g[21616]: Mounted /dev/sda1 (Read-Write, label "", NTFS 3.1)
Jul 05 22:31:20 pc500 ntfs-3g[21616]: Cmdline options: rw,noexec,nosuid,nodev,umask=000,users
Jul 05 22:31:20 pc500 ntfs-3g[21616]: Mount options: rw,noexec,nosuid,nodev,users,allow_other,nonempty,relatime,default_permissions,fsname
Jul 05 22:31:20 pc500 ntfs-3g[21616]: Global ownership and permissions enforced, configuration type 1
Jul 05 22:31:20 pc500 ntfs-3g[21616]: Unmounting /dev/sda1 ()
Jul 05 22:31:22 pc500 kernel: r8169 0000:02:00.0 enp2s0: link up
Jul 05 22:31:22 pc500 ifplugd(enp2s0)[1220]: Link beat detected.
Jul 05 22:31:25 pc500 kcheckpass[22375]: pam_tcb(kscreensaver:auth): Authentication passed for diddi from (uid=500)


An der vierten Zeile von unten läßt sich das erkennen. Offensichtlich passt dem Kernel der Mount-Vorgang nicht ins Konzept.
Diddi
 
Beiträge: 43
Registriert: Jan 16th, '12, 22:44


Zurück zu Basis-Support

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast

cron