12.3 halt.local does not run at shutdown

I have some commands I would like to run at shutdown on my OpenSuse 12.3 system. I understand halt.local would be a logical place to put the commands, but on my system, I’ve been able to determine that halt.local never runs when the system shuts down.

I’ve set up this test to document the issue:

Contents of halt.local:
linux1:~> cat /etc/init.d/halt.local
#! /bin/sh

Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany. All rights reserved.

Author: Werner Fink, 1998

Burchard Steinbild, 1998

/etc/init.d/halt.local

script with local commands to be executed from init on system shutdown

Here you should add things, that should happen directly before shuting

down.

echo “$(date) running halt.local” >>/var/log/halt.log

If I run halt.local manually, it in fact echo’s the message to /var/log/halt.log as it should:
Sun Aug 3 09:58:37 EDT 2014 running halt.local

If I execute a “shutdown -r now” command, the system reboots, and I never get the message in /var/log/halt.log

The halt-local service looks like this:
linux1:~>systemctl status halt-local
halt-local.service - /etc/init.d/halt.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/halt-local.service; static)
Active: inactive (dead)
CGroup: name=systemd:/system/halt-local.service

linux1:~>cat /usr/lib/systemd/system/halt-local.service

This file is part of systemd.

systemd is free software; you can redistribute it and/or modify it

under the terms of the GNU Lesser General Public License as published by

the Free Software Foundation; either version 2.1 of the License, or

(at your option) any later version.

[Unit]
Description=/etc/init.d/halt.local Compatibility
ConditionFileIsExecutable=/etc/init.d/halt.local
DefaultDependencies=no
After=shutdown.target
Before=final.target

[Service]
Type=oneshot
ExecStart=/etc/init.d/halt.local
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes

If I manually start the service, I get this:
linux1:~>systemctl start halt-local
linux1:~>systemctl status halt-local
halt-local.service - /etc/init.d/halt.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/halt-local.service; static)
Active: active (exited) since Sun, 2014-08-03 10:22:40 EDT; 6s ago
Process: 2743 ExecStart=/etc/init.d/halt.local (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/halt-local.service

Aug 03 10:22:40 linux1.randyburton.me systemd[1]: Started /etc/init.d/halt.local Compatibility.

And if I now check /var/log/halt.log, I can see that halt.local ran just fine:
Sun Aug 3 10:22:40 EDT 2014 running halt.local

However, a “shutdown -r now” still does not cause halt.local to run.

Any ideas on what’s going on here?

I have a workaround - defined my own service, as described here:
https://www.suse.com/communities/conversations/easy-running-scripts-boot-and-shutdown/
and in stop.d, I just put a link to /etc/init.d/halt.local:
linux1:~> ls -lh /etc/init.d/my_maintenance.d/stop.d/
total 0
lrwxrwxrwx 1 root root 22 Aug 3 09:26 halt.local -> /etc/init.d/halt.local

So, now, halt.local does in fact run when I reboot, but this seems a bit of a Rube Goldberg solution to me.

Any suggestions on how to get this to work the way it’s supposed to work?

One last comment on a minor issue… in the default OpenSuse /etc/init.d/halt.local file, in the comments, “shuting” should be “shutting”.

Thanks for the assistance,
Randy

On 2014-08-03 16:46, VTBurtonRA wrote:

> If I run halt.local manually, it in fact echo’s the message to
> /var/log/halt.log as it should:
> Sun Aug 3 09:58:37 EDT 2014 running halt.local
>
>
> If I execute a “shutdown -r now” command, the system reboots, and I
> never get the message in /var/log/halt.log

Maybe because the filesystem is already read-only at that phase… :-?

> One last comment on a minor issue… in the default OpenSuse
> /etc/init.d/halt.local file, in the comments, “shuting” should be
> “shutting”.

Ah, you have to report that in Bugzilla. Here it is just a comment
between users :wink:


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

>Maybe because the filesystem is already read-only at that phase… :-?

I’m confident it isn’t running at all - I’ve put other commands in there, and they don’t execute either.

Thanks for the suggestion though.

Randy

On 2014-08-03 20:16, VTBurtonRA wrote:
>
>> Maybe because the filesystem is already read-only at that phase… :-?
>
> I’m confident it isn’t running at all - I’ve put other commands in
> there, and they don’t execute either.

Unfortunately, I don’t have a 12.3 system here to try replicate the
issue. I know that at the beginning, those local jobs did not work with
systemd, and at some release, they worked again; I’m unsure which release.

> Thanks for the suggestion though.

Welcome. :slight_smile:


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

halt-local.service - /etc/init.d/halt.local Compatibility
          Loaded: loaded (/usr/lib/systemd/system/halt-local.service; static)
          **Active: inactive (dead)**
          CGroup: name=systemd:/system/halt-local.service

you need to enable it

systemctl enable halt-local

start it with

systemctl start halt-local

or replace halt-local if it is not the correct service name.

No.
It’s state is “static”, which means that it is enabled and cannot be disabled (only masked).
See systemd "static" unit file state / Applications & Desktop Environments / Arch Linux Forums f.e.

Of course it is shown as “inactive (dead)” here, because it hasn’t been started yet. (it gets only started at shutdown)

Btw, halt.local is run fine here on 13.1, even without enabling the service. I just tried it.
And it even logged to /var/log/halt.log successfully… :wink:

I cannot test on a 12.3 system either though.

Another way to achieve the same would be to put a script to /usr/lib/systemd/system-shutdown/, which gets called then on halt/poweroff/reboot/kexec. See “man systemd-halt.service” for details.
But I don’t know if that would work already on 12.3.

I have a 12.3 vm and halt.local does work on it.

I tried it myself now on 12.3 in a VM, and it did not work here.

It works when I run “systemctl start halt-local.service”, but it doesn’t get run on shutdown automatically.

“systemctl enable halt-local.service” didn’t work either, it cannot be enabled because it is static and has no “Install” section.

So apparently this is a shortcoming of the systemd included in 12.3 (or its configuration) as robin_listas already hinted at.
Strange that it would work for you then though. Did you do anything special to make it work?

I did not remember any configuration on my side. I only use

systemctl start halt.local

systemctl enable halt.local
systemctl status halt.local.service
halt.local.service
          Loaded: loaded (/etc/init.d/halt.local)
          Active: **active (exited) **since Sun, 2014-08-10 04:41:15 PHT; 5 days ago
         Process: 417 ExecStart=/etc/init.d/halt.local start (code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/halt.local.service

Inside /etc/init.d/halt.local i have something like this.

echo foo >> ~/message.txt

Then it gets populated with foo during a manual /etc/init.d/halt.local restart or a simple reboot.

And yes halt-local is indeed static on this side too :slight_smile:

I remember a problem I ran into with halt.local on my Optimus netbook, can’t have been later than 12.3 I suppose. My netbook is a little special I can toggle between intel only, nvidia only and optimus mode with acpi_call, problem is one has to set it in each session for the next session. So I put some code in halt.local to do that by selecting from a menu, that worked fine in intel mode but I never got it to work in nvidia mode. I never solved it and when I realised I rarely ran it in any other mode than intel only I set it permanently to intel mode in boot.local.

I do have an intel gfx card if that matters even with a vm :slight_smile:

Ok, you don’t actually use halt-local.service then, but enabled the init script /etc/init.d/halt.local directly to be started on boot.
Is that what you want though?
If I try this on 13.1 (cannot test 12.3 at the moment), I get the following message during boot: (excerpt from my /var/log/boot.log)

  OK  ] Started D-Bus System Message Bus.
         Starting Login Service...
         Starting halt.local.service...
         Starting Network Manager...
  OK  ] Started Restore Sound Card State.
  OK  ] Started halt.local.service.
  OK  ] Started Permit User Sessions.
         Starting LSB: X Display Manager...
  OK  ] Started Initialize hardware monitoring sensors.
         Starting Authorization Manager...
  OK  ] Started WPA Supplicant daemon.
  OK  ] Started Avahi mDNS/DNS-SD Stack.
  OK  ] Started Login Service.
  OK  ] Started Authorization Manager.
  OK  ] Started LSB: X Display Manager.

And your “systemctl status” output would also indicate that it is indeed started during boot already.

Luckily this forums memory is better than mine, my problem was already in 11.2, but maybe hcw’s comment is still relevant, I never researched it?
https://forums.opensuse.org/showthread.php/464018-Problem-with-halt-local