From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Jakub Narebski <jnareb@gmail.com>,
Eric Wong <normalperson@yhbt.net>,
Pavan Kumar Sunkara <pavan.sss1991@gmail.com>,
Petr Baudis <pasky@suse.cz>,
Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH 2/3] git-instaweb: Wait for server to start before running web browser
Date: Fri, 28 May 2010 21:11:24 +0200 [thread overview]
Message-ID: <1275073885-26537-3-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1275073885-26537-1-git-send-email-jnareb@gmail.com>
Add generic httpd_is_ready subroutine, which busy-waits for web server to
be started, by checking if $port is opened on localhost. This is used to
avoid situation where web browser is started before web server is ready to
accept connection, and fails.
It uses IO::Socket::INET module, which is core Perl module since v5.6.0.
Alternate solution, possible for those web servers that can run arbitrary
code hooks after they bind the listen socket (after they start accepting
connections), would be to use some kind of blocking mechanism: FIFO or
lockfile, see
http://thread.gmane.org/gmane.comp.version-control.git/147337/focus=147566
This can be always added later, as a web server specific branch in
httpd_is_ready function.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This was required to test support for 'plackup' web server in git-instaweb
(the next patch in this series), because default pure-Perl web server used
by Plack, namely HTTP::Server::PSGI, can take a while to start.
git-instaweb.sh | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/git-instaweb.sh b/git-instaweb.sh
index a8c5dc0..dc8478f 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -117,6 +117,19 @@ stop_httpd () {
rm -f "$fqgitdir/pid"
}
+httpd_is_ready () {
+ "$PERL" -MIO::Socket::INET -e "
+local \$| = 1; # turn on autoflush
+exit if (IO::Socket::INET->new('127.0.0.1:$port'));
+print 'Waiting for \'$httpd\' to start ..';
+do {
+ print '.';
+ sleep(1);
+} until (IO::Socket::INET->new('127.0.0.1:$port'));
+print qq! (done)\n!;
+"
+}
+
while test $# != 0
do
case "$1" in
@@ -414,7 +427,7 @@ start_httpd
url=http://127.0.0.1:$port
if test -n "$browser"; then
- git web--browse -b "$browser" $url || echo $url
+ httpd_is_ready && git web--browse -b "$browser" $url || echo $url
else
- git web--browse -c "instaweb.browser" $url || echo $url
+ httpd_is_ready && git web--browse -c "instaweb.browser" $url || echo $url
fi
--
1.7.0.1
next prev parent reply other threads:[~2010-05-28 19:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-28 19:11 [PATCH 0/3] git-instaweb: Support for 'plackup' and improvements Jakub Narebski
2010-05-28 19:11 ` [PATCH 1/3] git-instaweb: Remove pidfile after stopping web server Jakub Narebski
2010-05-28 19:11 ` Jakub Narebski [this message]
2010-05-28 19:31 ` [PATCH 2/3] git-instaweb: Wait for server to start before running web browser Pavan Kumar Sunkara
2010-05-28 19:58 ` Jakub Narebski
2010-05-28 19:11 ` [PATCHv4 3/3] git-instaweb: Add support for running gitweb via 'plackup' Jakub Narebski
2010-05-29 2:32 ` Eric Wong
2010-05-29 7:21 ` Eric Wong
2010-05-31 21:15 ` [PATCH 0/3] git-instaweb: Support for 'plackup' and improvements Petr Baudis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1275073885-26537-3-git-send-email-jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=normalperson@yhbt.net \
--cc=pasky@suse.cz \
--cc=pavan.sss1991@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).