Browse Source

Add configuration files to (install) and run Gearman as a Solaris SMF service

Trond Norbye 16 years ago
parent
commit
50c22c7683
6 changed files with 169 additions and 1 deletions
  1. 3 0
      .bzrignore
  2. 1 0
      configure.ac
  3. 1 1
      scripts/Makefile.am
  4. 26 0
      scripts/gearmand.in
  5. 50 0
      scripts/gearmand.xml.in
  6. 88 0
      scripts/smf_install.sh.in

+ 3 - 0
.bzrignore

@@ -45,6 +45,9 @@ benchmark/blobslap_worker
 bin/gearman
 tests/cpp_test
 scripts/gearmand-init
+scripts/gearmand
+scripts/gearmand.xml
+scripts/smf_install.sh
 m4/libtool.m4
 m4/ltoptions.m4
 m4/ltsugar.m4

+ 1 - 0
configure.ac

@@ -356,6 +356,7 @@ AC_CHECK_PROGS([PERL], [perl])
 AC_CONFIG_FILES(Makefile libgearman/Makefile gearmand/Makefile bin/Makefile
                 tests/Makefile examples/Makefile scripts/Makefile
                 support/Makefile benchmark/Makefile scripts/gearmand-init
+                scripts/gearmand.xml scripts/gearmand scripts/smf_install.sh
                 support/gearmand.pc support/gearmand.spec)
 
 AC_OUTPUT

+ 1 - 1
scripts/Makefile.am

@@ -5,4 +5,4 @@
 # Use and distribution licensed under the BSD license.  See
 # the COPYING file in this directory for full text.
 
-EXTRA_DIST= gearmand-init
+EXTRA_DIST= gearmand-init gearmand.xml gearmand README.solaris

+ 26 - 0
scripts/gearmand.in

@@ -0,0 +1,26 @@
+#!/sbin/sh
+#
+# Script used to start Gearman from Solaris SMF
+#
+. /lib/svc/share/smf_include.sh
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+
+case "$1" in
+   'start')
+      /bin/coreadm -p "`svcprop -p gearman/corepattern $SMF_FMRI`" $$
+      @sbindir@/gearmand -d
+   ;;
+
+   'stop')
+      smf_kill_contract $2 TERM 1
+   ;;
+
+   *)
+      echo "Usage: $0 {start|stop}"
+      exit 1
+;;
+esac
+
+exit $SMF_EXIT_OK

+ 50 - 0
scripts/gearmand.xml.in

@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
+<service_bundle type="manifest" name="gearman">
+    <service name="application/database/gearman" type="service" version="1">
+        <single_instance/>
+
+        <dependency name="multi-user-server" grouping="require_all" restart_on="none" type="service">
+            <service_fmri value="svc:/milestone/multi-user-server" />
+        </dependency>
+
+        
+        <!-- We need to map the name of the authorizations we defined to this service -->
+        <property_group name="general" type="framework">
+            <propval name="action_authorization" type="astring" 
+                     value="solaris.smf.manage.gearman" />
+            <propval name="value_authorization" type="astring" 
+                     value="solaris.smf.value.gearman" />
+        </property_group>
+
+
+        <property_group name="gearman" type="application">
+            <propval name="corepattern" type="astring" value="core.%f.%p" />
+        </property_group>
+
+        <!-- Define the instance and how to start / stop it -->
+        <instance name="gearman" enabled="false">
+            <exec_method type="method" name="start" exec="/lib/svc/method/gearmand start" timeout_seconds="30" >
+                <method_context>
+                    <method_credential user="gearmand" group="gearmand" />
+                </method_context>
+            </exec_method>
+            <exec_method type="method" name="stop" exec="/lib/svc/method/gearmand stop  %{restarter/contract}" timeout_seconds="60" >
+                <method_context>
+                    <method_credential user="gearmand" group="gearmand" />
+                </method_context>
+            </exec_method>
+        </instance>
+        
+
+       <stability value="Unstable" />
+        <template>
+            <common_name>
+                <loctext xml:lang="C">Gearman job server</loctext>
+            </common_name>
+            <documentation>
+                <manpage title="gearman" section="1" manpath="@prefix@/share/man" />
+            </documentation>
+        </template>
+    </service>
+</service_bundle>

+ 88 - 0
scripts/smf_install.sh.in

@@ -0,0 +1,88 @@
+#! /bin/pfsh
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+
+grep solaris.smf.value.gearman /etc/security/auth_attr > /dev/null
+if [ $? -ne 0 ]
+then
+  ed /etc/security/auth_attr <<EOF
+a
+solaris.smf.value.gearman:::Change Gearman value properties::
+solaris.smf.manage.gearman:::Manage Gearman service states::
+.
+w
+q
+EOF
+  if [ $? -ne 0 ]
+  then
+    echo "Failed to add authorization definitions"
+    exit 1
+  fi
+fi
+
+grep solaris.smf.manage.gearman /etc/security/prof_attr
+if [ $? -ne 0 ]
+then
+  ed /etc/security/prof_attr <<EOF
+a
+Gearman Administration::::auths=solaris.smf.manage.gearman,solaris.smf.value.gearman
+.
+w
+q
+EOF
+
+  if [ $? -ne 0 ]
+  then
+    echo "Failed to add profile definitions"
+    exit 1
+  fi
+fi
+
+getent group gearmand > /dev/null
+if [ $? -ne 0 ]
+then
+  groupadd gearmand
+  if [ $? -ne 0 ]
+  then
+    echo "Failed to create group gearmand"
+    exit 1
+  fi
+fi
+
+getent passwd gearmand > /dev/null
+if [ $? -ne 0 ]
+then
+  roleadd -c "Gearman daemon" -d @localstatedir@ -g gearmand \
+          -A solaris.smf.value.gearman,solaris.smf.manage.gearman gearmand
+  if [ $? -ne 0 ]
+  then
+    echo "Failed to create role gearmand"
+    exit 1
+  fi
+
+  mkdir -p @localstatedir@ 
+  chown gearmand:gearmand @localstatedir@
+fi
+
+/usr/sbin/install -f /lib/svc/method gearmand
+if [ $? -ne 0 ]
+then
+  echo "Failed to install smf startup script"
+  exit 1
+fi
+
+/usr/sbin/install -f /var/svc/manifest/application -m 0444 gearmand.xml
+if [ $? -ne 0 ]
+then
+  echo "Failed to install smf definition"
+  exit 1
+fi
+
+svccfg import /var/svc/manifest/application/gearmand.xml
+if [ $? -ne 0 ]
+then
+  echo "Failed to import smf definition"
+  exit 1
+fi
+