Would you please consider accepting the following patch, it does the following:
- Changes '] > ’ to stop rancid (configuration revision management) matching it to the RouterOS prompt.
- Changes netmask from /24 to /29 and moved VRRP IP from .10 to .3.
- Set schedulers’ start date to Unix Epoch (Jan/01/1970).
- Set schedulers’ intervals and start time to prevent overlapping.
- Only change FTP service, prevents SSH not being reachable on master or enabling Telnet.
- Replaces hard coded values with variables.
- Disables adding default route (makes loopback interfaces reachable).
- Disables silencing Routerboard boot process by default and handle errors (eg VM)
--- HA_init.rsc 2018-02-18 08:54:22.000000000 +0200
+++ ../../HA_init.rsc 2018-02-18 09:32:25.000000000 +0200
@@ -1,7 +1,7 @@
:do {
/system script
remove [find name=ha_checkchanges_new]
-add name=ha_checkchanges_new owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":if ([:len [/system script job find where script=\"ha_checkchanges\"]] > 1) do={:error \"already running checkchanges\"; } \
+add name=ha_checkchanges_new owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":if ([:len [/system script job find where script=\"ha_checkchanges\"]] > 1) do={:error \"already running checkchanges\"; } \
\n:global isMaster\
\n:global isStandbyInSync\
\n:global haPassword\
@@ -39,11 +39,11 @@
remove [find name=ha_config_new]
add name=ha_config_new owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source="/system script run [find name=\"ha_config_base\"]\
\n:global haNetwork \"169.254.23.0\"\
- \n:global haNetmask \"255.255.255.0\"\
- \n:global haNetmaskBits \"24\"\
+ \n:global haNetmask \"255.255.255.248\"\
+ \n:global haNetmaskBits \"29\"\
\n:global haAddressA \"169.254.23.1\"\
\n:global haAddressB \"169.254.23.2\"\
- \n:global haAddressVRRP \"169.254.23.10\""
+ \n:global haAddressVRRP \"169.254.23.3\""
remove [find name=ha_functions_new]
add name=ha_functions_new owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":global HADebug do={\
\n :put \$1\
@@ -103,7 +103,7 @@
\n :error \"Are you sure the other device is configured properly? I am unable to ping MAC \$pingMac\"\
\n}\
\n\
- \n:if ([:len [/ip address find where interface=\"\$haInterface\" and comment!=\"HA_AUTO\"]] > 0) do {\
+ \n:if ([:len [/ip address find where interface=\"\$haInterface\" and comment!=\"HA_AUTO\"]] > 0) do {\
\n :error \"Interface \$haInterface has IP addresses. HA should completely own the interface and it cannot be used by anything else. Please correct\"\
\n}\
\n\
@@ -155,7 +155,7 @@
\n:execute \"ha_setidentity\"\
\n:do { :local k [/system script find name=\"on_master\"]; if ([:len \$k] = 1) do={ /system script run \$k } } on-error={ :put \"on_master failed\" }"
remove [find name=ha_pushbackup_new]
-add name=ha_pushbackup_new owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":if ([:len [/system script job find where script=\"ha_pushbackup\"]] > 1) do={:error \"already running pushbackup\"; } \
+add name=ha_pushbackup_new owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":if ([:len [/system script job find where script=\"ha_pushbackup\"]] > 1) do={:error \"already running pushbackup\"; } \
\n:global haPassword\
\n:global isMaster\
\n:global haAddressOther\
@@ -247,7 +247,7 @@
\n}\
\n/log warning \"ha_startup: 0.3\"\
\n/interface ethernet disable [find]\
- \n:global haStartupHAVersion \"0.2alpha - ea961767e45b63b81aac87eed37301d8b70bedf7\"\
+ \n:global haStartupHAVersion \"0.2alpha - 858dc62b5a9e215a5e5896137a053d01d16695c6\"\
\n:global isStandbyInSync false\
\n:global isMaster false\
\n:global haPassword\
@@ -268,7 +268,7 @@
\n/system scheduler remove [find comment=\"HA_AUTO\"]\
\n\
\n#Pause on-error just in case we error out before the spin loop - hope 5 seconds is enough.\
- \n/system scheduler add comment=HA_AUTO name=ha_startup on-event=\":do {:global haInterface; /system script run [find name=ha_startup]; } on-error={ :delay 5; /interface ethernet disable [find default-name!=\\\"\\\$haInterface\\\"]; /log error \\\"ha_startup: FAILED - DISABLED ALL INTERFACES\\\" }\" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup \
+ \n/system scheduler add comment=HA_AUTO name=ha_startup on-event=\":do {:global haInterface; /system script run [find name=ha_startup]; } on-error={ :delay 5; /interface ethernet disable [find default-name!=\\\"\\\$haInterface\\\"]; /log error \\\"ha_startup: FAILED - DISABLED ALL INTERFACES\\\" }\" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=startup \
\n\
\n#/interface ethernet reset-mac-address\
\n/ip address remove [find interface=\"\$haInterface\"]\
@@ -315,8 +315,8 @@
\n }\
\n}\
\n\
- \n/ip route remove [find comment=\"HA_AUTO\"] \
- \n/ip route add gateway=\$haAddressOther distance=250 comment=HA_AUTO\
+ \n#/ip route remove [find comment=\"HA_AUTO\"] \
+ \n#/ip route add gateway=\$haAddressOther distance=250 comment=HA_AUTO\
\n\
\n/log warning \"ha_startup: 4\"\
\n\
@@ -337,10 +337,10 @@
\n/ip address add address=\$haAddressVRRP netmask=255.255.255.255 interface=HA_VRRP comment=\"HA_AUTO\"\
\n\
\n/log warning \"ha_startup: 6\"\
- \n/system scheduler add comment=HA_AUTO interval=30m name=ha_exportcurrent on-event=\"/export file=\\\"HA_current.rsc\\\"\" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/20/2000 start-time=22:37:10\
- \n/system scheduler add interval=10m name=ha_checkchanges on-event=ha_checkchanges policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/1/2000 start-time=18:00:30 comment=HA_AUTO\
+ \n/system scheduler add comment=HA_AUTO interval=10m name=ha_exportcurrent on-event=\"/export file=\\\"HA_current.rsc\\\"\" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=00:05:00\
+ \n/system scheduler add interval=10m name=ha_checkchanges on-event=ha_checkchanges policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=00:10:00 comment=HA_AUTO\
\n#Still need this - things like DHCP leases dont cause a system config change, we want to backup periodically.\
- \n/system scheduler add comment=HA_AUTO interval=24h name=ha_auto_pushbackup on-event=ha_pushbackup policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/20/2000 start-time=05:00:00\
+ \n/system scheduler add comment=HA_AUTO interval=24h name=ha_auto_pushbackup on-event=ha_pushbackup policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=05:00:00\
\n/log warning \"ha_startup: 7\"\
\n:if ([:len [/file find name=\"HA_dsa\"]] = 1) do={\
\n /ip ssh import-host-key private-key-file=HA_rsa\
@@ -352,9 +352,9 @@
\n/user add address=\"\$haNetwork/\$haNetmaskBits\" comment=HA_AUTO group=full name=ha password=\"\$haPassword\"\
\n/log warning \"ha_startup: 8\"\
\n#So you dont get annoyed with constant beeping\
- \n/system routerboard settings set silent-boot=yes\
+ \n#:do {/system routerboard settings set silent-boot=yes} on-error={};\
\n\
- \n:foreach service in [:toarray \"ftp,telnet,ssh\"] do={\
+ \n:foreach service in [:toarray \"ftp\"] do={\
\n :local serviceAddresses \"\"\
\n :foreach k in=[/ip service get [find name=\$service] address] do={\
\n :if (\$k != \"\$haAddressA/32\" and \$k != \"\$haAddressB/32\" and \$k != \"\$haAddressVRRP/32\") do {\
@@ -365,7 +365,7 @@
\n /ip service set [find name=\$service] address=[:toarray \$serviceAddresses]\
\n}\
\n\
- \n:if ([:len [/file find where name=\"HA_run-after-hastartup.rsc\"]] > 0) do {\
+ \n:if ([:len [/file find where name=\"HA_run-after-hastartup.rsc\"]] > 0) do {\
\n /import HA_run-after-hastartup.rsc\
\n}\
\n/delay 5\
@@ -388,7 +388,7 @@
\n /system script run [find name=\"ha_pushbackup\"]\
\n :put \"delaying 60\"\
\n /delay 60\
- \n :if (\$isMaster && [/ping 169.254.23.3 count=1 interface=ether1 ttl=1] >= 1) do {\
+ \n :if (\$isMaster && [/ping \$haAddressOther count=1 interface=\$haInterface ttl=1] >= 1) do {\
\n :put \"REBOOTING MYSELF\"\
\n :execute \"/system reboot\"\
\n } else {\
diff -uNr scripts/ha_checkchanges.script ../../scripts/ha_checkchanges.script
--- scripts/ha_checkchanges.script 2018-02-17 11:58:46.000000000 +0200
+++ ../../scripts/ha_checkchanges.script 2018-02-17 12:35:29.000000000 +0200
@@ -1,4 +1,4 @@
-:if ([:len [/system script job find where script="ha_checkchanges"]] > 1) do={:error "already running checkchanges"; }
+:if ([:len [/system script job find where script="ha_checkchanges"]] > 1) do={:error "already running checkchanges"; }
:global isMaster
:global isStandbyInSync
:global haPassword
diff -uNr scripts/ha_config.script ../../scripts/ha_config.script
--- scripts/ha_config.script 2018-02-18 08:54:28.000000000 +0200
+++ ../../scripts/ha_config.script 2018-02-18 08:54:06.000000000 +0200
@@ -1,7 +1,7 @@
/system script run [find name="ha_config_base"]
:global haNetwork "169.254.23.0"
-:global haNetmask "255.255.255.0"
-:global haNetmaskBits "24"
+:global haNetmask "255.255.255.248"
+:global haNetmaskBits "29"
:global haAddressA "169.254.23.1"
:global haAddressB "169.254.23.2"
-:global haAddressVRRP "169.254.23.10"
\ No newline at end of file
+:global haAddressVRRP "169.254.23.3"
\ No newline at end of file
diff -uNr scripts/ha_install.script ../../scripts/ha_install.script
--- scripts/ha_install.script 2018-02-17 12:13:18.000000000 +0200
+++ ../../scripts/ha_install.script 2018-02-17 12:37:49.000000000 +0200
@@ -29,7 +29,7 @@
:error "Are you sure the other device is configured properly? I am unable to ping MAC $pingMac"
}
-:if ([:len [/ip address find where interface="$haInterface" and comment!="HA_AUTO"]] > 0) do {
+:if ([:len [/ip address find where interface="$haInterface" and comment!="HA_AUTO"]] > 0) do {
:error "Interface $haInterface has IP addresses. HA should completely own the interface and it cannot be used by anything else. Please correct"
}
diff -uNr scripts/ha_pushbackup.script ../../scripts/ha_pushbackup.script
--- scripts/ha_pushbackup.script 2018-02-17 12:13:47.000000000 +0200
+++ ../../scripts/ha_pushbackup.script 2018-02-17 12:38:25.000000000 +0200
@@ -1,4 +1,4 @@
-:if ([:len [/system script job find where script="ha_pushbackup"]] > 1) do={:error "already running pushbackup"; }
+:if ([:len [/system script job find where script="ha_pushbackup"]] > 1) do={:error "already running pushbackup"; }
:global haPassword
:global isMaster
:global haAddressOther
diff -uNr scripts/ha_startup.script ../../scripts/ha_startup.script
--- scripts/ha_startup.script 2018-02-17 12:39:39.000000000 +0200
+++ ../../scripts/ha_startup.script 2018-02-18 09:32:33.000000000 +0200
@@ -35,7 +35,7 @@
/system scheduler remove [find comment="HA_AUTO"]
#Pause on-error just in case we error out before the spin loop - hope 5 seconds is enough.
-/system scheduler add comment=HA_AUTO name=ha_startup on-event=":do {:global haInterface; /system script run [find name=ha_startup]; } on-error={ :delay 5; /interface ethernet disable [find default-name!=\"\$haInterface\"]; /log error \"ha_startup: FAILED - DISABLED ALL INTERFACES\" }" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
+/system scheduler add comment=HA_AUTO name=ha_startup on-event=":do {:global haInterface; /system script run [find name=ha_startup]; } on-error={ :delay 5; /interface ethernet disable [find default-name!=\"\$haInterface\"]; /log error \"ha_startup: FAILED - DISABLED ALL INTERFACES\" }" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=startup
#/interface ethernet reset-mac-address
/ip address remove [find interface="$haInterface"]
@@ -82,8 +82,8 @@
}
}
-/ip route remove [find comment="HA_AUTO"]
-/ip route add gateway=$haAddressOther distance=250 comment=HA_AUTO
+#/ip route remove [find comment="HA_AUTO"]
+#/ip route add gateway=$haAddressOther distance=250 comment=HA_AUTO
/log warning "ha_startup: 4"
@@ -104,10 +104,10 @@
/ip address add address=$haAddressVRRP netmask=255.255.255.255 interface=HA_VRRP comment="HA_AUTO"
/log warning "ha_startup: 6"
-/system scheduler add comment=HA_AUTO interval=30m name=ha_exportcurrent on-event="/export file=\"HA_current.rsc\"" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/20/2000 start-time=22:37:10
-/system scheduler add interval=10m name=ha_checkchanges on-event=ha_checkchanges policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/1/2000 start-time=18:00:30 comment=HA_AUTO
+/system scheduler add comment=HA_AUTO interval=10m name=ha_exportcurrent on-event="/export file=\"HA_current.rsc\"" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=00:05:00
+/system scheduler add interval=10m name=ha_checkchanges on-event=ha_checkchanges policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=00:10:00 comment=HA_AUTO
#Still need this - things like DHCP leases dont cause a system config change, we want to backup periodically.
-/system scheduler add comment=HA_AUTO interval=24h name=ha_auto_pushbackup on-event=ha_pushbackup policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/20/2000 start-time=05:00:00
+/system scheduler add comment=HA_AUTO interval=24h name=ha_auto_pushbackup on-event=ha_pushbackup policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=Jan/01/1970 start-time=05:00:00
/log warning "ha_startup: 7"
:if ([:len [/file find name="HA_dsa"]] = 1) do={
/ip ssh import-host-key private-key-file=HA_rsa
@@ -119,9 +119,9 @@
/user add address="$haNetwork/$haNetmaskBits" comment=HA_AUTO group=full name=ha password="$haPassword"
/log warning "ha_startup: 8"
#So you dont get annoyed with constant beeping
-/system routerboard settings set silent-boot=yes
+#:do {/system routerboard settings set silent-boot=yes} on-error={};
-:foreach service in [:toarray "ftp,telnet,ssh"] do={
+:foreach service in [:toarray "ftp"] do={
:local serviceAddresses ""
:foreach k in=[/ip service get [find name=$service] address] do={
:if ($k != "$haAddressA/32" and $k != "$haAddressB/32" and $k != "$haAddressVRRP/32") do {
@@ -132,7 +132,7 @@
/ip service set [find name=$service] address=[:toarray $serviceAddresses]
}
-:if ([:len [/file find where name="HA_run-after-hastartup.rsc"]] > 0) do {
+:if ([:len [/file find where name="HA_run-after-hastartup.rsc"]] > 0) do {
/import HA_run-after-hastartup.rsc
}
/delay 5
diff -uNr scripts/ha_switchrole.script ../../scripts/ha_switchrole.script
--- scripts/ha_switchrole.script 2018-02-17 12:14:19.000000000 +0200
+++ ../../scripts/ha_switchrole.script 2018-02-18 09:17:57.000000000 +0200
@@ -4,7 +4,7 @@
/system script run [find name="ha_pushbackup"]
:put "delaying 60"
/delay 60
- :if ($isMaster && [/ping 169.254.23.3 count=1 interface=ether1 ttl=1] >= 1) do {
+ :if ($isMaster && [/ping $haAddressOther count=1 interface=$haInterface ttl=1] >= 1) do {
:put "REBOOTING MYSELF"
:execute "/system reboot"
} else {