Re: [Pythomnic3k-questions] Best Practice to Auto-Start cages under Linux
Brought to you by:
targeted
From: <dm...@ta...> - 2016-01-26 16:22:55
|
Hi Eric, I can give you an example which you should be able to incorporate into your rc.d start/stop framework. A few words about shutting down a Pythomnic application in general. First, there actually are two python processes - one "external", which executes startup.py and whose pid you have in cages/foo/logs/foo.pid and one "internal" which actually executes your application. External process monitors the internal one and restarts it if it crashes. Therefore you don't have access to the internal process directly. Second, shutting down is not immediate. When a shutdown is initiated, all the interfaces are signaled to stop accepting requests, but the requests already being executed are allowed to finish. This means that in the worst case shutdown process can take up to "request_timeout" seconds. As to how it is done. You kill the external process using its pid and then wait for the internal process to complete shutdown. The former is easy, and the latter is ugly, because you have no pid for the external process. As a hack, you could tail the log file until successful shutdown message appears in it. So, something like this: --- cage=foo timeout=10 /bin/echo -n "shutting down $cage:" kill `cat pythomnic3k/cages/$cage/logs/$cage.pid` for i in `jot - $timeout 0`; do tail pythomnic3k/cages/$cage/logs/$cage-`date +%Y%m%d`.log | grep -q 'properly shut down' && /bin/echo 'ok' && break if [ $i -eq 0 ]; then /bin/echo 'timeout' break fi /bin/echo -n '.' && sleep 1 done --- Dmitry On 22.01.2016 10:18, Eric Livingston wrote: > Dmitry, > > Do you have a handy template script that can start/stop cages under > linux (Debian Wheezy, in this case, so the rc.d structure) as you can > other services? I'd like to be able to something like > "/etc/init.d/cage start" and "stop" and put in in the default startup > sequence, etc. > > Starting a cage is easy, but I can't find a good way to cleanly shut > one down, unless startup.py also doubles as "shutdown.py"! > > Eric > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > > _______________________________________________ > Pythomnic3k-questions mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythomnic3k-questions |