Running as a service and Log4j configuration

926 views
Skip to first unread message

Drew

unread,
Feb 1, 2012, 8:35:32 PM2/1/12
to gitblit
Hi,

First and foremost, great job on building such a nice git web ui. I'm
migrating our repos from gitorious to gitblit now!

I'm trying to run gitblit as a service under Ubuntu server but I can't
seem to be able to configure log4j to log to a file instead of the
console. I tried passing -Dlog4j.configuration=custom_log4j.properties
but that didn't work. Seems like log4j configuration is read from temp/
webapp/log4j.properties and gets overwritten every time the server
start.

In addition, the current gitlab init.d script runs as root, I'm not
that good with bash, but I think it would be better if there was a way
to specify it to run with a less privileged user.

Thanks,

Drew

James Moger

unread,
Feb 2, 2012, 7:41:14 AM2/2/12
to git...@googlegroups.com
Gitblit GO does not allow modifying the log4j configuration.

Having said that GO does create log files. They should be located in
a "logs" folder wherever you unpacked the GO zip file.

> In addition, the current gitlab init.d script runs as root, I'm not
> that good with bash, but I think it would be better if there was a way
> to specify it to run with a less privileged user.

I can not speak for Gitlab, that is not my project.

-J

James Moger

unread,
Feb 2, 2012, 9:20:34 AM2/2/12
to git...@googlegroups.com
Hmmm. It seems that GO is not properly creating log files. I'm going
to revise the service scripts for the next release as I can see there
are issues with them.

Below is a revised script that I am using on Ubuntu Server 11.04. The
console output is redirected to a log file. You don't get rotation,
etc, but it is a start. Alternatively, you could install Tomcat and
use the WAR build.

#!/bin/sh

set -e

GITBLIT_PATH=/shares/gitblit/
GITBLIT_HTTP_PORT=0
GITBLIT_HTTPS_PORT=8443
JAVA="java -server -Xmx1024M -jar"

. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting gitblit server"
cd $GITBLIT_PATH
$JAVA $GITBLIT_PATH/gitblit.jar --httpsPort
$GITBLIT_HTTPS_PORT --httpPort $GITBLIT_HTTP_PORT >
/var/log/gitblit.log &
log_action_end_msg $?
;;
stop)
log_action_begin_msg "Stopping gitblit server"
cd $GITBLIT_PATH
$JAVA $GITBLIT_PATH/gitblit.jar --stop &
log_action_end_msg $?
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/gitblit {start|stop|restart|force-reload}"
exit 1
;;
esac

exit 0

Drew Kutcharian

unread,
Feb 2, 2012, 11:47:37 AM2/2/12
to git...@googlegroups.com, git...@googlegroups.com
Hi James,

Sorry, that was a typo, I meant GitBlit not Gitlab.

- Drew

Drew Kutcharian

unread,
Feb 2, 2012, 11:55:43 AM2/2/12
to git...@googlegroups.com
I think you should move the log4j.properties out of the jar file so it's possible to modify it.

In addition, the init.d script that you have will run gitblit as root, no? usually you need to "su" to a less privileged user.

- Drew

James Moger

unread,
Feb 2, 2012, 12:05:32 PM2/2/12
to git...@googlegroups.com
Yes, it probably does run as root. I personally don't have a problem
with that. Linux service scripts are a shortcoming in Gitblit.
Unfortunately, there is no one script that will work across all
flavors and as you point out you may want to run as a less privileged
user which may require doing a useradd and chgrp during
install-service. If you come up with a more manageable solution
please open a pull request on GitHub and I'll merge it.

-J

Drew Kutcharian

unread,
Feb 2, 2012, 12:34:25 PM2/2/12
to git...@googlegroups.com
I'm going to work on integrating GitBlit with Tomcat with Apache front-end using AJP and running it using Java Service Wrapper as a standard unix daemon. This is more of a production setup. I will email you the instructions.

Thanks again for creating GitBlit. I'm really starting to like it.

-- Drew

James Moger

unread,
Feb 2, 2012, 12:37:59 PM2/2/12
to git...@googlegroups.com
You are going to run into url proxy issues. Make sure to read the FAQ
about Tomcat and proxy layers.

-J

Drew Kutcharian

unread,
Feb 2, 2012, 12:45:00 PM2/2/12
to git...@googlegroups.com
I'm actually currently running GitBlit behind Apache using mod_proxy_http and I had the slash encoding issue so I disabled web.mountParameters since my apache doesn't support AllowEncodedSlashes NoDecode. I'm hoping I can get the pretty URLs to work using Tomcat/AJP.

I still prefer using GitBlit GO if I can get the custom logging and AJP connector.

-- Drew

Drew Kutcharian

unread,
Feb 2, 2012, 12:48:58 PM2/2/12
to git...@googlegroups.com
BTW, what version of Tomcat do you recommend for the WAR deploy?

On Feb 2, 2012, at 9:37 AM, James Moger wrote:

James Moger

unread,
Feb 2, 2012, 12:53:44 PM2/2/12
to git...@googlegroups.com
Tomcat 6 or 7 should be fine.

Drew

unread,
Feb 2, 2012, 9:45:18 PM2/2/12
to gitblit
So I got it working with Tomcat 7, Apache AJP and Java Service
Wrapper. It was pretty straight forward.

James Moger

unread,
Feb 3, 2012, 7:34:42 AM2/3/12
to git...@googlegroups.com
Nice. If you write it up I can include it in the next release of the site/docs.

-J

Drew Kutcharian

unread,
Feb 3, 2012, 12:56:52 PM2/3/12
to git...@googlegroups.com
Sure, I'll write it up and will email it to you.

Kosta

unread,
Feb 6, 2012, 9:02:21 AM2/6/12
to gitblit
I'd like to see an ajp-connector in the standalone (GO) version.
Any plans on adding ajp ?
Couldn't spot it on the Roadmap.

Note: For sure it would be possible to use the war-version and tomcat
to get ajp working, but as I use tomcat for ci-deployments its a
rather bad
idea to deploy gitblit to it. A separate tomcat-instance seems like an
overkill.
I guess there are many people that would like to use ajp with there
own reasons.

James Moger

unread,
Feb 6, 2012, 9:24:48 AM2/6/12
to git...@googlegroups.com
> I'd like to see an ajp-connector in the standalone (GO) version.
> Any plans on adding ajp ?

Open an issue for this and I'll see what I can do.

-J

James Moger

unread,
Feb 9, 2012, 7:46:25 PM2/9/12
to git...@googlegroups.com
Drew,

I looked into moving log4j.properties and I remember now why it is in inside the jar.  When this file is on the classpath it is automatically loaded by log4j both in deployment and in an IDE.  Otherwise you have to specify its location manually.  I can still do this but for the time being I won't because it complicates things when there are alternatives.

The -D parameter you tried specifying does work, but you have to specify it as a URL:

-Dlog4j.configuration=file:///home/james/log4j.properties

or in a full example:

java -Dlog4j.configuration=file:///home/james/log4j.properties -jar gitblit.jar <optional_gitblit_args>

I'll improve the documentation on this for the next release.

The following is Gitblit's log4j configuration.  I forgot that I had disabled the file appenders - they are defined just not activated.

#------------------------------------------------------------------------------
#
#  The following properties set the logging levels and log appender.  The
#  log4j.rootCategory variable defines the default log level and one or more
#  appenders.  For the console, use 'S'.  For the daily rolling file, use 'R'.
#  For an HTML formatted log, use 'H'.
#
#  To override the default (rootCategory) log level, define a property of the
#  form (see below for available values):
#
#        log4j.logger. =
#
#    Available logger names:
#      TODO
#
#    Possible Log Levels:
#      FATAL, ERROR, WARN, INFO, DEBUG
#
#------------------------------------------------------------------------------
log4j.rootCategory=INFO, S

#log4j.rootLogger=INFO
#log4j.logger.org=INFO
#log4j.logger.com=INFO
#log4j.logger.net=INFO

#log4j.logger.com.gitblit=DEBUG

log4j.logger.org.apache.wicket=INFO
log4j.logger.org.apache.wicket.RequestListenerInterface=WARN
log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=WARN

#------------------------------------------------------------------------------
#
#  The following properties configure the console (stdout) appender.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.S = org.apache.log4j.ConsoleAppender
log4j.appender.S.layout = org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern = %-5p %m%n

#------------------------------------------------------------------------------
#
#  The following properties configure the Daily Rolling File appender.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = logs/gitblit.log
log4j.appender.R.Append = true
log4j.appender.R.DatePattern = '.'yyy-MM-dd
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

#------------------------------------------------------------------------------
#
#  The following properties configure the Rolling File appender in HTML.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.H = org.apache.log4j.RollingFileAppender
log4j.appender.H.File = logs/gitblit.html
log4j.appender.H.MaxFileSize = 100KB
log4j.appender.H.Append = false
log4j.appender.H.layout = org.apache.log4j.HTMLLayout

Drew Kutcharian

unread,
Feb 10, 2012, 9:10:49 PM2/10/12
to git...@googlegroups.com
Thanks James. I ended up using Tomcat and was able to configure the logging using log4j. But I think it's a great idea to update the docs since most users will be using the standalone version.

-- Drew

Reply all
Reply to author
Forward
0 new messages