{"id":271,"date":"2007-07-05T14:11:48","date_gmt":"2007-07-05T11:11:48","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=271"},"modified":"2007-09-01T04:12:20","modified_gmt":"2007-09-01T01:12:20","slug":"more-netroute2-hacks-high-availability","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2007\/07\/05\/more-netroute2-hacks-high-availability\/","title":{"rendered":"more netroute2 hacks &#8211; high availability"},"content":{"rendered":"<p>The following post is going to be a one in a series of 2-3 posts regarding <a href=\"http:\/\/www.hol.gr\/netRoute2_ISDN.html\">netroute2 <\/a> (the link is in Greek) and some of my hacks\/modifications on it. All hacks refer to <a href=\"http:\/\/www.void.gr\/kargig\/blog\/2006\/12\/14\/netroute-firmware-577\/\">netroute2 firmware 577<\/a> that I have previously posted on my blog. For those who haven&#8217;t noticed yet, firmware 577 is unlocked, you can now connect to any ISP you like.<\/p>\n<p>Netroute2 has a strange bug and sometimes (not always) cannot reconnect to the ISP when the connection for some strange reason goes down. To cope with that, the netroute2 developers at <a href=\"http:\/\/www.intracom.gr\/\">Intracom<\/a> have created a script named <strong>high_avail<\/strong> that runs every 5 minutes from crontab. For some even stranger reason this script did not work for me as it should, so I patched it to make it _always_ work. <\/p>\n<p>The problem I faced at the very beggining was that the &#8220;high_avail&#8221; script resided in the read-only section of netroute2&#8217;s flash (\/usr\/bin\/high_avail). My solution to that problem was to create a directory named <strong>\/etc\/bin\/<\/strong> and store there all my new scripts and changes since the \/etc dir is writable. <\/p>\n<p>My changes to the high_avail script are these:<br \/>\n<code>--- usr\/bin\/high_avail  2007-07-03 20:59:21.000000000 +0300<br \/>\n+++ etc\/bin\/high_avail  2007-07-04 03:31:54.000000000 +0300<br \/>\n@@ -15,25 +15,32 @@<br \/>\n if [ -s \/var\/run\/dial ]; then<br \/>\n        act_conn=`$CAT \/var\/run\/dial`<br \/>\n fi<br \/>\n-adsl_iface=$ADSL_BASE<br \/>\n+if [ -z \"$act_conn\" ]; then<br \/>\n+       act_conn=\"\/etc\/wan\/current\/CHANGEME\"<br \/>\n+fi<br \/>\n+<br \/>\n+adsl_iface=$ADSL_BASE<br \/>\n+echo \"$act_conn\"<br \/>\n reload_module() {<br \/>\n        \/bin\/hangup<br \/>\n+       killall -9 pppd<br \/>\n+       ifconfig eth2 down<br \/>\n        \/sbin\/rmmod $loaded_mod<br \/>\n        if [ $? -eq 0 ]; then<br \/>\n                $ECHO \"done\"<br \/>\n        else<br \/>\n                $ECHO \"failed\"<br \/>\n                $ECHO \"ERROR: high_avail: Failed to unload $loaded_mod\"<br \/>\n-               exit 13<br \/>\n+#              exit 13<br \/>\n        fi<br \/>\n-       [ -n \"$act_conn\" ] && \/usr\/bin\/dial $act_conn<br \/>\n+       [ -n \"$act_conn\" ] && \/etc\/bin\/dial $act_conn<br \/>\n }<br \/>\n HIGH_AVAIL_IP=`$GREP HIGH_AVAIL_IP \/etc\/net.conf | $CUT -d'=' -f2`<br \/>\n-<br \/>\n #Check Current Modem status<br \/>\n if [ -z \"$loaded_mod\" ]; then<br \/>\n        $ECHO \"high_avail: No Module found loaded.\"<br \/>\n+       reload_module<br \/>\n        exit 1<br \/>\n elif [ \"`\/usr\/bin\/modem_wrap halt`\" = \"yes\" ]; then<br \/>\n        $ECHO \"high_avail: Module $loaded_mod found in HALTED state\"<br \/>\n@@ -41,6 +48,7 @@<br \/>\n        exit 11<br \/>\n elif [ -z \"$act_conn\" ]; then<br \/>\n        $ECHO \"high_avail: No WAN Connection dialed ...\"<br \/>\n+       reload_module<br \/>\n        exit 2<br \/>\n elif [ -z \"$HIGH_AVAIL_IP\" ]; then<br \/>\n        $ECHO \"high_avail: No Ping Target IP Found ...\"<br \/>\n<\/code><\/p>\n<p>and the whole new script resides here: <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/high_avail.gz' title=''><strong>\/etc\/bin\/high_avail<\/strong><\/a>. (You need to gunzip it).<\/p>\n<p>What you <strong>need<\/strong> to change for your connection is the part that says <strong>CHANGEME<\/strong>. You can replace that with what you can find inside the \/etc\/wan\/current\/ directory.<\/p>\n<p>I noticed that when the module for the modem was loaded then the modem was unable to reconnect to the ISP, but upon unloading and reloading of the module, and then trying to connect again, all came back to normal. So what I changed in the high_avail script was making sure the module gets unloaded properly and reloaded when there&#8217;s no connection active.<\/p>\n<p>One might notice that inside <strong>high_avail<\/strong> I&#8217;ve also changed a path from \/usr\/bin\/dial to <strong>\/etc\/bin\/dial<\/strong>.<br \/>\nThis script is used to call another script that actually makes the call to the isp. <\/p>\n<p><code>--- usr\/bin\/dial        2007-07-03 21:00:13.000000000 +0300<br \/>\n+++ etc\/bin\/dial        2007-07-04 03:39:45.000000000 +0300<br \/>\n@@ -1,25 +1,16 @@<br \/>\n #!\/bin\/sh<br \/>\n ECHO=\/bin\/echo<br \/>\n-<br \/>\n conn=\"$1\"<br \/>\n #ATM encapsulation mode for modem<br \/>\n encmode=0<br \/>\n-<br \/>\n $ECHO \"Dialing $conn ....\"<br \/>\n-<br \/>\n if [ $# -lt 1 -o ! -e $conn ]; then<br \/>\n-<br \/>\n        $ECHO \"Usage: dial &lt;connection&gt; [ppp_option]\"<br \/>\n        $ECHO \"connection:    connection name\"<br \/>\n        $ECHO \"[ppp_option]:    optional argument passed to PPPD\"<br \/>\n-<br \/>\n        exit 1<br \/>\n-<br \/>\n else<br \/>\n-<br \/>\n        #Bring down previous processes<br \/>\n        \/bin\/hangup<br \/>\n-<br \/>\n-       \/usr\/bin\/dial_conn $conn primary_conn $2<br \/>\n-<br \/>\n+       \/etc\/bin\/dial_conn $conn primary_conn $2<br \/>\n fi<br \/>\n<\/code><\/p>\n<p>These are my changes to \/usr\/bin\/dial script that is now placed under <strong>\/etc\/bin\/dial<\/strong><br \/>\nThe whole scripts resides here: <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/dial.gz' title=''><strong>\/etc\/bin\/dial<\/strong><\/a>. (You need to gunzip it).<\/p>\n<p>As said before, this script in turn calls another one, <strong>dial_conn<\/strong> which is used to actually make the call. My changes to \/usr\/bin\/dial_conn which now becomes \/etc\/bin\/dial_conn:<\/p>\n<p><code><br \/>\n--- usr\/bin\/dial_conn   2007-07-03 21:00:13.000000000 +0300<br \/>\n+++ etc\/bin\/dial_conn   2007-07-04 03:43:11.000000000 +0300<br \/>\n@@ -154,14 +154,13 @@<br \/>\n                                exit 1<br \/>\n                        fi<br \/>\n                done<br \/>\n-<br \/>\n        fi<br \/>\n-<br \/>\n        if [ \"$2\" = \"primary_conn\" ]; then<br \/>\n                #Start the high-availability service<br \/>\n-               $ECHO \"*\/5 * * * * root $PIDOF high_avail > \/dev\/null 2>&1 || \/usr\/bin\/high_avail > \/var\/run\/high_avail 2>&1\" > \/etc\/cron.d\/cron_high_avail<br \/>\n+               $ECHO \"*\/5 * * * * root $PIDOF high_avail > \/dev\/null 2>&1 || \/etc\/bin\/high_avail > \/var\/run\/high_avail 2>&1\" > \/etc\/cron.d\/cron_high_avail<br \/>\n                $CHMOD 755 \/etc\/cron.d\/cron_high_avail<br \/>\n        fi<br \/>\n-<br \/>\n+       sleep 5<br \/>\n+       #\/etc\/bin\/wshaper ppp0 192 1024<br \/>\n        exit 0<br \/>\n fi<br \/>\n<\/code><\/p>\n<p>the whole file resides here: <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/dial_conn.gz' title=''><strong>\/etc\/bin\/dial_conn<\/strong><\/a>. (You need to gunzip it).<\/p>\n<p>What I&#8217;ve changed here is the line that gets stored on crontab and calls the <strong>high_avail<\/strong> script every 5 minutes to check whether our connection is active or not. The rest of the changes will be the subject of the next post about netroute2 on this blog.<\/p>\n<p>What is left now is to make netroute2 calls these new scripts from \/etc\/bin\/ on boot instead of the ones from \/usr\/bin.<\/p>\n<p>a) Copy \/bin\/dial_current to \/etc\/bin\/dial_current, edit it with vi and go to line 5 and change the line that says \/usr\/bin\/dial with <strong>\/etc\/bin\/dial<\/strong>.<br \/>\nb) Edit \/etc\/init.d\/rc-run, go to line 243 and change all occurences of \/bin\/dial_current with <strong>\/etc\/bin\/dial_current<\/strong>. There must be 2.<br \/>\nc) Edit <strong>\/etc\/rc.d\/rc.dialcurrent<\/strong> with vi, go to line 8 and change \/usr\/bin\/dial to <strong>\/etc\/bin\/dial<\/strong>.<\/p>\n<p>So, if you have done it right, you should now have 4 scripts inside your netroute2&#8217;s \/etc\/bin:<br \/>\na) <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/high_avail.gz' title=''><strong>\/etc\/bin\/high_avail<\/strong><\/a><br \/>\nb) <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/dial.gz' title=''><strong>\/etc\/bin\/dial<\/strong><\/a><br \/>\nc) <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/dial_conn.gz' title=''><strong>\/etc\/bin\/dial_conn<\/strong><\/a><br \/>\nd) <a href='http:\/\/www.void.gr\/kargig\/blog\/wp-content\/dial_current.gz' title=''><strong>\/etc\/bin\/dial_current<\/strong><\/a><br \/>\nand you should have also changed 2 scripts, \/etc\/init.d\/rc-run and \/etc\/rc.d\/rc.dialcurrent<\/p>\n<p>That&#8217;s all. Now save your changes with <strong>\/etc\/init.d\/checkpoint<\/strong> and upon reboot your modem will have a nice new high_avail script that will (hopefully) always  work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following post is going to be a one in a series of 2-3 posts regarding netroute2 (the link is in Greek) and some of my hacks\/modifications on it. All hacks refer to netroute2 firmware 577 that I have previously posted on my blog. For those who haven&#8217;t noticed yet, firmware 577 is unlocked, you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[5,3,8],"tags":[],"class_list":["post-271","post","type-post","status-publish","format-standard","hentry","category-internet","category-linux","category-networking"],"aioseo_notices":[],"views":4717,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=271"}],"version-history":[{"count":0,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/271\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}