I run a node.js server on an embedded device which provides a web UI to allow users to modify network interface settings - for example, changing from Static to DHCP or vice versa, or setting specific Static IP settings (netmask, gatetway), etc. With these user-driven configuration parameters, I am able to programmatically generate a new /etc/network/interfaces file (of course, after backing the previous file to /etc/network/interfaces.bak file). I even do a 'cat /etc/network/interfaces' to the log file of the new configuration file to confirm the new interfaces file's contents and syntactic validity. So far, everything is hunky-dory.
However, if there is a reboot on my device (with or without a /etc/init.d/networking stop/start prior to reboot), I find that many times the system comes up with an empty /etc/network/interfaces file and, therefore, no network interfaces. (Fortunately, I have a JTAG interface allowing SSH connection and so still have connection to my device but to users their device is essentially bricked.)
What would cause the OS to blank the /etc/network/interfaces file? I think this must be done during system initialization - but for what reason?
If I make the same changes manually using a text editor and reboot, everything is fine - the new interface settings come up every time.
I am at a loss to explain what might be causing this behavior.
Here are other factors that I considered but have ruled out:
It's possible that the modified file wasn't flushed to the disk and remained in a cache. The
cat command could have read the file from that cache.
sync (see here) to force a flush to the underlying storage.