4

As stated in subject. I have this script that works fine from command line:

#!/sbin/sh

GITCOMMAND="git daemon --base-path=/my/git/repo --export-all --enable=receive-pack --reuseaddr"

startcmd () {
    `$GITCOMMAND`
}

stopcmd () {
    pkill -f "git *"
}

case "$1" in
'start')
        startcmd
        ;;
'stop')
        stopcmd
        ;;
'restart')
        stopcmd
        sleep 1
        startcmd
        ;;
*)
        echo "Usage: $0 { start | stop | restart }"
        exit 1
        ;;
esac

and this SMF configuration:

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type="manifest" name="git-server">
  <service name="site/git-server" type="service" version="1">
  <create_default_instance enabled="true"/>
  <single_instance/>
  <dependency name="network" grouping="require_all" restart_on="refresh" type="service">
    <service_fmri value="svc:/milestone/network:default"/>
  </dependency>
  <dependency name="filesystem" grouping="require_all" restart_on="refresh" type="service">
    <service_fmri value="svc:/system/filesystem/local"/>
  </dependency>

  <method_context working_directory="/home/massive/massive-lannister">
    <method_credential user="admin" group="staff" privileges='basic,net_privaddr'  />
    <method_environment>
      <envvar name="PATH" value="/usr/local/bin:/usr/bin:/usr/sbin:/bin"/>
      <envvar name="HOME" value="/develop"/>
    </method_environment>
  </method_context>

  <exec_method
    type="method"
    name="start"
    exec="/usr/local/bin/start-stop-git.sh start"
    timeout_seconds="60"/>

  <exec_method
    type="method"
    name="stop"
    exec="/usr/local/bin/start-stop-git.sh stop"
    timeout_seconds="60"/>

  <property_group name="startd" type="framework">
    <propval name="duration" type="astring" value="child"/>
    <propval name="ignore_error" type="astring" value="core,signal"/>
  </property_group>

  <property_group name="application" type="application">
  </property_group>

  <stability value="Evolving"/>

  <template>
    <common_name>
      <loctext xml:lang="C">git server service</loctext>
    </common_name>
  </template>
  </service>
</service_bundle>

service registers and enables without any errors on command line, but does not run:

# svcs -xv
svc:/site/git-server:default (git server service)
 State: maintenance since Sun Mar 16 02:29:04 2014
Reason: Method failed.
   See: http://illumos.org/msg/SMF-8000-8Q
   See: /var/svc/log/site-git-server:default.log
Impact: This service is not running.

Log file does not reveal much:

# cat /var/svc/log/site-git-server:default.log
[ Mar 16 02:29:04 Enabled. ]
[ Mar 16 02:29:04 Executing start method ("/usr/local/bin/start-stop-git.sh start"). ]
[ Mar 16 02:29:04 Stopping because service exited with a configuration error. ]

I'm not sure where to go from here. Any help will be appreciated.

3

OK, so I found a problem in my SMF config XML. If anyone would benefit from this, here's the working solution:

/usr/local/bin/start-stop-git.sh

#!/sbin/sh

GITCOMMAND="git daemon --base-path=/my/git/repo --export-all --enable=receive-pack --reuseaddr"

startcmd () {
    `$GITCOMMAND`
}

stopcmd () {
    pkill -f "git *"
}

case "$1" in
'start')
        startcmd
        ;;
'stop')
        stopcmd
        ;;
'restart')
        stopcmd
        sleep 1
        startcmd
        ;;
*)
        echo "Usage: $0 { start | stop | restart }"
        exit 1
        ;;
esac

git-server.xml:

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type="manifest" name="git-server">
  <service name="site/git-server" type="service" version="1">
  <create_default_instance enabled="true"/>
  <single_instance/>
  <dependency name="network" grouping="require_all" restart_on="refresh" type="service">
    <service_fmri value="svc:/milestone/network:default"/>
  </dependency>
  <dependency name="filesystem" grouping="require_all" restart_on="refresh" type="service">
    <service_fmri value="svc:/system/filesystem/local"/>
  </dependency>

  <method_context working_directory="/develop">
    <method_credential user="admin" group="staff" privileges='basic,net_privaddr'  />
    <method_environment>
      <envvar name="PATH" value="/opt/local/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin"/>
      <envvar name="HOME" value="/develop"/>
    </method_environment>
  </method_context>

  <exec_method
    type="method"
    name="start"
    exec="/usr/local/bin/start-stop-git.sh start"
    timeout_seconds="60"/>

  <exec_method
    type="method"
    name="stop"
    exec="/usr/local/bin/start-stop-git.sh stop"
    timeout_seconds="60"/>

  <property_group name="startd" type="framework">
    <propval name="duration" type="astring" value="child"/>
    <propval name="ignore_error" type="astring" value="core,signal"/>
  </property_group>

  <property_group name="application" type="application">
  </property_group>

  <stability value="Evolving"/>

  <template>
    <common_name>
      <loctext xml:lang="C">git server service</loctext>
    </common_name>
  </template>
  </service>
</service_bundle>

To install and verify:

#svccfg import git-server.xml
#svcadm enable git-server
#svcs -xv

The last command should not print anything if system is healthy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.