openSuSE 12.3 Shutdown Script with systemd

Hi!
I am looking for an easy way to execute a shutdown script that backups a few directories via rsync. That means it must be finished before the network is down.
We’ve done that with halt.local and a ‘systemctl network restart’ at the beginning of the script file before - which worked fine with openSuSE 12.2.

I tried the same with 12.3 and it does not work anymore. First of all the halt-local.service needs a [Install] section now. Otherwise you can not enable the service and halt.local is ignored. But the ‘systemctl network restart’ workaround now prevents SuSE from continuing the shutdown process (Ctrl-Alt-Del continues it).

There must be an easy solution within the systemd system - but I can’t find it. I tried so many different scripts and services and just don’t get it to work.

So please - has anybody here a hint or a howto for me? I’m quite desperate at the moment…

Thanks a lot
stunner

this thread might help
https://bbs.archlinux.org/viewtopic.php?pid=1146444

On 2013-07-19 14:06, stunner wrote:

> We’ve done that with halt.local and a ‘systemctl network restart’ at
> the beginning of the script file before - which worked fine with
> openSuSE 12.2.

That’s an horrible hack. You should have created your own systemv script.

> There must be an easy solution within the systemd system - but I can’t
> find it. I tried so many different scripts and services and just don’t
> get it to work.

Yes, of course. You need creating a service file that has the
appropriate After and Before lines. Something like this - warning: I
have not tested it.


[Unit]
Description=backup service
After=network.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=-/usr/local/bin/run-backup-service

[Install]
WantedBy=multi-user.target

and enable it:


systemctl enable /etc/systemd/system/backup.service

If some other service is needed to be available, add it.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

Thanks a lot :wink:

I tried so many things. And I think now I got it (with a little workaround):

[Unit]
Description=backup service
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/etc/init.d/backup.sh
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

The service must be enabled and started to work at shutdown.

Thanks a lot for your help,
stunner

On 2013-07-19 16:06, stunner wrote:
> robin_listas;2573156 Wrote:

> Thanks a lot :wink:

Welcome

> I tried so many things. And I think now I got it (with a little
> workaround):

Maybe you should add “local-fs.target” as needed, or “after”, to make sure.

> The service must be enabled and started to work at shutdown.

Right.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)