2

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:

  • Perhaps the file isn't saved properly? I've ruled this out because the cat command would indicate it was successfully saved.
  • Perhaps there are other files (or persistent settings) that need to be modified, without which the configuration is considered invalid and blanked? I've ruled this out because my understanding is that the interfaces file is the only configuration required for interface setup.
  • Perhaps there are syntatic errors in the interfaces file. I've ruled this out because I've compared my programmatic output to valid files and things look fine. Furthermore, I don't think syntatic errors would cause a file to be blanked.

EDIT: My device is based on a TI Sitara uP running a Debian Wheezy 3.14 variant. I run node.js v0.12.x as the server backend.

HiDefLoLife
  • 555
  • 1
  • 8
  • 28
  • Maybe file wasn't flushed to the disk. The `cat` could work from a cache. See whether `sync` (https://stackoverflow.com/questions/2384202/how-to-flush-cache-of-hard-disk-and-flash-disk-or-filesystem-from-command-line) makes a difference. – Malt Jun 07 '16 at 19:08
  • @Malt, can you pose this as an answer - I've run some tests using 'sync' as a programmatic step in my server's network configuration process and everything appears to be working. I'd like to acknowledge your contribution - much appreciated! I'm sure that as answer, it will be useful for others down the road too. – HiDefLoLife Jun 07 '16 at 20:10
  • I think it would be useful for future readers to add the make and model of your embedded device as well as the OS you're running. Others might run into the same issue with various other files. – Malt Jun 07 '16 at 20:27

1 Answers1

2

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.

Try using sync (see here) to force a flush to the underlying storage.

Malt
  • 28,965
  • 9
  • 65
  • 105
  • As Malt suspected, it appears that node.js' fs.write command was never fully committed to the disk - but issuing a sync command was able to ensure saving the file to disk, so it was there after reboot. – HiDefLoLife Jun 07 '16 at 20:26