<p dir="ltr">/dev is a separate filesystem and is never read-only.</p>
<p dir="ltr">Another approach would be to let microupsd exit normally, but then start a separate microupsd instance (e.g. microupsd-shutdown.service) which schedules the UPS poweroff.</p>
<br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 9, 2017, 12:03 Marek Floriańczyk <<a href="mailto:marek.florianczyk@gmail.com">marek.florianczyk@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dnia środa, 9 sierpnia 2017 10:29:37 CEST Lennart Poettering pisze:<br>
> On Di, 08.08.17 16:03, Marek Floriańczyk (<a href="mailto:marek.florianczyk@gmail.com" target="_blank">marek.florianczyk@gmail.com</a>) wrote:<br>
> > Hi all,<br>
> ><br>
> > I have a small device MicroUPS which helps me to shutdown my system on<br>
> > embedded devices, it is controlled by script /etc/init.d/microups and in<br>
> > this script I need to know whether system is going down for reboot or for<br>
> > halt, because in case of halt I need to send small data over RS232 to<br>
> > MicroUPS device to cut the power off.<br>
><br>
> Note that this is necessarily racy: you can't really know how long the<br>
> system will actually take to shut down, hence if you trigger your<br>
> hardware for shutdown at an early phase of the shutdown process you<br>
> now start racing the remaining shutdown phase against the hardware turning<br>
> off power...<br>
><br>
> If you want to fix this properly, and remove this race entirely the<br>
> only fully correct way out I see is to use an initrd for booting, and<br>
> doing the RS232 thing from that. Note that if you use a properly<br>
> prepared initrd, systemd will actually transition back to it at<br>
> shutdown, and while doing so it will permit unmounting the root file<br>
> system properly at shutdown. And only if you start the RS232 thing<br>
> after the point where the root fs is unmounted you can fully remove<br>
> the race in the generic case, since only at that point everything is<br>
> fully synced to disk, all complex storage is disassembled and so on.<br>
><br>
> Now, adding this to the initrd is not the easiest thing in the world,<br>
> and in particular in embedded devices avoiding an initrd might be a<br>
> good thing. As long as you have no complex storage (i.e. no DM, no<br>
> LVM, no LUKS, no RAID, no iscsi, yaddayadda) you can instead cut a<br>
> corner and just drop in a shutdown script to<br>
> /usr/lib/systemd/system-shutdown/. All executable files in that<br>
> directory are run at very late boot, at a point where all file systems<br>
> that can be unmounted have been unmounted and the rest have been<br>
> remounted read-only (i.e. the root fs will be r/o and everything else<br>
> is gone). All services are gone at that point too, hence you live in a<br>
> very minimal, very reduced environment. If you issue your RS232<br>
> commands from that environment you should be mostly good. (but again,<br>
> if you do complex storage all of this falls apart, and you have to do<br>
> the initrd thing instead).<br>
><br>
> Note that /usr/lib/systemd/system-shutdown/ is outside of usual<br>
> service management. It's run at a point where service management is<br>
> already turned off. As such, you really just drop executable scripts<br>
> or binaries there, and nothing long-running, no daemons or such, just<br>
> simple programs that run and exit.<br>
><br>
> For details about this facility see the systemd-halt.service(8) man<br>
> page. The scripts executed that way will get one parameter, which<br>
> tells it what operation is being executed. And if its "poweroff", then<br>
> you know that the system is going down for powering off rather than<br>
> reboot.<br>
<br>
Hi,<br>
<br>
This looks like a good way for me.<br>
I cannot really use initrd, because my MicroUPS is intended to work not only<br>
for me but also for an average people, with some .deb package to install.<br>
This is an early version of my device, now it looks different, has higher<br>
power output and so on<br>
<a href="https://www.indiegogo.com/projects/microups-for-raspberry-beaglebone-cubieboard#/" rel="noreferrer" target="_blank">https://www.indiegogo.com/projects/microups-for-raspberry-beaglebone-cubieboard#/</a><br>
<br>
<br>
I'm aware of race condition but some microcomputers like Raspberry if they<br>
shutdown the operating system, the power is still ON, and I have no way to<br>
figure out when to turn power off. So what I'm doing is telling microups device<br>
to cut power off 30 seconds after shutdown has been initiated (parameter is<br>
configurable).<br>
Microcomputers usually have some SD card, sometimes built-in NAND memory, and<br>
sometimes single SATA SSD disk, so complex storage is not an issue (I think)<br>
<br>
The question is, will my binary be able to open RS232 port eg. /dev/ttyACM0<br>
when filesystem is Read-Only ?<br>
And if it is binary it will need to load some libs at least libc at the start.<br>
<br>
The man page you pointed to says the parameter is: "halt", "poweroff",<br>
"reboot" or "kexec", so the first two should work for me.<br>
<br>
Best Regards<br>
Marek<br>
<br>
<br>
><br>
> Lennart<br>
<br>
<br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</blockquote></div><div dir="ltr">-- <br></div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">Mantas Mikulėnas <<a href="mailto:grawity@gmail.com">grawity@gmail.com</a>><br>
Sent from my phone</p>
</div></div>