<p>fs_cli -x &quot;fsctl shutdown gracefully&quot;</p>
<p>-BDF</p>
<div class="gmail_quote">On Apr 3, 2012 4:48 PM, &quot;Mario G&quot; &lt;<a href="mailto:mario_fs@mgtech.com">mario_fs@mgtech.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">If you mean the effect, it did not stop FS although the results were the same, it prevented the fast FS shutdown/startup from activating the internal profile so <i>none</i> of the phone extensions work. In my case that meant all phones were out from 2am to whenever I activated internal. Not good in case of an emergency. Hope it may be useful to someone, it took me 15 days to find and resolve.<div>
<br></div><div>If you mean how is FreeSwitch shutdown, the 2am script runs a script that runs one command: <span style="font-family:Menlo;font-size:11px">/usr/local/freeswitch/bin/fs_cli -x &quot;shutdown&quot;</span><div>
<br><div><div>On Apr 3, 2012, at 11:24 AM, Anthony Minessale wrote:</div><br><blockquote type="cite"><div>How exactly does it &quot;stop&quot; freeswitch?<br><br>On Tue, Apr 3, 2012 at 11:17 AM, Mario G &lt;<a href="mailto:mario_fs@mgtech.com" target="_blank">mario_fs@mgtech.com</a>&gt; wrote:<br>
<blockquote type="cite">I am posting this in case someone else runs into this, especially since I<br></blockquote><blockquote type="cite">found it may not be Mac OSX specific (I was able to duplicate on SUSE<br></blockquote>
<blockquote type="cite">although not as much).<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Both of the following conditions must exist:<br></blockquote><blockquote type="cite">1. You have at least one TCP local extension. In this case, due to Bria,<br>
</blockquote><blockquote type="cite">etc. on an iPad, using TCP reduced battery usage since no need to run in<br></blockquote><blockquote type="cite">background.<br></blockquote><blockquote type="cite">2. FreeSwitch is recycled very quickly, in this case down/up within 30<br>
</blockquote><blockquote type="cite">seconds because it was automated at 2am each day. I needed it due to a long<br></blockquote><blockquote type="cite">running sofia memory leak on OSX which may be resolved but I need to test.<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Problem: The extension using TCP cause a TIME_WAIT that keeps the 5060 port<br></blockquote><blockquote type="cite">active (but NOT open) on the TCP stack, in my case it was 30 seconds but I<br>
</blockquote><blockquote type="cite">found the time could be different on other platforms. When FreeSwitch comes<br></blockquote><blockquote type="cite">back up the &quot;internal.xml&quot; profile fails because port 5060 is in use. If FS<br>
</blockquote><blockquote type="cite">is brought up AFTER the TIME_WAIT goes away there is no problem, but in my<br></blockquote><blockquote type="cite">case it was very quick each night to minimize the outage.<br></blockquote>
<blockquote type="cite"><br></blockquote><blockquote type="cite">Solution: I changed the OSX plist that auto restarts FS to run a script that<br></blockquote><blockquote type="cite">starts FS, this makes no difference except a script is more flexible. Rather<br>
</blockquote><blockquote type="cite">than use an arbitrary sleep time I check for port 5060 which is more<br></blockquote><blockquote type="cite">reliable and faster. I tested this many times using different scenarios and<br>
</blockquote><blockquote type="cite">all worked. Note I tried to use the &quot;lsof -i TCP:5060&quot; command but it shows<br></blockquote><blockquote type="cite">only OPEN ports so it won&#39;t work.<br></blockquote><blockquote type="cite">
<br></blockquote><blockquote type="cite">#!/bin/sh<br></blockquote><blockquote type="cite">while : ; do<br></blockquote><blockquote type="cite">   a=$(/usr/sbin/netstat -p tcp)<br></blockquote><blockquote type="cite">   if [[ &quot;$a&quot; != *sip* ]] ; then<br>
</blockquote><blockquote type="cite">     break<br></blockquote><blockquote type="cite">   fi<br></blockquote><blockquote type="cite">   echo &quot;Port 5060 still in use - waiting for it to free up&quot;<br></blockquote>
<blockquote type="cite">   echo &quot;${a}&quot;<br></blockquote><blockquote type="cite">   /bin/sleep 3<br></blockquote><blockquote type="cite">done<br></blockquote><blockquote type="cite">/usr/local/freeswitch/bin/freeswitch -nc -nonat<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">#   a=$(/usr/sbin/lsof -i TCP:5060)  &lt;- only shows open ports<br></blockquote><blockquote type="cite">#   if [ &quot;$a&quot; = &quot;&quot; ] ; then<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On Apr 3, 2012, at 8:53 AM, Mario G wrote:<br></blockquote><blockquote type="cite">
<br></blockquote><blockquote type="cite">For anyone who may run into this see &quot;FS shutdown not closing TCP port<br></blockquote><blockquote type="cite">causes TIME_WAIT problems&quot; for follow up and solution.<br></blockquote>
<blockquote type="cite">On Apr 2, 2012, at 1:33 PM, Mario G wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">That&#39;s what I was thinking, trying to figure out how now. Will post a<br>
</blockquote><blockquote type="cite">solution when I get one.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On Apr 2, 2012, at 1:28 PM, Anthony Minessale wrote:<br></blockquote><blockquote type="cite">
<br></blockquote><blockquote type="cite">From what I see, sofia uses the REUSEADDR flag so I will bet its yet<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">another MAC specific thing.<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I am not really sure what you can do since you tend to find issues<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">
deep inside libsofia-sip and its portability to OSX.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Maybe make your restart script sleep a bit?<br></blockquote><blockquote type="cite"><br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">su_setreuseaddr(socket, 1);<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">
On Mon, Apr 2, 2012 at 3:13 PM, Mario G &lt;<a href="mailto:mario_fs@mgtech.com" target="_blank">mario_fs@mgtech.com</a>&gt; wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">If FS is shutdown and started too quickly, the internal profile ip/port<br>
</blockquote><blockquote type="cite">stays in use and FS will fail to start it. After searching on the wen I<br></blockquote><blockquote type="cite">found many references to TIME_WAIT but all fixes were to the program source.<br>
</blockquote><blockquote type="cite">So I am wondering if when FS/sofia shuts down they are not releasing the<br></blockquote><blockquote type="cite">ip/port for internal. If it&#39;s true, I found some source changes to solve it.<br>
</blockquote><blockquote type="cite">Google &quot;TIME-WAIT&quot; and you&#39;ll find lots of good stuff like<br></blockquote><blockquote type="cite"><a href="http://serverfault.com/questions/329845/how-to-forcibly-close-a-socket-in-time-wait" target="_blank">http://serverfault.com/questions/329845/how-to-forcibly-close-a-socket-in-time-wait</a>.<br>
</blockquote><blockquote type="cite">Apparently there is no way to free up the port manually. Help/comments<br></blockquote><blockquote type="cite">anyone?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">
Mario G<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_________________________________________________________________________</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">
<br></blockquote>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</a><br><br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com" target="_blank">MSN:anthony_minessale@hotmail.com</a><br>
GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com" target="_blank">PAYPAL:anthony.minessale@gmail.com</a><br>IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br>
<a>sip:888@conference.freeswitch.org</a><br><a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org" target="_blank">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:<a href="tel:%2B19193869900" value="+19193869900" target="_blank">+19193869900</a><br>
<br>_________________________________________________________________________<br>Professional FreeSWITCH Consulting Services:<br><a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br><br>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br><a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>Official FreeSWITCH Sites<br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br><a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br><a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>FreeSWITCH-users mailing list<br><a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></blockquote></div><br></div></div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div>