{"id":244,"date":"2012-10-02T15:17:33","date_gmt":"2012-10-02T13:17:33","guid":{"rendered":"http:\/\/clark.tipistrani.it\/?p=244"},"modified":"2012-10-02T15:17:33","modified_gmt":"2012-10-02T13:17:33","slug":"etcinit-ducarp","status":"publish","type":"post","link":"http:\/\/clark.tipistrani.it\/?p=244","title":{"rendered":"\/etc\/init.d\/ucarp"},"content":{"rendered":"<p>Master<\/p>\n<p>#!\/bin\/sh<\/p>\n<p>PATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin:\/\/usr\/local\/sbin:\/usr\/local\/bin<br \/>\n#set to -P if you want this to be the preferred master<br \/>\nPREEMPT=-P<br \/>\n#Log to \/var\/log\/messages<br \/>\nLOG=syslog<br \/>\nFAILOVER_ID=10<br \/>\nSHARED_SECRET=passwordsupersecret<br \/>\nVIRTUAL_IP=192.168.2.241<br \/>\nREAL_IP=192.168.2.240<br \/>\nINTERFACE=eth1<br \/>\nVIP_UP_SCRIPT=\/etc\/ucarp\/ucarp-up.sh<br \/>\nVIP_DOWN_SCRIPT=\/etc\/ucarp\/ucarp-down.sh<br \/>\nUCARP_PIDFILE=\/var\/run\/ucarp.pid<\/p>\n<p>OPTIONS=&#8221;-B -v $FAILOVER_ID -p $SHARED_SECRET -a $VIRTUAL_IP -s $REAL_IP -i $INTERFACE \\<br \/>\n-u $VIP_UP_SCRIPT -d $VIP_DOWN_SCRIPT $PREEMPT -k 0 -b 1 -z -f $LOG&#8221;<\/p>\n<p>test -x \/usr\/sbin\/ucarp || exit 0<\/p>\n<p>case &#8220;$1&#8221; in<br \/>\nstart)<\/p>\n<p>if [ ! -x \/usr\/sbin\/ucarp ]; then<br \/>\necho &#8220;ucarp binary missing &#8211; not starting&#8221;<br \/>\nexit 1<br \/>\nfi<br \/>\nif ( ! pgrep -f \/usr\/sbin\/ucarp )<br \/>\nthen<br \/>\necho -n &#8220;Starting ucarp service: ucarp&#8221;<br \/>\nstart-stop-daemon &#8211;start &#8211;make-pidfile &#8211;pidfile\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ${UCARP_PIDFILE} &#8211;quiet &#8211;exec \/usr\/sbin\/ucarp \\<br \/>\n&#8212; $OPTIONS<br \/>\nelse<br \/>\necho &#8220;ucarp is running, not starting&#8221;<br \/>\nfi<br \/>\necho &#8220;.&#8221;<br \/>\n;;<\/p>\n<p>stop)<br \/>\necho -n &#8220;Stopping ucarp service: ucarp&#8221;<br \/>\nrm -f \/var\/run\/ukarp.pid &amp;&amp; killall ucarp<br \/>\necho &#8220;.&#8221;<br \/>\n;;<\/p>\n<p>restart|force-reload)<br \/>\n$0 stop<br \/>\nsleep 2<br \/>\n$0 start<br \/>\n;;<\/p>\n<p>*)<br \/>\necho &#8220;Usage: \/etc\/init.d\/ucarp {start|stop|restart|force-reload}&#8221; &gt;&amp;2<br \/>\nexit 1<br \/>\n;;<br \/>\nesac<\/p>\n<p>exit 0<\/p>\n<p>La linea importante \u00e8 quella OPTIONS che analizziamo a fondo<br \/>\nl&#8217;opzione -B \u00e8 quella che demonizza ucarp cio\u00e8 in parole povere lo fa girare in background.<br \/>\nL&#8217;opzione -v definisce la virtual id ed \u00e8 un valore numerico compreso tra tra 1 e 255 deve essere uguale su entrambe le macchine ci possono essere pi\u00f9 virtual id.<br \/>\nL&#8217;opzione -p definisce la password sharata che deve ovviamente essere identica su ambo le macchine eche non viene trasmessa in chiaro.<br \/>\nL&#8217;opzione -a\u00a0 definisce l&#8217;Ip virtuale.<br \/>\nL&#8217;opzione -s definisce l&#8217;IP reale della scheda su cui si genera il virtual IP.<br \/>\nL&#8217;opzione -i definisce l&#8217;interfaccia su cui si opera.<br \/>\nL&#8217;opzione -u definisce l&#8217;up script che vedremo in dettaglio dopo.<br \/>\nL&#8217;opzione -d definisce il down script che vedremo in dettaglio dopo.<br \/>\nL&#8217;opzione -P definisce il Preempt cio\u00e8 porta la macchiana a fare il take per diventare master,<br \/>\nL&#8217;opzione -k 0 definisce l&#8217;Advertisement skew cio\u00e8, la &#8220;diciamo&#8221; priorit\u00e0 con cui la macchina viene eletta master\u00a0 a valori bassi di k corrisponde alta probabilit\u00e0 che la macchina faccia il take come master il valore e \u00e8 compreso 0 e 255 il default \u00e8 0 \u00e8 sicuramente meglio mettercelo lo 0 semplifica non di poco la vita.<br \/>\nL&#8217;opzione -z \u00e8 il compendio dell&#8217;opzione -d<br \/>\nL&#8217;opzione -f definisce la facilitazione per il syslog.<br \/>\nQui i parametri -k 0 e -b 1 forzano la macchina a Master<\/p>\n<p>slave<\/p>\n<p>#!\/bin\/sh<\/p>\n<p>PATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin:\/usr\/local\/bin:\/usr\/local\/sbin<br \/>\n#set to -P if you want this to be the preferred master<br \/>\nPREEMPT=-P<br \/>\n#Log to \/var\/log\/messages<br \/>\nLOG=syslog<br \/>\nFAILOVER_ID=10<br \/>\nSHARED_SECRET=passwordsupersecret<br \/>\nVIRTUAL_IP=192.168.2.241<br \/>\nREAL_IP=192.168.2.5<br \/>\nINTERFACE=eth1<br \/>\nVIP_UP_SCRIPT=\/etc\/ucarp\/ucarp-up.sh<br \/>\nVIP_DOWN_SCRIPT=\/etc\/ucarp\/ucarp-down.sh<br \/>\nUCARP_PIDFILE=\/var\/run\/ucarp.pid<br \/>\nOPTIONS=&#8221;-B -v $FAILOVER_ID -p $SHARED_SECRET -a $VIRTUAL_IP -s $REAL_IP -i $INTERFACE \\<br \/>\n-u $VIP_UP_SCRIPT -d $VIP_DOWN_SCRIPT $PREEMPT -k 200 -b 5 -z -f $LOG&#8221;<\/p>\n<p>test -x \/usr\/sbin\/ucarp || exit 0<\/p>\n<p>case &#8220;$1&#8221; in<br \/>\nstart)<\/p>\n<p>if [ ! -x \/usr\/sbin\/ucarp ]; then<br \/>\necho &#8220;ucarp binary missing &#8211; not starting&#8221;<br \/>\nexit 1<br \/>\nfi<br \/>\nif ( ! pgrep -f \/usr\/sbin\/ucarp )<br \/>\nthen<br \/>\necho -n &#8220;Starting ucarp service: ucarp&#8221;<br \/>\nstart-stop-daemon &#8211;start &#8211;make-pidfile &#8211;pidfile\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ${UCARP_PIDFILE} &#8211;quiet &#8211;exec \/usr\/sbin\/ucarp \\<br \/>\n&#8212; $OPTIONS<br \/>\nelse<br \/>\necho &#8220;ucarp is running, not starting&#8221;<br \/>\nfi<br \/>\necho &#8220;.&#8221;<br \/>\n;;<\/p>\n<p>stop)<br \/>\necho -n &#8220;Stopping ucarp service: ucarp&#8221;<br \/>\nrm -f \/var\/run\/ucarp.pid &amp;&amp; killall ucarp<br \/>\necho &#8220;.&#8221;<br \/>\n;;<\/p>\n<p>restart|force-reload)<br \/>\n$0 stop<br \/>\nsleep 2<br \/>\n$0 start<br \/>\n;;<\/p>\n<p>*)<br \/>\necho &#8220;Usage: \/etc\/init.d\/ucarp {start|stop|restart|force-reload}&#8221; &gt;&amp;2<br \/>\nexit 1<br \/>\n;;<br \/>\nesac<\/p>\n<p>exit 0<\/p>\n<p>La linea importante \u00e8 quella OPTIONS che analizziamo a fondo<br \/>\nl&#8217;opzione -B \u00e8 quella che demonizza ucarp cio\u00e8 in parole povere lo fa girare in background.<br \/>\nL&#8217;opzione -v definisce la virtual id ed \u00e8 un valore numerico compreso tra tra 1 e 255 deve essere uguale su entrambe le macchine ci possono essere pi\u00f9 virtual id.<br \/>\nL&#8217;opzione -p definisce la password sharata che deve ovviamente essere identica su ambo le macchine eche non viene trasmessa in chiaro.<br \/>\nL&#8217;opzione -a\u00a0 definisce l&#8217;Ip virtuale.<br \/>\nL&#8217;opzione -s definisce l&#8217;IP reale della scheda su cui si genera il virtual IP.<br \/>\nL&#8217;opzione -i definisce l&#8217;interfaccia su cui si opera.<br \/>\nL&#8217;opzione -u definisce l&#8217;up script che vedremo in dettaglio dopo.<br \/>\nL&#8217;opzione -d definisce il down script che vedremo in dettaglio dopo.<br \/>\nL&#8217;opzione -P definisce il Preemt cio\u00e8 porta la macchiana a fare il take per diventare master,<br \/>\ncommento personale poich\u00e8 questo \u00e8 lo slave non dovrebbe essere necessario stando alla letteratura in materia, per\u00f2 dopo lunghi test e parecchi insuccessi nonostante l&#8217;evidente controsenso del &#8221; tu sei master ma sei meno master dell&#8217;altra macchina(vedi opzione -k)&#8221; questo modo si \u00e8 rivelato l&#8217;unico per fare funzionare le cose a dovere.<br \/>\nL&#8217;opzione -k 200 definisce l&#8217;Advertisement skew cio\u00e8, la &#8220;diciamo&#8221; priorit\u00e0 con cui la macchina viene eletta master\u00a0 a valori bassi di k corrisponde alta probabilit\u00e0 che la macchina faccia il take come master il valore e \u00e8 compreso 0 e 255 il default \u00e8 0<br \/>\nL&#8217;opzione -z \u00e8 il compendio dell&#8217;opzione -d<br \/>\nL&#8217;opzione -f definisce la facilitazione per il syslog.<br \/>\nQui i parametri -k 200 e -b 5 forzano la macchina a slave<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Master #!\/bin\/sh PATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin:\/\/usr\/local\/sbin:\/usr\/local\/bin #set to -P if you want this to be the preferred master PREEMPT=-P #Log to \/var\/log\/messages LOG=syslog FAILOVER_ID=10 SHARED_SECRET=passwordsupersecret VIRTUAL_IP=192.168.2.241 REAL_IP=192.168.2.240 INTERFACE=eth1 VIP_UP_SCRIPT=\/etc\/ucarp\/ucarp-up.sh VIP_DOWN_SCRIPT=\/etc\/ucarp\/ucarp-down.sh UCARP_PIDFILE=\/var\/run\/ucarp.pid OPTIONS=&#8221;-B -v $FAILOVER_ID -p $SHARED_SECRET -a $VIRTUAL_IP -s $REAL_IP -i $INTERFACE \\ -u $VIP_UP_SCRIPT -d $VIP_DOWN_SCRIPT $PREEMPT -k 0 -b 1 -z -f $LOG&#8221; test -x \/usr\/sbin\/ucarp [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,8,7,6],"tags":[],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-cluster","category-linux","category-sistemi-operativi","category-work"],"_links":{"self":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":7,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":251,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions\/251"}],"wp:attachment":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}