Newbie scripting advice sought (Hover DDNS &

Status
Not open for further replies.

Pseudolife

Dabbler
Joined
Jan 7, 2016
Messages
25
Hello,

I've been running a little FreeNAS box at home for about a year now, and it's generally going great. It is, however, my first introduction to FeeBSD, and frankly to (home) networking. It's been a learning experience, but right now I'm currently on lunch at work with an OpenVPN connection to my home network where I have access to my own files and network enabled systems. I'm really proud of myself for that.

In the year I've been using FreeNAS I haven't touched the scripting aspects much. I have one script (found on the forum) for doing a backup of the FreeNAS system, but that's it. I'm getting to the point where I think I need to make it do more, and I'm looking for some patient advice.

First I want to start using one of the domain names I own for my Dynamic DNS. Sadly Hover doesn't have a DDNS service, but there is an unofficial solution. Basically some people have developed various takes on a Python script that checks for current IP and then does an update. Sounds great. I don't actually know Python, so it's going to be a learning experience. From the FreeNAS side, I assume I can just make this a cron job set to go off every half hour or so. I'm guessing it should probably only edit the the DNS record if it needs to instead of writing (the typically the same) number 48 times a day.
Here are the script details:
https://jeffquast.com/post/hover-api/
https://github.com/sideshowcoder/dyn-hover
https://gist.github.com/andybarilla/b0dd93e71ff18303c059
https://gist.github.com/dankrause/5585907

Second, I'm looking to setup a docker box on my network to play with various things without risking my FreeNAS machine's stability while I learn things (likely the hard way). I was thinking I would run both the FreeNAS box and the Docker Box off the same UPS. I'd plug the UPS into the FreeNAS box so it can be shut down if the UPS kicks in and the battery runs down. I'm guessing there is a way to the "shut down scripts" option in FreeNAS to have it issue a shut down request over the network to the docker server whenever it shuts down. I have no idea how to do that in a python script, but I'm betting someone else has already done it and I'm hoping I can be pointed at a user friendly guide or existing script?

Thank you
 
Last edited:

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
Hello,

I've been running a little FreeNAS box at home for about a year now, and it's generally going great. It is, however, my first introduction to FeeBSD, and frankly to (home) networking. It's been a learning experience, but right now I'm currently on lunch at work with an OpenVPN connection to my home network where I have access to my own files and network enabled systems. I'm really proud of myself for that.

In the year I've been using FreeNAS I haven't touched the scripting aspects much. I have one script (found on the forum) for doing a backup of the FreeNAS system, but that's it. I'm getting to the point where I think I need to make it do more, and I'm looking for some patient advice.

First I want to start using one of the domain names I own for my Dynamic DNS. Sadly Hover doesn't have a DDNS service, but their is an unofficial solution. Basically some people have developed various takes on a Python script that checks for current IP and then does an update. Sounds great. I don't actually know Python, so it's going to be a learning experience. From the FreeNAS side, I assume I can just make this a cron job set to go off every half hour or so. I'm guessing it should probably only edit the the DNS record if it needs to instead of writing (the typically the same) number 48 times a day.
Here are the script details:
https://jeffquast.com/post/hover-api/
https://github.com/sideshowcoder/dyn-hover
https://gist.github.com/andybarilla/b0dd93e71ff18303c059
https://gist.github.com/dankrause/5585907

Second, I'm looking to setup a docker box on my network to play with various things without risking my FreeNAS machine's stability while I learn things (likely the hard way). I was thinking I would run both the FreeNAS box and the Docker Box off the same UPS. I'd plug the UPS into the FreeNAS box so it can be shut down if the UPS kicks in and the battery runs down. I'm guessing there is a way to the "shut down scripts" option in FreeNAS to have it issue a shut down request over the network to the docker server whenever it shuts down. I have no idea how to do that in a python script, but I'm betting someone else has already done it and I'm hoping I can be pointed at a user friendly guide or existing script?

Thank you
Can't help you with the dynamic DNS stuff, but I have a suggestion for shutting down your Docker box: set up SSH connectivity from your FreeNAS server to the Docker server -- which I presume is running Linux? -- and include a shutdown command for the Linux server as part of your FreeNAS UPS shutdown command. The script would be very simple; something like this ought to work:
Code:
#!/bin/sh

# Issue shutdown command to Linux Docker box:
ssh root@dockerbox shutdown -h now

# Shut down the FreeNAS server:
shutdown -p now
You would specify the full path to this script as the Shutdown Command: on your Services->UPS->Settings form. And of course you can tweak the shutdown command options as needed for your installation.

Refer to my "Configuring UPS support for single or multiple FreeNAS servers" resource for details on configuring the FreeNAS UPS service.

Good luck!
 

Pseudolife

Dabbler
Joined
Jan 7, 2016
Messages
25
Thank you Spearfoot! That guide you linked to looks extremely helpful. I don't have my Docker box up and running yet, but I was intending to run Linux, so this should be just what I'm looking for. Sadly some non-computer related issues will probably keep me from getting the Docker system up and running until Fall or Winter. At least now I have an idea about how it will work, so I can make sure to make a compatible system.

As for the Dynamic DNS... well I'm having some complications with getting a sub-domain made at the Hover end, so I haven't had a chance to test the script yet. I suspect it will work, but I will have to change the way Hover and my website host interact first. Alternatively I bet it would work fine if I was willing to throw an entire domain name at it instead of a sub-domain, and it may come to that.
In the meantime I continue to use a free dynamic IP service I have to re-up each month.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
Thank you Spearfoot! That guide you linked to looks extremely helpful. I don't have my Docker box up and running yet, but I was intending to run Linux, so this should be just what I'm looking for. Sadly some non-computer related issues will probably keep me from getting the Docker system up and running until Fall or Winter. At least now I have an idea about how it will work, so I can make sure to make a compatible system.

As for the Dynamic DNS... well I'm having some complications with getting a sub-domain made at the Hover end, so I haven't had a chance to test the script yet. I suspect it will work, but I will have to change the way Hover and my website host interact first. Alternatively I bet it would work fine if I was willing to throw an entire domain name at it instead of a sub-domain, and it may come to that.
In the meantime I continue to use a free dynamic IP service I have to re-up each month.
You're very welcome.

Note that you may need to insert a sleep command in the script if the Linux box is using resources (NFS or whatever) on the FreeNAS server and therefore the FreeNAS server needs to wait until the Linux server shuts down before shutting down itself. Like this:
Code:
#!/bin/sh

# Issue shutdown command to Linux Docker box:
ssh root@dockerbox shutdown -h now

# Sleep 2 minutes (as an example) waiting for the Docker box to shut down:
sleep 120

# Shut down the FreeNAS server:
shutdown -p now
Regarding dynamic DNS... I use duckdns.org for my two domains. I configure my gateway (a Peplink Balance 20) to use dnsomatic.com to automatically register IP assignment changes by my ISP. Both duckdns and dnsomatic are free, BTW. You may be able to use them to set up dynamic DNS support on your system.
 
Joined
Apr 9, 2015
Messages
1,258
Don't know about any other DDNS services but I use freedns.afraid and have a simple script setup on my FreeNAS as a cron job to update the DNS.

wget https://freedns.afraid.org/dynamic/update.php?UXXXXXXXXXXXXXXXXXXXXXOTA4OTXXXXX==

To forward a subdomain to my DDNS I put in a CNAME record to my DDNS address on my webhost but a Domain name registrar that has DNS services should be able to allow the same thing.
 

Pseudolife

Dabbler
Joined
Jan 7, 2016
Messages
25
I've figured out my issue with Dynamic DNS vs Hover: The script is not going to work because although Hover is my domain registrar, I'm actually using the name servers on my webhost.

My current options:
  1. See if my webhost has anything that will work for this. (So far nothing obvious.)
  2. Giving up on using my own sub-domain and continuing to use No-IP or some other Dynamic DNS option like I do now.
  3. Transferring all the DNS records for one domain from my host to Hover so I can use the script. This could break many things in the move, and it would make adding new subdomains in the future annoying because I would have to do the work in two places instead of one.
  4. Getting a new domain explicitly for this purpose and letting Hover handle it outright. Don't plan on using the domain for anything else.
 
Joined
Apr 9, 2015
Messages
1,258
Use the Dynamic DNS and then do a cname redirect to whatever subdomain they give you on your webhost who is handling the DNS services.. It's simple and it works perfectly. I actually use my for plex and OpenVPN connections and have had no issues. Plus it's free so it's hard to beat.
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
I would (and have) just install ubuntu in a vm in your FreeNAS box. Then run dockers to your hearts content in the vm.

Very little Chance of damaging the FreeNAS that way.
 

SweetAndLow

Sweet'NASty
Joined
Nov 6, 2013
Messages
6,421
For the ups shutdown the way you do it is through NUT. No need for fancy scripts it cron job, just use the right tool for the job. Basically you set up your docker host to monitor the freenas nut service and when that service gets notified to shutdown from the ups it sends it to all the other hosts listening.

Sent from my Nexus 5X using Tapatalk
 

Pseudolife

Dabbler
Joined
Jan 7, 2016
Messages
25
UPDATE: I actually now have an Ubuntu Server running Docker sitting next to my FreeNAS machine. It's not doing much at the moment but I have lots of plans. The FreeNAS machine is plugged into the UPS via USB and will shut itself down on a power loss that lasts long enough. The Docker machine is also plugged into same UPS, along with a switch putting them on the same wired connection into that room. Elsewhere the router and modem are plugged into a separate UPS. Basically, if the power goes out, the network doesn't immediately suffer any failures.

Unfortunately my lack of expertise is causing me a problem. I have SSH installed on the Docker box, but I can't figure out how to make a script on FreeNAS that can log into and issue Sudo commands on the Docker machine. My problem is that, SSH needs a password typed by hand (security feature) and the script can't mimic that. As of right now, if the power went out, FreeNAS would shut itself off, but Docker would stay up until the UPS runs out of power.

Apparently the standard move here is to use keys to bypass the SSH login password, but I failed to get that setup correctly. I wasn't able to find a guide that explained how to do that in this situation. Most guides talk about setting up keys so a person can SSH into a linux server, but they don't exactly line up with FreeNAS. I tried adapting some of those for making a FreeNAS server able to run an script to SSH into a linux server, but we are well beyond my comfort level, and I couldn't get it working. Right now I'm looking using sshpass instead.

On the DDNS front I've basically stuck to using the free service and simply re-upping it once a month. It's a lower priority to me at this point so I'm not going to poke at it.
 

Pseudolife

Dabbler
Joined
Jan 7, 2016
Messages
25
For the ups shutdown the way you do it is through NUT. No need for fancy scripts it cron job, just use the right tool for the job. Basically you set up your docker host to monitor the freenas nut service and when that service gets notified to shutdown from the ups it sends it to all the other hosts listening.
I wasn't aware that was possible. Could you point me in the direction of a guide on how to do that?
 

SweetAndLow

Sweet'NASty
Joined
Nov 6, 2013
Messages
6,421
Status
Not open for further replies.
Top