Gitosis Package

The SMF support is a very simple wrapper around the "git daemon" command. It will take all properties under the "git-daemon" property group and use them as arguments.

Configuring the Daemon

Step 0) Import the manifest: (This should be done by the package, no cost as the service is disabled by default)
# svccfg import git-daemon.xml

Step 1) Before enabling the service you have to set a few options:

# svccfg -s svc:/network/git-daemon:default setprop 'git-daemon/base-path = astring: "/var/opt/csw/gitosis/repositories"'

# svccfg -s svc:/network/git-daemon:default setprop 'git-daemon/export-all = astring: ""'

# svccfg -s svc:/network/git-daemon:default setprop 'git-daemon/verbose = astring: ""'

Step 2)

Enable the service:

# svcadm enable git-daemon

Creating multiple instances

Create the instance and "git-daemon" property group:

# svccfg -s svc:/network/git-daemon add test1234

# svccfg -s svc:/network/git-daemon:test1234 addpg git-daemon application

Now at least add a port property to make sure you don't get a port conflict with the default instance:

# svccfg -s svc:/network/git-daemon:test123 setprop 'git-daemon/verbose = astring: 9999'

Changing the User the git-daemon Is Running As

If you're for example exporting gitosis-managed repositories you might want git-daemon to run as the "gitosis" user and group. This is how you do that:

Adding the method_context property group if it is missing:

# svccfg -s svc:/network/git-daemon:test1234 addpg method_context framework

# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/user = astring: "webservd"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/group = astring: "webservd"'

For some reason it's required to set the whole set of method_context attribues (the actual set might be smaller but this works for me):

# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/limit_privileges = astring: ":default"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/privileges = astring: ":default"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/project = astring: ":default"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/resource_pool = astring: ":default"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/supp_groups = astring: ":default"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/use_profile = boolean: "false"'
# svccfg -s svc:/network/git-daemon:test1234 setprop 'method_context/working_directory = astring: ":default"'

NOTE: This is currently a work in progress. The SMF support will most likely be integrated directly into the git package.

git-daemon.xml

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
 
<service_bundle type="manifest" name="CSWgit:git-daemon">
 
<service name="network/git-daemon" type="service" version="1">
 
    <dependency name="fs-local" grouping="require_all" restart_on="none" type="service">
        <service_fmri value="svc:/system/filesystem/local"/>
    </dependency>
 
    <dependency name="net-physical" grouping="require_all" restart_on="none" type="service">
        <service_fmri value="svc:/network/physical"/>
    </dependency>
 
    <exec_method type="method" name="start" exec="/opt/csw/lib/svc/method/svc-git-daemon start" timeout_seconds="60"/>
 
<!--
    <exec_method type="method" name="stop" exec="/opt/csw/lib/svc/method/svc-git-daemon stop" timeout_seconds="60"/>
-->
    <exec_method type="method" name="stop" exec=":kill" timeout_seconds="60"/>
 
    <instance name="default" enabled="false">
        <property_group name="git-daemon" type="instance">
<!--
            <propval name="arguments" type="astring" value="- -base-path=/home/trygvis/tmp/git-daemon - -export-all - -verbose"/>
-->
            <propval name="base-path" type="astring" value="/home/trygvis/tmp/git-daemon"/>
            <propval name="export-all" type="astring" value=""/>
            <propval name="port" type="astring" value="9999"/>
        </property_group>
    </instance>
 
    <template>
        <common_name>
            <loctext xml:lang="C">Git Daemon</loctext>
        </common_name>
        <documentation>
            <manpage title="git-daemon" section="1" manpath="/opt/csw/share/man"/> 
        </documentation>
    </template>
 
</service>
 
</service_bundle>

/opt/csw/lib/svc/method/svc-git-daemon

#!/bin/sh

set -e

. /lib/svc/share/smf_include.sh

start() {
  echo "Starting git-daemon, running as " `id`

  echo "Arguments (one per line):"
  args="--detach"
  echo "--detach"
  # Find all properties under "git-daemon/*" and use them as arguments
#  svcprop -p git-daemon $SMF_FMRI|sed "s,\(git-daemon/.*\) astring.*,\1," | while read property
  for property in `svcprop -p git-daemon $SMF_FMRI|sed "s,git-daemon/\(.*\) astring.*,\1,"`
  do
    arg=`svcprop -p git-daemon/$property $SMF_FMRI`
    if [ "$arg" = '""' ]
    then
      echo "--$property"
    args="$args --$property"
    else
      echo "--$property=$arg"
    args="$args --$property=$arg"
    fi
  done
  /opt/csw/bin/git daemon $args
}

case "$1" in
start)
  start
  ;;

*)
  exit 1
  ;;
esac

exit $SMF_EXIT_OK
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License