From db61f060be5bc00cc9a44df694bac4ee4b65d02d Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 23 Jun 2011 21:55:00 +0200 Subject: git-instaweb: Extract configuring web server into configure_httpd This is preparatory work for making start/restart check that git-instaweb set up correct configuration, and generate it if it is missing. Pure refactoring, no functional changes. Signed-off-by: Jakub Narebski Acked-by: Eric Wong --- git-instaweb.sh | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index 8bfa8a055c..49bab7bc97 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -587,32 +587,36 @@ our \$projects_list = \$projectroot; EOF } +configure_httpd() { + case "$httpd" in + *lighttpd*) + lighttpd_conf + ;; + *apache2*|*httpd*) + apache2_conf + ;; + webrick) + webrick_conf + ;; + *mongoose*) + mongoose_conf + ;; + *plackup*) + plackup_conf + ;; + *) + echo "Unknown httpd specified: $httpd" + exit 1 + ;; + esac +} + gitweb_conf resolve_full_httpd mkdir -p "$fqgitdir/gitweb/$httpd_only" -case "$httpd" in -*lighttpd*) - lighttpd_conf - ;; -*apache2*|*httpd*) - apache2_conf - ;; -webrick) - webrick_conf - ;; -*mongoose*) - mongoose_conf - ;; -*plackup*) - plackup_conf - ;; -*) - echo "Unknown httpd specified: $httpd" - exit 1 - ;; -esac +configure_httpd start_httpd url=http://127.0.0.1:$port -- cgit v1.3-5-g9baa From 48bf76ca93c7569660712c12b3c4f86c60803352 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 23 Jun 2011 21:56:37 +0200 Subject: git-instaweb: Use $conf, not $fqgitdir/gitweb/httpd.conf Don't repeat yourself: use "$conf" instead of its [current] contents, namely "$fqgitdir/gitweb/httpd.conf". Signed-off-by: Jakub Narebski Acked-by: Eric Wong --- git-instaweb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index 49bab7bc97..2be22a0dfe 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -103,7 +103,7 @@ start_httpd () { case "$httpd" in *mongoose*|*plackup*) #These servers don't have a daemon mode so we'll have to fork it - $full_httpd "$fqgitdir/gitweb/httpd.conf" & + $full_httpd "$conf" & #Save the pid before doing anything else (we'll print it later) pid=$! @@ -117,7 +117,7 @@ $pid EOF ;; *) - $full_httpd "$fqgitdir/gitweb/httpd.conf" + $full_httpd "$conf" if test $? != 0; then echo "Could not execute http daemon $httpd." exit 1 -- cgit v1.3-5-g9baa From c0175f92c7da1c379c25b5a70d53b9d550bcc11d Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 23 Jun 2011 22:59:26 +0200 Subject: git-instaweb: Move all actions at the end of script As a nice side-effect now the order of parameters does not matter: $ git instaweb --httpd=apache2 --start is now (after this patch) the same as $ git instaweb --start --httpd=apache2 Before this commit --start, --stop, --restart (and their subcommand versions start, stop, restart) exited immediately. This is preparatory work for making start/restart check that correct configuration is set up; this change was required to have access in start_httpd to requested web browser etc. Signed-off-by: Jakub Narebski Acked-by: Eric Wong --- git-instaweb.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index 2be22a0dfe..9a2f20f6ad 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -27,6 +27,7 @@ httpd="$(git config --get instaweb.httpd)" root="$(git config --get instaweb.gitwebdir)" port=$(git config --get instaweb.port) module_path="$(git config --get instaweb.modulepath)" +action="browse" conf="$GIT_DIR/gitweb/httpd.conf" @@ -148,17 +149,13 @@ while test $# != 0 do case "$1" in --stop|stop) - stop_httpd - exit 0 + action="stop" ;; --start|start) - start_httpd - exit 0 + action="start" ;; --restart|restart) - stop_httpd - start_httpd - exit 0 + action="restart" ;; -l|--local) local=true @@ -611,6 +608,22 @@ configure_httpd() { esac } +case "$action" in +stop) + stop_httpd + exit 0 + ;; +start) + start_httpd + exit 0 + ;; +restart) + stop_httpd + start_httpd + exit 0 + ;; +esac + gitweb_conf resolve_full_httpd -- cgit v1.3-5-g9baa From 5ad6d387f19d9dd28b323f5cfea8663cb7b74617 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 23 Jun 2011 23:01:03 +0200 Subject: git-instaweb: Check that correct config file exists for (re)start Currently start/restart does not generate any configuration files for spawning a new instance. This means that $ git instaweb --http= --start might pick up stale 'httpd.conf' file for a different web server (e.g. for default lighttpd when requesting apache2). This commit changes that, and makes git-instaweb generate web server config file and/or gitweb config file if don't exists. This required naming config files after the name of web server (alternate solution would be to somehow mark for which web server was config file generated). Note that web servers that embed configuration in server script file, namely webrick and plackup, and which delete "$conf" in their *_conf function, would have their config (server script) always regenerated. Note: this commit introduces a bit of code repetition (but only a few lines). Reported-by: Gurjeet Singh Signed-off-by: Jakub Narebski Acked-by: Eric Wong --- Documentation/git-instaweb.txt | 8 ++++---- git-instaweb.sh | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Documentation/git-instaweb.txt b/Documentation/git-instaweb.txt index 08f85ba046..ea95c90460 100644 --- a/Documentation/git-instaweb.txt +++ b/Documentation/git-instaweb.txt @@ -51,8 +51,8 @@ OPTIONS start:: --start:: - Start the httpd instance and exit. This does not generate - any of the configuration files for spawning a new instance. + Start the httpd instance and exit. Regenerate configuration files + as necessary for spawning a new instance. stop:: --stop:: @@ -62,8 +62,8 @@ stop:: restart:: --restart:: - Restart the httpd instance and exit. This does not generate - any of the configuration files for spawning a new instance. + Restart the httpd instance and exit. Regenerate configuration files + as necessary for spawning a new instance. CONFIGURATION ------------- diff --git a/git-instaweb.sh b/git-instaweb.sh index 9a2f20f6ad..01a1b05e6b 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -99,6 +99,12 @@ start_httpd () { # here $httpd should have a meaningful value resolve_full_httpd + mkdir -p "$fqgitdir/gitweb/$httpd_only" + conf="$fqgitdir/gitweb/$httpd_only.conf" + + # generate correct config file if it doesn't exist + test -f "$conf" || configure_httpd + test -f "$fqgitdir/gitweb/gitweb_config.perl" || gitweb_conf # don't quote $full_httpd, there can be arguments to it (-f) case "$httpd" in @@ -628,6 +634,7 @@ gitweb_conf resolve_full_httpd mkdir -p "$fqgitdir/gitweb/$httpd_only" +conf="$fqgitdir/gitweb/$httpd_only.conf" configure_httpd -- cgit v1.3-5-g9baa