q;Pc@snddkZddkZddkZddkZddkZyddkZWn#ej oddklZnXddk l Z l Z ddk l Z lZddkZddkZddkZddkZdZeiidZdefdYZd e fd YZd efd YZd ZdZdZdddZdddZ dZ!dS(iN(t subprocess24(tCommandt BadCommand(tloadappt loadserveritjavatDaemonizeExceptioncBseZRS((t__name__t __module__(((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRst ServeCommandc BseZdZdZdZdZdZeZe i deZ e i dddd d d d d e i ddddd dd de i dddd dd de edo#e i dddddd dne i dddd dd d e i d!dd"d d#d d$e i d%dd&ddd d'e i d(dd)d*dd d+e i d,dd-ddd d.e i d/dddd0d d1e ed2oBe i d3dd4d d5d d6e i d7dd8d d9d d:ne i d;dd<ddd d=eo#e i d>dddd?d d@neidAeiZdZdBZdCZdRZdHZdIZdJZdKZdLZdMZdNZdOZe dPZ!dQZ"RS(Sis3CONFIG_FILE [start|stop|restart|status] [var=value]isServe the described applications This command serves a web application that uses a paste.deploy configuration file for the server and application. If start/stop/restart is given, then --daemon is implied, and it will start (normal operation), stop (--stop-daemon), or do both. You can also include variable assignments like 'http_port=8080' and then use %(http_port)s in your config files. tquiets-ns --app-nametdesttapp_nametmetavartNAMEthelps)Load the named application (default main)s-ss--servertservert SERVER_TYPEsUse the named server.s --server-namet server_namet SECTION_NAMEsIUse the named server as defined in the configuration file (default: main)tforks--daemontdaemontactiont store_truesRun in daemon (background) modes --pid-filetpid_filetFILENAMEsBSave PID to file (default to paster.pid if running in daemon mode)s --log-filetlog_filetLOG_FILEs4Save output to the given log file (redirects stdout)s--reloadtreloadsUse auto-restart file monitors--reload-intervaltreload_intervaltdefaultsKSeconds between checking files (low number can cause significant CPU usage)s--monitor-restarttmonitor_restartsAuto-restart server if it diess--statust show_statuss5Show the status of the (presumably daemonized) servertsetuids--usertset_usertUSERNAMEs5Set the user (usually only possible when run as root)s--groupt set_grouptGROUPs6Set the group (usually only possible when run as root)s --stop-daemont stop_daemonsGStop a daemonized server (given a PID file, or default paster.pid file)s--disable-jython-reloadertdisable_jython_reloadersDisable the Jython reloaders ^[a-z][a-z]+:tPYTHON_RELOADER_SHOULD_RUNtPASTE_MONITOR_SHOULD_RUNtstarttstoptrestarttstatuscsiio iStidpdi_i_niiiiiioipt dnid}t idjo5idi joid}id}qId}id}nVd}io5idi joid}id}nd}i}t }ii otoyii okyddkl}Wntj oqX|d tii}io|iidqn|ptiiiohdd kl}idjo d GHn|itiiio|iidqkqoiSqsn|d&jot d|n|djp iio iS|djp |d joIi}|o |djo dGHndGH|S|d jo|Snii }i!|} i"i#|pd|}nii$} ii%o*d} | djpt&ii%} n|} ti'} t(idt o>ii)pdi_)nii*pdi_*qnii*oUyt+ii*d} Wn+t,j o}d|}t |nX| i-nii)oUyt+ii)d}Wn+t,j o}d|}t |nX|i-nt(idt oJyi.Wq%t/j o)}idjot0|GHndSXnii1o"tiii2 o i3Sii)oi4ii)nii*o;t5ii*d}|t6_7|t6_8t9i:d|n|}|i;do|t d}n|i;do d}n|o&ti<i=| |}i>|ni?| d| d| d| i@|d|d| d| idjo3ttd od!tiA}nd"}|GHnfd#}|o)tBiCd$|iDd%GH|iEn|dS('NR"sYou must give a config fileiiiti(t JythonMonitort poll_interval(treloadersRunning reloading file monitorR*R+R,R-s,Error: must give start|stop|restart (not %s)sCould not stop daemon; abortingsCould not stop daemonsconfig:segg:PasteScriptRs paster.pids paster.logtas&Error: Unable to write to log file: %ss&Error: Unable to write to pid file: %ststreamsegg:tnamet relative_tot global_conftgetpidsStarting server in PID %i.sStarting server.cswyWnbttfj oP}idjont|odt|}nd}d|GHnXdS(Nit R.sExiting%s (-v to see traceback)(t SystemExittKeyboardInterrupttverbosetstr(tetmsg(tappRtself(s6/usr/lib/python2.6/site-packages/paste/script/serve.pytserves ttargetsStarting Jython file monitor(NsstartsstopR,R-(FtoptionsR&thasattrtNoneR"R$tchange_user_grouptrequires_config_filetargsRtlentpossible_subcommandstFalseRtjythonR'tpaste.reloaderR/t ImportErrortintRt watch_filetostenvirontgett_reloader_environ_keytpasteR1R;tinstalltrestart_with_reloaderR R t parse_varst _scheme_retsearchRRtAssertionErrortgetcwdtgetattrRRtopentIOErrortcloset daemonizeRR<Rt_monitor_environ_keytrestart_with_monitort record_pidt LazyWritertsyststdouttstderrtloggingt basicConfigt startswithtpathtjointlogging_file_configRRR7t threadingtThreadR*tperiodic_reload(R@tapp_spectcmdtrestvarstjython_monitorR/R1tresultR tvarsRt server_spectbasetwriteable_log_filetioeR>twriteable_pid_filetext stdout_logtlog_fnRA((R@R?Rs6/usr/lib/python2.6/site-packages/paste/script/serve.pytcommands                                         cKst|d|d||S(NR4R5(R(R@RxR4R5tkw((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR1s cKst|d|d||S(NR4R5(R(R@RrR4R5R((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR6scCs{t|ii}|o td||iifn|idjo dGHnti}|otidntiti}|otidnddk }|i |i d}||i jo t }nx>td|D]-}yti|Wqtj oqXqWttdo ti}nd}ti|titiddtidddS( Ns4Daemon is already running (PID: %s from PID file %s)isEntering daemon modeiitdevnulls /dev/nulli(t live_pidfileRCRRR;RQRt_exittsetsidtresourcet getrlimitt RLIMIT_NOFILEt RLIM_INFINITYtMAXFDtrangeR`tOSErrorRDRR^tO_RDWRtdup2(R@tpidRtmaxfdtfdt REDIRECT_TO((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRa;s<        cCsxti}|idjod||fGHnt|d}|it||itit |||idS(NisWriting PID %s to %stw( RQR7R;R^twriteR<R`tatexittregistert_remove_pid_file(R@RRtf((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRdgs  cCs9|iipd}tii|pd|GHdSt|}|pd|GHdSt|}|pGd|GHyti|Wn%tt fj o}d|GHdSXdSx_t dD]D}t|pPnd dk }ti ||i tidqWd |GHd Stii|oti|nd S( Ns paster.pidsNo PID file exists in %sisNot a valid PID file in %ss!PID in %s is not valid (deleting)sCould not delete: %sii isfailed to kill web process %sii(RCRRQRltexistst read_pidfileRtunlinkRR_RtsignaltkilltSIGTERMttimetsleep(R@RRR=tjR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR&ps:          cCs|iipd}tii|pd|GHdSt|}|pd|GHdSt|}|pd||fGHdSd|GHdS(Ns paster.pidsNo PID file %sisNo PID in file %ssPID %s in %s is not runningsServer running in PID %si(RCRRQRlRRR(R@RR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR s     cCs|idtdS(NR1(RctTrue(R@((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRWscCs|idjo|o dGHq)dGHnxg|itigti}tii}|od||ieZdZddZdZdZdZdZRS(sT File-like object that opens a file lazily when it is first written to. RcCs.||_d|_ti|_||_dS(N(tfilenameREtfileobjRotLocktlocktmode(R@RR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyt__init__s  cCsi|idjoR|iiz0|idjot|i|i|_nWd|iiXn|iS(N(RRERtacquireR^RRtrelease(R@((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR^s  cCs'|i}|i||idS(N(R^Rtflush(R@ttextR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR s  cCs'|i}|i||idS(N(R^t writelinesR(R@RR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRs  cCs|iidS(N(R^R(R@((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRs(RRt__doc__RR^RRR(((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRes    cCsit|}|oRytit|d|SWqetj o!}|itijo|SqeXndS(s(pidfile:str) -> int | None Returns an int found in the named file, if there is one, and if there is a running process with that process id. Return None if no such process exists. iN(RRQRRORterrnotEPERMRE(tpidfileRR=((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRs cCsrtii|oWy6t|}|i}|it|iSWqntt fj odSXndSdS(N( RQRlRR^treadR`ROtstripRR_RE(RRtcontent((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR*s    c CsRti}||jodStii|pdSt|}|ii}|iyt|}Wnt j on&X||jod|||fGHdS|djo d|GHnyti |dSWnt j o}d|GHnXy*t|d}|i d|iWn$t j o}d||fGHnXdGHdS( Ns,PID file %s contains %s, not expected PID %sisRemoving PID file %ssCannot remove PID file: %sRR.sStale PID left in file: %s (%e)sStale PID removed( RQR7RlRR^RRR`RORRRR(t written_pidRt verbosityt current_pidRRt pid_in_fileR=((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR6s<         iicCs tit|d|d|dS(s This makes sure any open ports are closed. Does this by connecting to them until they give connection refused. Servers should call like:: import paste.script ensure_port_cleanup([80, 443]) tmaxtriest sleeptimeN(RRt_cleanup_ports(tbound_addressesRR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pytensure_port_cleanup]s c Csddk}ddk}x|D]}xt|D]v}|i|i|i}y|i|Wn7|ij o(}|id|ijonPq2Xt i |q2Wt d|i qWdS(NiisTimeout waiting for port.( tsocketRRtAF_INETt SOCK_STREAMtconnectterrorRHt ECONNREFUSEDRRR9R`( RRRRRt bound_addresstattempttsockR=((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyRjs     cCsGyddk}Wntj odSXd}|i|i|dS(sK Attempts to turn a SIGTERM exception into a SystemExit exception. iNcSs tdS(N(R9(tsignotframe((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyt handle_terms(RRNR(RR((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyR}s  ("RRQRRfRRRNt paste.utilRRRRt paste.deployRRRoRRit ConfigParserRtplatformRkRLt ExceptionRR tobjectReRRRRRR(((s6/usr/lib/python2.6/site-packages/paste/script/serve.pyt s4         $  '