Artem,
Since you're running Ubuntu, you should really use Upstart for
controlling the git-daemons and git-proxy processes on your server
(shameless self promotion: I have written an article about Upstart on
my personal blog:
http://zmalltalker.com/linux/init-scripts-part-1.html)

Assuming you're running the latest version of Gitorious, you should
create an Upstart recipe for your Git daemons and make it look like
this:

# /etc/init/git-daemons.conf
description "Native git daemons on port 9400"
author "Marius Mårnes Mathiesen <mar...@gitorious.com>"

script
  /usr/bin/git daemon --listen=0.0.0.0 --port=9400 --syslog
  --export-all --base-path=<PATH TO YOUR REPOSITORIES> --verbose
  --reuseaddr --user=git --group=git <PATH TO YOUR REPOSITORIES>
end script

start on started rc RUNLEVEL=[35]
stop on runlevel [06]

Next, you should set up your git-proxy process to start whenever
git-daemons is started. It should look like this:

# /etc/init/git-daemons.conf
description "Git proxy on 9418 to 9400"
author "Marius Mårnes Mathiesen <mar...@gitorious.com>"

start on started git-daemons
stop on stopped git-daemons

env RAILS_ENV=production
# If your Ruby is not in PATH, add it to PATH here:
env PATH=/opt/ruby-enterprise/bin:$PATH


exec <PATH TO YOUR GITORIOUS INSTALLATION>/script/git-proxy -h 127.0.0.1

Insert the correct paths in the two files above (anything in UPPERCASE
between brackets).
After you have added these two files, let Upstart know about them:

% initctl reload-configuration

And then start the git daemons:

% start git-daemons

This should first start your git daemons, and once they are started
start the git proxy. Both processes should be started when the
machine starts and stop when it shuts down. To see the status:

% initctl list | grep git

Cheers,
- Marius

On Thu, Nov 29, 2012 at 04:47:20AM -0800, Artem Silenkov wrote:
> Good day!
>
> We have a problem with git-proxy init script. Git-proxy run fine with it
> and daemonize but after few minutes stop to do any work.
> With error in log
> Looking up "/project/repo.git"
> IOError - closed stream
>
> So no client could push-pull with
> fatal: The remote end hung up unexpectedly
>
> Process is in working state even could strace it but brocken somehow. I'm
> not ruby programmer but guess that it is logger problem after daemonizing
> like here.
> http://stackoverflow.com/questions/1711603/ruby-daemons-causing-activerecord-logger-ioerror
>
> We tried to hack git-proxy script with no success.
>
> This is our init script under ubuntu 12.04
>
> #! /bin/sh
> ### BEGIN INIT INFO
> # Provides:          git-proxy
> # Required-Start:
> # Required-Stop:
> # Default-Start:     2 3 4 5
> # Default-Stop:      0 1 6
> # Short-Description: GIT-proxy server daemon
> # Description:       Starts the GIT-proxy needed by Gitorious
> ### END INIT INFO
>
> # Author: Fabio Akita <*******@gmail.com>
> # adapted for git-proxy by 2gis team
>
> RUBY_HOME="/opt/ruby-enterprise"
> GITORIOUS_HOME="/var/www/gitorious"
> RETVAL=0
> PROG="git-proxy"
> PID_FILE=$GITORIOUS_HOME/log/git-proxy.pid
> GIT_DAEMON="$RUBY_HOME/bin/ruby $GITORIOUS_HOME/script/git-proxy
> --pid=$PID_FILE"
> LOCK_FILE=/var/lock/git-proxy
>
> export RAILS_ENV=production
>
> do_check_pid() {
>   if [ -f $PID_FILE ]; then
>     PID=`cat $PID_FILE`
>     RUNNING=`ps --pid $PID | wc -l`
>   else
>     PID=0
>     RUNNING=0
>   fi
> }
>
> runlevel=`runlevel | awk '{print $2}'`
>
> start()
> {
>   do_check_pid
>   if [ $RUNNING != 2 ] ; then
>     echo -n "Starting $PROG"
>     /bin/su - git -c "export RAILS_ENV=production;$GIT_DAEMON" 2>&1
> >/dev/null
>     sleep 1
>     if [ -f $PID_FILE ] ; then
>       echo "."
>       RETVAL=0
>     else
>       echo ": FAILURE!!!"
>       RETVAL=1
>     fi
>   else
>     echo "$PROG already running"
>     RETVAL=1
>   fi
>   [ "$RETVAL" = 0 ] && touch $LOCK_FILE
> }
>
> stop()
> {
>   do_check_pid
>   if [ $RUNNING != 2 ] ; then
>     echo "$PROG not running"
>   else
>     echo -n "Stopping $PROG"
>     PROGPID=`cat $PID_FILE`
>     kill -TERM $PROGPID && echo "."
>   fi
>   RETVAL=0
>   # if we are in halt or reboot runlevel kill all running sessions
>   # so the TCP connections are closed cleanly
>   if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
>     PROGPID=`cat $PID_FILE`
>     kill -9 $PROGPID > /dev/null
>   fi
>   [ "$RETVAL" = 0 ] && {
>     rm -f $LOCK_FILE && rm -f $PID_FILE
>   }
> }
>
> case "$1" in
>   start)
>     start
>     ;;
>   stop)
>     stop
>     ;;
>     restart)
>         stop
>         start
>         ;;
>   condrestart)
>     if [ -f $LOCK_FILE ] ; then
>       if [ "$RETVAL" = 0 ] ; then
>         stop
>         # avoid race
>         sleep 10
>         start
>       fi
>     fi
>     ;;
>   *)
>     echo "Usage: $0 {start|stop|restart|condrestart}"
>     RETVAL=1
> esac
> exit $RETVAL
>
> #EOF
>
> When git-proxy started in console or with cron as described above there
> were no errors only when daemonized. No matter how much users try to
> pushpull.
>
> We need more knowledge to investigate further ))
>
>
> вторник, 11 сентября 2012 г., 20:47:27 UTC+7 пользователь Marius Mårnes
> Mathiesen написал:
> >
> > On Fri, Aug 17, 2012 at 6:25 PM, Austin Montgomery 
> > <mont...@gmail.com<javascript:>
> > > wrote:
> >
> >> So I have come up with a solution. I added the following line to my git
> >> users crontab and it has the git-proxy up and running without a hitch on
> >> reboot.
> >>
> >> * * * * * cd /var/www/gitorious && env RAILS_ENV=production bundle exec
> >> script/git-proxy 2>&1 >/dev/null
> >>
> >>
> > Austin,
> > Glad to hear you got it working. A couple of alternatives:
> >
> > - Use a process monitoring tool like Monit (apt-get install monit). By
> > writing a small recipe you can have monit ensure your process (identified
> > by a pid file, which the git-proxy script will create) is running. It will
> > even make sure the proxy is available on a specific port and can be set up
> > to restart the service if it consumes too much resources
> > - Create a script in /etc/init.d like you suggested
> > - Even better, as Ubuntu has moved from /etc/init.d scripts to Upstart,
> > place a script in eg. /etc/init/git-proxy.conf - my Upstart knowledge is a
> > little rusty, but I'm sure someone on the list can share something...
> >
> > Cheers,
> > - Marius
> >
>
> --
> To post to this group, send email to gitorious@googlegroups.com
> To unsubscribe from this group, send email to
> gitorious+unsubscr...@googlegroups.com

-- 
To post to this group, send email to gitorious@googlegroups.com
To unsubscribe from this group, send email to
gitorious+unsubscr...@googlegroups.com

Reply via email to