Mercurial hook not executing properly

后端 未结 9 1438
北恋
北恋 2020-12-30 12:02

This should be a very simple thing to have run, but for some reason it won\'t work with my Mercurial repository. All I want is for the remote repo to automatically run

9条回答
  •  我在风中等你
    2020-12-30 12:48

    Tthe reason I've found for this has nothing to do with redirecting stdout to stderr. As you may see in the wiki page it is not specified on the wiki's current version https://www.mercurial-scm.org/wiki/FAQ#FAQ.2FCommonProblems.Any_way_to_.27hg_push.27_and_have_an_automatic_.27hg_update.27_on_the_remote_server.3F

    The problem I've found is around permissions.

    In my original setup, I had a user, lets say hguser with a repo on its home, and a script /etc/init.d/hg.init to launch hg serve. The problem being hg serve was being run by root, while most files under the repo pertained to hguser (some of them switched to root at some point, but it won't mind, since I'll correct them with chown)

    Solution:

    • chown -R hguser:hguser /home/hguser/repo (to correct ALL files, back to hguser)
    • launch su hguser -c "hg serve ..." (in my case from /etc/init.d/hg.init)
    • changegroup = hg update -C under [hooks] in repo/.hg/hgrc as usual

    Now it should work on push

    PS: in my case, I rather update to the head of a specific branch, so I use hg update -C -r staging, to make the staging server update only to the head of the intended branch, even if the tip is from another branch (like development for instance)

    BTW my hg.init script ended up like this: (notice the su hguser part)

    #!/bin/sh
    #
    # Startup script for mercurial server.
    #
    # @see http://jf.blogs.teximus.com/2011/01/running-mercurial-hg-serve-on-linux.html
    
    HG=/usr/bin/hg
    CONF=/etc/mercurial/hgweb.config
    # Path to PID file of running mercurial process.
    PID_FILE=/etc/mercurial/hg.pid
    
    state=$1
    
    case "$state" in
    'start')
        echo "Mecurial Server service starting."
        (su hguser -c "${HG} serve -d --webdir-conf ${CONF} -p 8000 --pid-file ${PID_FILE}")
      ;;
    
    'stop')
      if [ -f "${PID_FILE}" ]; then
        PID=`cat "${PID_FILE}"`
        if [ "${PID}" -gt 1 ]; then
          kill -TERM ${PID}
          echo "Stopping the Mercurial service PID=${PID}."
        else
          echo Bad PID for Mercurial -- \"${PID}\"
        fi
      else
    
        echo No PID file recorded for mercurial
      fi
      ;;
    
    *)
      echo "$0 {start|stop}"
      exit 1
      ;;
    esac
    

    PS: due credit to http://jf.blogs.teximus.com/2011/01/running-mercurial-hg-serve-on-linux.html

提交回复
热议问题