Network Mounts Randomly Dropping

Network Mounts Randomly Dropping
Photo by Explore with Joshua / Unsplash

So I have noticed a few times where my CIFS mounts on my linux servers crash whenever my fileserver reboots. It's a shame they don't detect when the connection drops and then try to re-establish it. Then again my fileserver does not reboot very frequently, pretty much only for security updates. So far I have been simply rebooting the Linux servers after my fileserver comes back up. I am currently doing this manually, but that would become quite a large trouble if I make more servers mount to my fileserver.

So can I automate this and set up a script to reboot those services and their servers? It would be great if I could have it be a timed event, say 15 minutes after the fileserver comes back online. I'm certain I can make this happen with a PowerShell script and Task Scheduler's after boot option.

With OpenSSH baked into Windows now I can SSH directly from PowerShell using a command like ssh [username@FQDN].

One sticking point I come across is OpenSSH from inside PowerShell won't take passwords so I can't have it run a sudo reboot command and then have it enter the credentials. I'm sure there might be a way to have a command reference the password in a hidden file but I'm having trouble wrapping my brain around the concept right now. Alternatively, I could edit /etc/sudoers with david ALL=NOPASSWD: /sbin/halt, /sbin/reboot /sbin/shutdown. This would allow the command sudo reboot to run without a password prompt and complete the reboot. If my david account was to be compromised the risk is pretty minimal because they would still need my sudo password for any other sudo commands. Yes they could harass me by rebooting or shutting down my server but that would really only alert me to their presence right?

I begin to write out my first draft of the script, but the reboot command does not work. It is still asking for the password. Annoying. I'm out of time for today so I'll have to come back to this tomorrow.