Earlier quoted context omitted.
I tend to push the metaphor of software being meant to be read and only incidentally to be run by a computer as far as I can. We are telling a story to future us or our successors. Stories have rules and it's jarring when you violate them. There's an idea in software that's a bit like the corollary of Chekhov's gun. Chekhov's gun is about not presaging jarring story elements that will never come to pass. But it's nea…
Quoted post unavailable.
Writing systemd units that stop gracefully before shutdown
21–30 of 57 posts
Re: Writing systemd units that stop gracefully before shutdown
#22Halt is apparently not the same as poweroff.
AT power supplies didn't have any mechanism for the system to tell the power supply it wasn't needed any more. So when you shut down the computer, it would wind up at a screen with a message approximating "it is now safe to switch off your computer", at which point the system would halt.
ATX power supplies added the ability for the OS to trigger an actual power off. But that's a different end-state to halting, and if you halt the system then it stays on. You may wonder why anyone would want to halt when power off is an option, and to be honest I'm not entirely sure -- possibly because you have a hardware watchdog which will trigger a reboot of a halted machine but not of a powered off machine?
Re: Writing systemd units that stop gracefully before shutdown
#23Chrome is giving me an instant NXDOMAIN error.
Dig shows that
$ dig psdn.io @1.1.1.1
...
;; ->>HEADER
so then I prefix "www." like is in the URL... $ dig www.psdn.io @1.1.1.1
...
;; ->>HEADER
Okay, fine: $ dig poseidon-www.pages.dev @1.1.1.1
...
;; ->>HEADER
...wat??(Where there's no ANSWER section, none was returned, just an AUTHORITY section)
This is reproducible for me with 1.1.1.1, 8.8.8.8 and 9.9.9.9.
Re: Writing systemd units that stop gracefully before shutdown
#24A much more challenging task is writing a systemd unit that starts gracefully before shutdown. I wanted to write a unit that could issue an API call to delete the instance rather than doing a normal power off. Putting it at a reasonable place in the sequence took a lot of trial and error! The trick is actually to have the unit be started at some point in normal boot up (e.g. “armed”) and then do the actual task when…
I have the following unit file saved for that purpose: [Unit] # https://stackoverflow.com/questions/36729207/trigger-event-on-aws-ec2-instance-stop-terminate Description=unlink agent from remote server Before=shutdown.target [Service] Type=oneshot EnvironmentFile=-/etc/environment KillMode=none ExecStart=/bin/true ExecStop=/opt/service-name/shutdown-unlink RemainAfterExit=yes User=root [Install] WantedBy=multi-user.t…
Re: Writing systemd units that stop gracefully before shutdown
#25Meta: I can't reach this website! Chrome is giving me an instant NXDOMAIN error. Dig shows that $ dig psdn.io @1.1.1.1 ... ;; ->>HEADER so then I prefix "www." like is in the URL... $ dig www.psdn.io @1.1.1.1 ... ;; ->>HEADER Okay, fine: $ dig poseidon-www.pages.dev @1.1.1.1 ... ;; ->>HEADER ...wat?? (Where there's no ANSWER section, none was returned, just an AUTHORITY section) This is reproducible for me with 1.1.1…
dig www.psdn.io @1.1.1.1
; > DiG 9.16.33-RH > www.psdn.io @1.1.1.1
;; global options: +cmd
;; Got answer:
;; ->>HEADERRe: Writing systemd units that stop gracefully before shutdown
#26Earlier quoted context omitted.
I have the following unit file saved for that purpose: [Unit] # https://stackoverflow.com/questions/36729207/trigger-event-on-aws-ec2-instance-stop-terminate Description=unlink agent from remote server Before=shutdown.target [Service] Type=oneshot EnvironmentFile=-/etc/environment KillMode=none ExecStart=/bin/true ExecStop=/opt/service-name/shutdown-unlink RemainAfterExit=yes User=root [Install] WantedBy=multi-user.t…
You unit races with the network being brought down, since it isn't listed as a "Before" target, FYI.
Re: Writing systemd units that stop gracefully before shutdown
#27Earlier quoted context omitted.
I tend to push the metaphor of software being meant to be read and only incidentally to be run by a computer as far as I can. We are telling a story to future us or our successors. Stories have rules and it's jarring when you violate them. There's an idea in software that's a bit like the corollary of Chekhov's gun. Chekhov's gun is about not presaging jarring story elements that will never come to pass. But it's nea…
Quoted post unavailable.
Re: Writing systemd units that stop gracefully before shutdown
#28Earlier quoted context omitted.
You unit races with the network being brought down, since it isn't listed as a "Before" target, FYI.
I could be mistaken, but I don't think even that would be sufficient? Before would make your command execute before the network is brought down, but it wouldn't have the latter wait for your command to actually complete.
@CGamesPlay network.target's "primary purpose is for ordering things properly at shutdown: since the shutdown ordering of units in systemd is the reverse of the startup ordering, any unit that is order After=network.target can be sure that it is stopped before the network is shut down if the system is powered off."
https://www.freedesktop.org/wiki/Software/systemd/NetworkTar...
Re: Writing systemd units that stop gracefully before shutdown
#29Edit: Note that my example runlevels are for Solaris, other UNIX/Linux OSes will vary.
Re: Writing systemd units that stop gracefully before shutdown
#30A much more challenging task is writing a systemd unit that starts gracefully before shutdown. I wanted to write a unit that could issue an API call to delete the instance rather than doing a normal power off. Putting it at a reasonable place in the sequence took a lot of trial and error! The trick is actually to have the unit be started at some point in normal boot up (e.g. “armed”) and then do the actual task when…