SMF support for Cool Stack Apache

Here are instructions on how to use SMF to manage Apache. These instructions assume no knowledge of SMF. All commands should be executed as root.

Create the manifest

 The manifest defines the service and controls the privileges with which the service will execute. We use the service name csk-httpd to distinguish this as a Cool Stack service (and not to cause any confusion with the httpd service that already exists).

Create a file named /var/svc/manifest/network/cskapache2.xml with the following contents :

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
    Copyright 2006-2007 Sun Microsystems, Inc.  All rights reserved.
    CSKapache2 manifest - should reside in /var/svc/manifest/network.
-->

<service_bundle type='manifest' name='CSKamp:apache'>

<service
    name='network/csk-http'
    type='service'
    version='1'>

    <!--
       Because we may have multiple instances of network/http
       provided by different implementations, we keep dependencies
       and methods within the instance.
    -->

    <instance name='CSKapache2' enabled='false'>
    <!--
       Wait for network interfaces to be initialized.
    -->
       <dependency name='network'
           grouping='require_all'
           restart_on='error'
           type='service'>
           <service_fmri value='svc:/milestone/network:default'/>
       </dependency>

       <!--
          Wait for all local filesystems to be mounted.
       -->
       <dependency name='filesystem-local'
           grouping='require_all'
           restart_on='none'
           type='service'>
           <service_fmri
               value='svc:/system/filesystem/local:default'/>
       </dependency>

       <!--
           Wait for automounting to be available, as we may be
           serving data from home directories or other remote
           filesystems.
       -->
       <dependency name='autofs'
           grouping='optional_all'
           restart_on='error'
           type='service'>
           <service_fmri
               value='svc:/system/filesystem/autofs:default'/>
       </dependency>

       <exec_method
           type='method'
           name='start'
           exec='/opt/coolstack/lib/svc/method/svc-cskapache2 start'
           timeout_seconds='60'>
           <method_context>
               <method_credential
                   user='webservd' group='webservd'
                   privileges='basic,!proc_session,!proc_info,!file_link_any,net_privaddr' />
           </method_context>
      </exec_method>

      <exec_method
           type='method'
           name='stop'
           exec='/opt/coolstack/lib/svc/method/svc-cskapache2 stop'
           timeout_seconds='60'>
           <method_context />
      </exec_method>

       <exec_method
           type='method'
           name='refresh'
           exec='/opt/coolstack/lib/svc/method/svc-cskapache2 refresh'
           timeout_seconds='60'>
           <method_context />
      </exec_method>

        <property_group name='httpd' 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>

    <stability value='Evolving' />
    <template>
        <common_name>
            <loctext xml:lang='C'>
                Apache 2 HTTP server
            </loctext>
        </common_name>
        <documentation>
            <manpage title='httpd' section='8'
                manpath='/opt/coolstack/apache2/man' />
            <doc_link name='apache.org'
                uri='http://httpd.apache.org' />
        </documentation>
    </template>
</service>

</service_bundle>

Create the method

Create the file /opt/coolstack/lib/svc/method/svc-cskapache2 referenced in the manifest with the following contents and make it executable. You will have to create all directories below /opt/coolstack/lib first.This file assumes a certain name and location for the apache configuration and pid file. Edit it if you are not using the default settings from Cool Stack.

#!/sbin/sh
#
# Copyright 2004-2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident "@(#)http-apache2       1.2     04/11/11 SMI"
# Modified for apache in CSKamp package of Cool Stack
# This file should reside in /opt/coolstack/lib/svc/method

. /lib/svc/share/smf_include.sh

APACHE_HOME=/opt/coolstack/apache2
CONF_FILE=$APACHE_HOME/conf/httpd.conf
PIDFILE=$APACHE_HOME/logs/httpd.pid

[ ! -f ${CONF_FILE} ] &&  exit $SMF_EXIT_ERR_CONFIG

case "$1" in
    start)
        /bin/rm -f ${PIDFILE}
        cmd="start"
        ;;
    refresh)
        cmd="graceful"
        ;;
    stop)
        cmd="stop"
        ;;
    \*)
        echo "Usage: $0 {start|stop|refresh}"
        exit 1
        ;;
esac

exec ${APACHE_HOME}/bin/apachectl $cmd 2>&1

Change file ownership

Since we want to start apache as user webservd (not root), we need to ensure that this user can write to the log directory and the pid file. All these files  reside in /opt/coolstack/apache2/logs by default.

# cd /opt/coolstack/apache2
# chown -R webservd logs
# chgrp -R webservd logs


Disable the Solaris http service

We do not want our service to conflict with the apache2 service that ships with Solaris. Note that by default, this service is disabled. You can check if it is enabled as follows :

# svcs |grep http

If no output is printed, then it is disabled. If you see something like :

maintenance    11:47:11 svc:/network/http:apache2

or

online    11:47:11 svc:/network/http:apache2

then, the service is up. Disable the service as follows : 

# svcadm -v disable http

svc:/network/http:apache2 disabled.
 

Start the csk-http service

Import the new service config as follows :

# svccfg -v import /var/svc/manifest/network/cskapache2.xml

We are now ready to start our service. Start it as follows :

# svcadm -v enable csk-http 

If the service starts successfully, you should see httpd processes running. A log of the service startup will be in /var/svc/log/network-csk-http:CSKapache2.log file. You can also get more detailed information for troubleshooting startup failures from the command svcs -x. More information on SMF can be found at  http://www.sun.com/bigadmin/content/selfheal/smf-quickstart.html

 

 


 

Comments:

When I run svcadm -v enable csk-http, I receive the following message: svcadm: Pattern 'csk-http' doesn't match any instances Any tips? TIA Christian

Posted by Christian Probst on April 20, 2007 at 03:45 PM PDT #

You need to import the manifest before svcadm will see it: # svccfg import /var/svc/manifest/network/cskapache2.xml # svcadm enable csk-http # svcs -xv csk-http svc:/network/csk-http:CSKapache2 (Apache 2 HTTP server) Hope that helps! -kyu

Posted by kyu on April 21, 2007 at 07:46 AM PDT #

Sorry about that. I forgot the import step in my instructions - I have now fixed this. Shanti

Posted by Shanti Subramanyam on April 23, 2007 at 01:16 AM PDT #

the service refuses to go online and goes in maintanance mode I was able to send it online removing the : --- <method_context> <method_credential user='webservd' group='webservd' privileges='basic,!proc_session,!proc_info,!file_link_any,net_privaddr' /> </method_context> --- part. ..yes I applied the commands: # cd /opt/coolstack/apache2 # chown -R webservd logs # chgrp -R webservd logs to the log folder.

Posted by Roberto on June 27, 2007 at 04:47 PM PDT #

I apologize for the previous post without html formatting
I repeate it to make it clear::

the service refuses to go online and goes in maintanance mode
I was able to send it online removing the :
---
<code> <method_context> <method_credential user='webservd' group='webservd' privileges='basic,!proc_session,!proc_info,!file_link_any,net_privaddr' /> </method_context> </code>
---
part.
..yes
I applied the commands:
# cd /opt/coolstack/apache2
# chown -R webservd logs
# chgrp -R webservd logs
to the log folder.

Posted by guest on June 27, 2007 at 04:52 PM PDT #

Hi Thanks for the post. Unfortunately the apache service goes into maintenance mode for me too. Will not start. I get the following error from the log file /var/svc/log/network-csk-http:CSKapache2.log Error is: /sbin/sh: /opt/coolstack/lib/svc/method/svc-cskapache2: not found Any ideas? Thanks Jamie

Posted by Jamie on July 01, 2007 at 10:00 PM PDT #

Hi Fixed it. My mistake. I had edited the script file above on winxp and transferred the file to my solaris zone. It left weird M\^ characters all over the text. That caused the problem. So instead I cut and past from the above into the script file. Hey presto! We have Apache as a service running. Thanks Jamie

Posted by Jamie on July 01, 2007 at 10:24 PM PDT #

FYI, remember to chmod the method making it executable.

Posted by Spiff on July 31, 2007 at 08:58 PM PDT #

Hello Shanti

I have exactly followed word by word from your blog but its still not working and says its in maintenance mode, can you be a little more specific?Are there anymore dependencies required?an early reply is appreciated.

Thank you
Naresh

Posted by naresh on December 23, 2009 at 04:49 AM PST #

First, Cool Stack is obsolete - it has been replaced by Web Stack. Secondly, the newest Cool Stack releases (1.3.x) included SMF support, so none of this is required. But please upgrade to Web Stack.

Posted by Shanti Subramanyam on December 24, 2009 at 12:14 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

I'm a Senior Staff Engineer in the Performance & Applications Engineering Group (PAE). This blog focuses on tips to build, configure, tune and measure performance of popular open source web applications on Solaris.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today