You are not logged in.

#1 2012-08-14 13:24:05

domac
Member
Registered: 2012-08-06
Posts: 102

[solved] execute script on systemd shutdown/reboot

Hello!
I tried to execute a script on shutdown and/or reboot…

-rwxr-xr-x 1 root root  319 Aug 14 14:46 dwm-tmpfile

I modified /usr/lib/systemd/system/reboot.target.wants/console-kit-log-system-restart.service -> ../console-kit-log-system-restart.service

[Unit]
Description=Console System Reboot Logging
DefaultDependencies=no
After=sysinit.target console-kit-log-system-start.service
Before=shutdown.target

[Service]
Type=oneshot
ExecStartPre=/bin/bash -c /home/domac/.bin/dwm-tmpfile store
ExecStart=/usr/sbin/ck-log-system-restart

and /usr/lib/systemd/system/poweroff.target.wants/console-kit-log-system-stop.service -> ../console-kit-log-system-stop.service

[Unit]
Description=Console System Shutdown Logging
DefaultDependencies=no
After=sysinit.target console-kit-log-system-start.service
Before=shutdown.target

[Service]
Type=oneshot
ExecStartPre=/bin/bash -c /home/domac/.bin/dwm-tmpfile store
ExecStart=/usr/sbin/ck-log-system-stop

My script looks like

$domac.vex cat ~/.bin/dwm-tmpfile 
#!/bin/bash

case $1 in
    store)
        #store tmp files
        cp -r /tmp/.dwm/ /home/domac/.tmpdwm
    ;;
    restore)
        #restore tmp files
        cp -r /home/domac/.tmpdwm/ /tmp/.dwm
    ;;
    *)
        #undefined action
    ;;
esac

Does someone know what I am doing wrong?
Thanks for help in advance!

Last edited by domac (2012-08-14 22:00:44)


domac [ git ]

Offline

#2 2012-08-14 13:36:22

tomegun
Developer
From: France
Registered: 2010-05-28
Posts: 661

Re: [solved] execute script on systemd shutdown/reboot

Is the problem that the service file is not enabled at shutdown, or that it fails?

Try:

# systemctl start <myservice>.service
# systemctl status <myselvice>.service

Offline

#3 2012-08-14 13:49:35

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] execute script on systemd shutdown/reboot

Thanks for the reply. I did as you wrote

$domac.vex sudo systemctl start console-kit-log-system-stop.service
$domac.vex sudo systemctl start console-kit-log-system-restart.service
$domac.vex sudo systemctl status console-kit-log-system-stop.service
console-kit-log-system-stop.service - Console System Shutdown Logging
	  Loaded: loaded (/usr/lib/systemd/system/console-kit-log-system-stop.service; static)
	  Active: inactive (dead)
	  CGroup: name=systemd:/system/console-kit-log-system-stop.service

$domac.vex sudo systemctl status console-kit-log-system-restart.service
console-kit-log-system-restart.service - Console System Reboot Logging
	  Loaded: loaded (/usr/lib/systemd/system/console-kit-log-system-restart.service; static)
	  Active: inactive (dead)
	  CGroup: name=systemd:/system/console-kit-log-system-restart.service

and I'm going to reboot now and will come with more information then. Thanks!

Edit: It didn't worked. Maybe I'm using the wrong files? I have no idea since I'm using systemd… I'm sorry for that but I switched to systemd yesterday. smile

Last edited by domac (2012-08-14 14:05:53)


domac [ git ]

Offline

#4 2012-08-14 14:59:25

12eason
Banned
Registered: 2010-07-20
Posts: 103

Re: [solved] execute script on systemd shutdown/reboot

Pretty sure you should not need to modify existing units just to get them to load your script. Just make your own unit file, set it to trigger before the console kit units, and then install the unit.

eta; as always though, check

journalctl

to see what errors the service throws.

Last edited by 12eason (2012-08-14 15:01:59)

Offline

#5 2012-08-14 15:12:12

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] execute script on systemd shutdown/reboot

Thanks for the reply!

I already check #journalctl but there is no error. Just the errors with wpa_supplicant and dhcp I'm already asking about in another thread.
Do you have a good source how to setup an own unit and make it execute before my computer shutdown or reboot?

Nevermind, I'll post my whole #journalctl here:

Logs begin at Tue, 14 Aug 2012 15:55:53 +0200, end at Tue, 14 Aug 2012 16:57:00 +0200.
Aug 14 15:55:53 vex systemd-journal[119]: Journal started
Aug 14 15:55:53 vex systemd-modules-load[111]: Inserted module 'acpi_call'
Aug 14 15:55:53 vex systemd-modules-load[111]: Inserted module 'acpi_cpufreq'
Aug 14 15:55:53 vex systemd-modules-load[111]: Module 'cpufreq_ondemand' is builtin
Aug 14 15:55:53 vex systemd-modules-load[111]: Inserted module 'cpufreq_powersave'
Aug 14 15:55:56 vex systemd-fsck[239]: bootfs: clean, 421/24096 files, 37734/96356 blocks
Aug 14 15:55:57 vex acpid[262]: starting up with netlink and the input layer
Aug 14 15:55:57 vex acpid[262]: 1 rule loaded
Aug 14 15:55:57 vex acpid[262]: waiting for events: event logging is off
Aug 14 15:55:58 vex dhcpcd[261]: version 5.5.6 starting
Aug 14 15:55:58 vex dhcpcd[266]: version 5.5.6 starting
Aug 14 15:55:58 vex su[265]: pam_unix(su:session): session opened for user domac by (uid=0)
Aug 14 15:55:58 vex su[265]: pam_unix(su:session): session closed for user domac
Aug 14 15:55:58 vex su[292]: pam_unix(su:session): session opened for user domac by (uid=0)
Aug 14 15:55:58 vex su[292]: pam_unix(su:session): session closed for user domac
Aug 14 15:55:58 vex su[294]: pam_unix(su:session): session opened for user domac by (uid=0)
Aug 14 15:55:58 vex su[294]: pam_unix(su:session): session closed for user domac
Aug 14 15:55:58 vex dhcpcd[266]: wlan0: carrier acquired
Aug 14 15:55:58 vex dhcpcd[261]: eth0: sending IPv6 Router Solicitation
Aug 14 15:55:58 vex dhcpcd[261]: eth0: sendmsg: Network is unreachable
Aug 14 15:55:58 vex dhcpcd[266]: wlan0: carrier lost
Aug 14 15:55:58 vex dhcpcd[266]: wlan0: waiting for carrier
Aug 14 15:55:58 vex dhcpcd[261]: eth0: broadcasting for a lease
Aug 14 15:55:59 vex systemd-logind[268]: New seat seat0.
Aug 14 15:55:59 vex systemd-logind[268]: Watching system buttons on /dev/input/event3 (Power Button)
Aug 14 15:55:59 vex systemd-logind[268]: Watching system buttons on /dev/input/event5 (Video Bus)
Aug 14 15:55:59 vex systemd-logind[268]: Watching system buttons on /dev/input/event4 (Video Bus)
Aug 14 15:55:59 vex systemd-logind[268]: Watching system buttons on /dev/input/event1 (Lid Switch)
Aug 14 15:55:59 vex systemd-logind[268]: Watching system buttons on /dev/input/event2 (Sleep Button)
Aug 14 15:55:59 vex dhcpcd[261]: eth0: carrier lost
Aug 14 15:55:59 vex dhcpcd[266]: wlan0: carrier acquired
Aug 14 15:55:59 vex dhcpcd[266]: wlan0: sending IPv6 Router Solicitation
Aug 14 15:55:59 vex dhcpcd[266]: wlan0: sendmsg: Cannot assign requested address
Aug 14 15:55:59 vex dhcpcd[266]: wlan0: broadcasting for a lease
Aug 14 15:56:00 vex dhcpcd[266]: wlan0: offered 192.168.2.117 from 192.168.2.1
Aug 14 15:56:01 vex dhcpcd[266]: wlan0: acknowledged 192.168.2.117 from 192.168.2.1
Aug 14 15:56:01 vex dhcpcd[266]: wlan0: leased 192.168.2.117 for 864000 seconds
Aug 14 15:56:01 vex dhcpcd[266]: forked to background, child pid 356
Aug 14 15:56:02 vex dhcpcd[261]: eth0: sending IPv6 Router Solicitation
Aug 14 15:56:02 vex dhcpcd[261]: eth0: sendmsg: Network is unreachable
Aug 14 15:56:03 vex dhcpcd[356]: wlan0: sending IPv6 Router Solicitation
Aug 14 15:56:06 vex dhcpcd[261]: eth0: sending IPv6 Router Solicitation
Aug 14 15:56:06 vex dhcpcd[261]: eth0: sendmsg: Network is unreachable
Aug 14 15:56:07 vex dhcpcd[356]: wlan0: sending IPv6 Router Solicitation
Aug 14 15:56:07 vex dbus-daemon[267]: dbus[267]: [system] Activating via systemd: service name='org.freedesktop.ConsoleKit' unit='console-kit-daemon.service'
Aug 14 15:56:08 vex console-kit-daemon[360]: missing action
Aug 14 15:56:08 vex dbus-daemon[267]: dbus[267]: [system] Activating service name='org.freedesktop.PolicyKit1' (using servicehelper)
Aug 14 15:56:08 vex dbus-daemon[267]: dbus[267]: [system] Successfully activated service 'org.freedesktop.PolicyKit1'
Aug 14 15:56:08 vex dbus-daemon[267]: dbus[267]: [system] Successfully activated service 'org.freedesktop.ConsoleKit'
Aug 14 15:56:08 vex systemd-logind[268]: New session 1 of user domac.
Aug 14 15:56:09 vex acpid[262]: client connected from 465[0:100]
Aug 14 15:56:09 vex acpid[262]: 1 client rule loaded
Aug 14 15:56:10 vex dhcpcd[261]: eth0: sending IPv6 Router Solicitation
Aug 14 15:56:10 vex dhcpcd[261]: eth0: sendmsg: Network is unreachable
Aug 14 15:56:10 vex dhcpcd[261]: eth0: no IPv6 Routers available
Aug 14 15:56:11 vex dhcpcd[356]: wlan0: sending IPv6 Router Solicitation
Aug 14 15:56:11 vex dhcpcd[356]: wlan0: no IPv6 Routers available
Aug 14 15:56:15 vex dbus-daemon[267]: dbus[267]: [system] Activating via systemd: service name='org.freedesktop.UPower' unit='upower.service'
Aug 14 15:56:16 vex dbus-daemon[267]: dbus[267]: [system] Successfully activated service 'org.freedesktop.UPower'
Aug 14 15:56:16 vex dbus-daemon[267]: dbus[267]: [system] Activating service name='org.freedesktop.UDisks' (using servicehelper)
Aug 14 15:56:16 vex dbus-daemon[267]: (process:617): GLib-WARNING **: goption.c:2179: ignoring no-arg, optional-arg or filename flags (16) on option of arg-type 1 in entry (null):helper-dir
Aug 14 15:56:16 vex dbus-daemon[267]: dbus[267]: [system] Successfully activated service 'org.freedesktop.UDisks'
Aug 14 15:56:16 vex dbus-daemon[267]: (udisks-daemon:617): udisks-daemon-WARNING **: No /proc/mdstat file: No such file or directory
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:01.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:01.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:02.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:02.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:16.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:16.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1a.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1a.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1b.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1b.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.1
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.1
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.3
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.3
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.3/0000:04:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.3/0000:04:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.5
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.5
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1c.5/0000:05:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1c.5/0000:05:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1d.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1d.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1e.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1e.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1f.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1f.2
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.2
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:00/0000:00:1f.6
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.6
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:ff/0000:ff:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:ff/0000:ff:00.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:ff/0000:ff:00.1
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:ff/0000:ff:00.1
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:ff/0000:ff:02.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:ff/0000:ff:02.0
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:ff/0000:ff:02.1
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:ff/0000:ff:02.1
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:ff/0000:ff:02.2
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:ff/0000:ff:02.2
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci ADDING /sys/devices/pci0000:ff/0000:ff:02.3
Aug 14 15:56:16 vex dbus-daemon[267]: **** pci IGNORING ADD /sys/devices/pci0000:ff/0000:ff:02.3
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/scsi_host/host1
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/scsi_host/host1
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata3/host2/scsi_host/host2
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.2/ata3/host2/scsi_host/host2
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata4/host3/scsi_host/host3
Aug 14 15:56:16 vex dbus-daemon[267]: **** scsi_host IGNORING ADD /sys/devices/pci0000:00/0000:00:1f.2/ata4/host3/scsi_host/host3
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:16 vex dbus-daemon[267]: helper(pid   626): launched job udisks-helper-ata-smart-collect on /dev/sda
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDING /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0
Aug 14 15:56:16 vex dbus-daemon[267]: **** ADDED /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGING /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGED /sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
Aug 14 15:56:16 vex dbus-daemon[267]: **** UPDATING /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
Aug 14 15:56:16 vex dbus-daemon[267]: **** CHANGED /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
Aug 14 15:56:17 vex dbus-daemon[267]: /dev/sda:
Aug 14 15:56:17 vex dbus-daemon[267]: setting standby to 160 (13 minutes + 20 seconds)
Aug 14 15:56:17 vex dbus-daemon[267]: **** NOTE: standby helper for /dev/sda completed successfully
Aug 14 15:56:17 vex dbus-daemon[267]: helper(pid   626): completed with exit code 0
Aug 14 15:56:17 vex dbus-daemon[267]: **** EMITTING CHANGED for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 15:56:18 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 15:56:18 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 15:56:19 vex acpid[262]: client 465[0:100] has disconnected
Aug 14 15:56:28 vex dhcpcd[261]: timed out
Aug 14 15:56:28 vex systemd[1]: dhcpcd@eth0.service: control process exited, code=exited status=1
Aug 14 15:56:28 vex systemd[1]: Unit dhcpcd@eth0.service entered failed state.
Aug 14 15:56:28 vex systemd[1]: Startup finished in 6s 59ms 69us (kernel) + 37s 461ms 177us (userspace) = 43s 520ms 246us.
Aug 14 15:56:39 vex acpid[262]: client connected from 465[0:100]
Aug 14 15:56:39 vex acpid[262]: 1 client rule loaded
Aug 14 16:21:59 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 16:26:17 vex dbus-daemon[267]: **** Refreshing ATA SMART data for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 16:26:17 vex dbus-daemon[267]: helper(pid  3427): launched job udisks-helper-ata-smart-collect on /dev/sda
Aug 14 16:26:17 vex dbus-daemon[267]: helper(pid  3427): completed with exit code 0
Aug 14 16:26:17 vex dbus-daemon[267]: **** EMITTING CHANGED for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 16:28:54 vex systemd-logind[268]: Power key pressed.
Aug 14 16:28:54 vex systemd-logind[268]: Refusing power-off, user is logged in.
Aug 14 16:28:55 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 16:28:55 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 16:29:44 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 16:29:44 vex dbus-daemon[267]: **** /proc/self/mountinfo changed
Aug 14 16:29:44 vex acpid[262]: client 465[0:100] has disconnected
Aug 14 16:29:44 vex acpid[262]: client connected from 465[0:100]
Aug 14 16:29:44 vex acpid[262]: 1 client rule loaded
Aug 14 16:57:00 vex dbus-daemon[267]: **** Refreshing ATA SMART data for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Aug 14 16:57:00 vex dbus-daemon[267]: helper(pid 20745): launched job udisks-helper-ata-smart-collect on /dev/sda
Aug 14 16:57:00 vex dbus-daemon[267]: helper(pid 20745): completed with exit code 0
Aug 14 16:57:00 vex dbus-daemon[267]: **** EMITTING CHANGED for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda

Had one hibernate in between.


domac [ git ]

Offline

#6 2012-08-14 20:15:41

12eason
Banned
Registered: 2010-07-20
Posts: 103

Re: [solved] execute script on systemd shutdown/reboot

Not sure if just a hibernate is going to capture a switch to shutdown.target, which console-kit comes before. You need to have a persistent journal, as per the wiki: and then you should get this kind of thing after a reboot:

Aug 13 11:43:37 desktop systemd[1]: home.mount mount process exited, code=exited status=32
Aug 13 11:43:38 desktop dhcpcd[939]: received SIGTERM, stopping
Aug 13 11:43:38 desktop dhcpcd[939]: eth0: removing interface
Aug 13 11:43:40 desktop systemd[1]: Unit home.mount entered failed state.
Aug 13 11:43:40 desktop systemd[1]: Shutting down.
Aug 13 11:43:41 desktop systemd-journal[157]: Journal stopped
----- Reboot -----
Aug 13 11:44:13 desktop systemd-journal[153]: Journal started
Aug 13 11:44:13 desktop systemd-modules-load[160]: Inserted module 'microcode'
Aug 13 11:44:17 desktop /usr/sbin/gpm[301]: *** info [daemon/startup.c(136)]:
Aug 13 11:44:17 desktop /usr/sbin/gpm[301]: Started gpm successfully. Entered daemon mode.

As for making your own unit, all the details are in man systemd.unit and man systemd.service. You just need a [Unit], [Service] and [Install] section and set it to happen before shutdown, much like console-kit does.

Offline

#7 2012-08-14 20:24:25

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,865
Website

Re: [solved] execute script on systemd shutdown/reboot

Can I suggest that you use graysky's excellent sync-anything-daemon in this scenario? It seems like you're trying to replicate the behaviour that this script exhibits.

If it's not quite the same thing, perhaps the .service file will be a useful template for you.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#8 2012-08-14 21:10:33

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] execute script on systemd shutdown/reboot

Thanks for pointing that out!
But I don't get how this code will be run before shutdown, reboot or whereever the ram is cleared. I don't wanna use asd because I mount things on tmpfs manually and systemd should provide an equivalent to rc.shutdown using the systemd way… sad
I'd love to execute my script, so I will try to write my one service in reference to the asd one.
Thanks for the tip!

Edit: Writing my own service solved the problem! Thank you WorMzy! Should I post the final output? I mean, everyone can look at the code at graysky2's github. smile If someone want to see my code, just ask for it. wink

Last edited by domac (2012-08-14 21:59:27)


domac [ git ]

Offline

#9 2012-08-14 21:57:54

12eason
Banned
Registered: 2010-07-20
Posts: 103

Re: [solved] execute script on systemd shutdown/reboot

It's the combination of RemainAfterExit and ExecStop that allows it to run on shutdown. systemd treats it as a running dameon even after the ExecStart script has exited and then uses ExecStop to kill the service on stutdown.

Last edited by 12eason (2012-08-14 21:58:20)

Offline

#10 2012-08-14 22:00:24

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] execute script on systemd shutdown/reboot

Thanks for that explanation 12eason. smile
Now it works and I know why for 100%. wink


domac [ git ]

Offline

#11 2012-08-14 22:02:11

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,865
Website

Re: [solved] execute script on systemd shutdown/reboot

When it starts (syncs), the script proper (/usr/bin/anything-sync-daemon) copies the contents of any directories defined in the asd config file to a tmpfs also specified there (/dev/shm by default, but /tmp or any other tmpfs would work fine*), then symlinks the original directory to the tmpfs directory. When it stops (unsyncs), the symlink is removed, and the contents of the tmpfs directory is copied back to the original location.

If the service file is enabled (# systemctl enable asd.service), when the system boots, systemd starts the service, which calls the script, which syncs the directory to the tmpfs. Then when the system shuts down/reboots, systemd stops the service, which calls the script, which "unsyncs" the directory back to the HDD/SSD. If you manually start the service (# systemctl start asd.service), the same thing happens, but it only happens once (i.e. when you reboot, the script will get called to "unsync", but the script won't be called to sync back to the tmpfs during the next boot up.

Hope that clears thing up for you.

*/tmp may not be the best location to use if you use bleachbit-esque software

EDIT: I guess I was too slow writing this. Haha.

Last edited by WorMzy (2012-08-14 22:03:32)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#12 2015-05-19 06:16:27

yance
Member
Registered: 2015-05-19
Posts: 9

Re: [solved] execute script on systemd shutdown/reboot

domac wrote:

Thanks for pointing that out!
But I don't get how this code will be run before shutdown, reboot or whereever the ram is cleared. I don't wanna use asd because I mount things on tmpfs manually and systemd should provide an equivalent to rc.shutdown using the systemd way… sad
I'd love to execute my script, so I will try to write my one service in reference to the asd one.
Thanks for the tip!

Edit: Writing my own service solved the problem! Thank you WorMzy! Should I post the final output? I mean, everyone can look at the code at graysky2's github. smile If someone want to see my code, just ask for it. wink

@domac, can you share how you make your service? I also make service for running script during shutdown process but it won't run again.

Offline

#13 2015-05-19 07:31:25

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,865
Website

Re: [solved] execute script on systemd shutdown/reboot

Yance, welcome to Arch. Please take care not to bump old topics, especially if they're marked as solved. Create a new topic about your problem and link back to this one if it's still relevant.

https://wiki.archlinux.org/index.php/Fo … bumping.22

Closing.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB