[Mongrel] Mongrel under opensolars with SMF

snacktime snacktime at gmail.com
Tue Jun 26 13:09:24 EDT 2007


I create a single service with an instance for each mongrel.  The
start exec_method calls a shell script that first deletes the pid file
if it exists then runs mongrel directly with all the options as
arguments, no config file.  Right now we are just using :kill in the
stop exec_method.  Note the property group for the authorizations in
the service section.  This is what is used to allow a specific non
root user to control this service via svcadm in conjunction with an
entry in /etc/user_attr.  So far it's working pretty well but we still
need to make some adjustments, like telling the system to back off a
bit and send a notification if mongrel won't start, setting resource
limits, etc..


/etc/user_attr:
www::::auths=solaris.smf.manage.mongrel

Sample config with one instance:

<service_bundle type='manifest' name='Mongrel'>
  <service name='network/mongrel' type='service' version='0'>

    <dependency name='fs' grouping='require_all' restart_on='none'
type='service'>
      <service_fmri value='svc:/system/filesystem/local'/>
    </dependency>
    <dependency name='net' grouping='require_all' restart_on='none'
type='service'>
      <service_fmri value='svc:/network/loopback'/>
    </dependency>
    <dependent name='mongrel_multi-user' restart_on='none'
grouping='optional_all'>
      <service_fmri value='svc:/milestone/multi-user'/>
    </dependent>

        <property_group name='general' type='framework'>
       <propval name='action_authorization' type='astring'
value='solaris.smf.manage.mongrel' />
       <propval name='value_authorization' type='astring'
value='solaris.smf.manage.mongrel' />
    </property_group>

    <instance name='p8000' enabled='false'>
    <exec_method name='start' type='method'
exec='/opt/csw/lib/svc/method/svc-mongrel 8000' timeout_seconds='60'>
      <method_context working_directory='/opt/local/www/rails/staging/current'>
        <method_credential user='mongrel' group='www' />
        <method_environment>
          <envvar name="PATH" value="/usr/bin:/bin:/opt/csw/bin" />
        </method_environment>
      </method_context>
    </exec_method>

    <exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'>
      <method_context/>
    </exec_method>

    <property_group name='mongrel' type='application'>
      <stability value='Evolving' />
      <propval name='ssl' type='boolean' value='false' />
    </property_group>

      <property_group name='startd' type='framework'>
        <!-- sub-process core dumps shouldn't restart session -->
        <propval name='ignore_error' type='astring' value='core,signal' />
    </property_group>
  </instance>

  <!-- more instances here -->

   <stability value='Evolving' />
  </service>
</service_bundle>

svc-mongrel:
#!/sbin/sh
. /lib/svc/share/smf_include.sh


PORT=$1
ENVIRONMENT=staging
CWD=/opt/local/www/rails/$ENVIRONMENT/current
LOGFILE=/opt/local/www/rails/$ENVIRONMENT/shared/log/mongrel_$PORT.log
PIDFILE=/opt/local/www/rails/$ENVIRONMENT/shared/pids/mongrel_$PORT.pid
DOCROOT=$CWD/public
IP=10.1.1.4
USER=mongrel
GROUP=www

/bin/rm -f $PIDFILE

/opt/csw/bin/mongrel_rails start -d -e $ENVIRONMENT -p $PORT -a $IP -l
$LOGFILE -r $DOCROOT -c $CWD --user $USER --group $GROUP -P $PIDFILE


More information about the Mongrel-users mailing list