0

I do understand from the configs how to make a service restart in case of a fail but in this case a simple restart would always result in the same fail again and again

how can set a service to restart with alternative parameters?

i tried to edit the .../dhcpcd.service.d/wait.conf from my Raspberry Pi to load a config file from my /boot section with the -f option

but if there is no file, the service just fails and does not fallback to use the default config

so i need to know how to change the wait.conf so it would restart the service on fail without the -f /boot/dhcpcd_boot.conf option instead

to be clear, i just edited the wait.conf and attached the line above and did nothing else to any other part

i want to be able to specify a dhcpcd_boot.conf with custom settings from a windows machine without using bonjour while in USB gadget RNDIS mode and without installing an DHCP server on the windows machine to SSH into the pi.

Core of my issue is, I want the dhcp service, which requests and assigns my network adapter an IP, to run a config off the fat32 /boot/ partition, but if the file is damaged or missing, the service fails to run and i am locked out of my raspberry pi, because it runs in gadget mode emulating an RNDIS without IP.

9
  • Thank you RalfFriedl, for helping with the markup
    – mindforger
    Commented Feb 20, 2019 at 6:39
  • I do not understand the details of your question. What are this wait.conf and dhcpcd_boot.conf files? Where they are located? What program uses option -f? What is the line above you attached to wait.conf? What has a windows machine to do with your RasPi? What is this USB gadget RNDIS mode? I think you are using a network (wifi, wired)?
    – Ingo
    Commented Feb 21, 2019 at 19:15
  • to be most explicit, i want to run the DHCPCD service that comes native with the rasbian (and its service files) and let it try to read a config file from the /boot/ and falling back to the default config using the -foption ... but there are 2 ddifficulties, first it has to start in the wait.conf in a delayed manner (how it is actually solved with the default raspbian image) and if the file is missing or invalid, the service is not started at all .... so i wanted to know how i can modify the wait.conf to restart itself but with alternative command line parameters without the -f option
    – mindforger
    Commented Feb 26, 2019 at 14:00
  • the reason for all this is a way to be able to modify the ip configuration on the SD card via a windows PC ... i am not running any wifi or physical ethernet connection, but in the so called gadget mode, emulating an RNDIS network adapter through the USB port. And in case of an issue with IP adresses on the windows system that i attach my pi to as usb emulated RNDIS network card i want to be able to change the IP with the config from the host system ... my pi only has 2 entry points, the SDCard which i can only read the fat32 /boot/ or SSH after connecting it through USB
    – mindforger
    Commented Feb 26, 2019 at 14:02
  • You wrote: "the reason for all this is a way to be able to modify the ip configuration on the SD card via a windows PC". Is this really the only reason for all the trouble? Why don't you just ask it?
    – Ingo
    Commented Feb 26, 2019 at 15:47

2 Answers 2

1

In a comment you wrote:

the reason for all this is a way to be able to modify the ip configuration on the SD card via a windows PC

and asked for a simple solution. The problem is that MS Windows can only read the small fat boot partition and not the ext4 root partition containing the program files. But only for one configuration file like /etc/dhcpcd.conf it is no problem to move it to the boot partition and link to it on the root partition. This way you can modify it on a MS Windows PC to be used by programs looking at the root partition for its configuration files. Just do on the running RasPi:

rpi ~$ sudo mv /etc/dhcpcd.conf /boot
mv: failed to preserve ownership for '/boot/dhcpcd.conf': Operation not permitted

You can ignore the warning. It is because a fat filesystem cannot manage linux permissions. Then link to the moved file so dhcpcd can find it on its old place:

rpi ~$ sudo ln -s /boot/dhcpcd.conf /etc/dhcpcd.conf

The other way around isn't possible because fat doesn't support symlinks. That's the reason why we have to copy the file to the boot partition.

7
  • you CAN actually symlink to a non-ex partition?! I was told there is no way, because they are too dissimilar! (ike i wrote in that particular comment, i was stumped on in forums with "alternative" solutions and this was also called but mowed down by several "no can go") .... PS: i still used that other idea with the failfsafe shellscript instead of the direct command line, it works quite too
    – mindforger
    Commented Mar 1, 2019 at 7:07
  • @mindforger Yes you can. The other way around isn't possible because fat doesn't support symlinks. That's the reason why we have to copy the file to the boot partition.
    – Ingo
    Commented Mar 1, 2019 at 9:28
  • i am a bit curious, what will happen if the actual file is missing and the service is trying to create a new file? will it be created on /boot or will it overwrite the symlink? I will try to find out this weekend but if you already know i might not need to make a new SD card for this experiment :P
    – mindforger
    Commented Mar 1, 2019 at 13:21
  • @mindforger I don't know. Try it. But as far as I know dhcpcd will not create a new default /etc/hostapd.conf and it will never overwrite the symlink file. What settings should be in there? It think it will stop with an error message.
    – Ingo
    Commented Mar 1, 2019 at 13:29
  • What settings should be in there? The Pi is running as an USB Networkcard + USB Drive and i want to be able to use it on any windows PC, presenting the networkcard, a putty.exe + /boot/ access on the USB Drive Interface (maybe another /devfolder to get stuff moved over better :P) ... simply to have a pi zero ready to program and use by simply sticking it into any windows machine. But for maintenance purpose and most importantly, when i canged and forgot the last IP, i want to be able to edit the config via an SD card reader .... PS how to i linebreaks in comments?
    – mindforger
    Commented Mar 2, 2019 at 14:13
1

Not familiar with the specific service you're referring to, but in the general case, if there isn't a way to do this within systemd (I'm not aware of any), you could have systemd run a script that maintains state in a separate file, updating it as needed if the service restarts. You'll probably also need a second service, which runs before your main service at system boot, to reset the state file.

Thinking further about this, if it's a systemd-controlled service, you could use ExecStartPre to run a script that checks the wellness of the "standard" configuration. If the "standard" configuration is trashed in some way, you could then save it way (if desired) and restore it from the other location.

It is curious and concerning that this file is getting trashed in some way. That might be worth further investigation.

2
  • i am not sure what you are about, but you gave me an idea, instead of running the dhcpcd directly from the service script i could indeed run a shellscript that in his turn tries to run the actual service and if it fails, fall back to the default call ... core of my issue is i want the dhcp service, which requests and assigns my network adapter an IP, to run a config off the fat32 /boot/ partition, but if the file is damaged or missing, the service fails to run and i am locked out of my raspberry pi, because it runs in gadget mode emulating an RNDIS without IP
    – mindforger
    Commented Feb 20, 2019 at 18:45
  • It is curious and concerning that this file is getting trashed in some way. That might be worth further investigation. no, that is very common with the Pi SD Cards, they sometimes get corrupted either during a power loss or when not removed properly from the PC (and other shenanigangs i already encountered, like a faulty exfat lib stalling the drivemanager in windows, forcing a hard shutdown)
    – mindforger
    Commented Feb 26, 2019 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.