CFengine 3 Tutorial -- Part 2 -- Building Software and SMF Manifests / Scripts


** CFEngine and dependencies Building OpenSSL **

$ echo PATH
/usr/bin:/usr/sbin:/sbin:/bin:/usr/sfw/bin:/usr/local/bin:/usr/ccs/bin
/var/tmp/openssl-1.0.0 $ ./Configure solaris-x86-gcc shared
--prefix=/usr/local/ssl --openssldir=/usr/local/ssl
/var/tmp/openssl-1.0.0 $ gmake
/var/tmp/openssl-1.0.0 $ gmake install

Building PCRE

/var/tmp/pcre-8.02 $ echo $LDFLAGS
-L/usr/sfw/lib -L/usr/sfw/lib
/var/tmp/pcre-8.02 $ ./configure --disable-cpp CFLAGS="-g -O3" CC=gcc
--enable-utf8 --enable-unicode-properties
/var/tmp/pcre-8.02 $ gmake
/var/tmp/pcre-8.02 $ sudo gmake install

Building CFEngine

Note: I modify the Makefile to statically compile in the BerkeleyDB, OpenSSL, and libpcre libraries into the CFEngine binaries. I also modify the reference for pthread to pthreads for Solaris. These adjustments to the Makefile are dependant on how you built the software above. Caveat emptor

/var/tmp/cfengine-3.0.4 $ export
LD_LIBRARY_FLAGS=/usr/sfw/lib:/usr/local/lib:/usr/lib
/var/tmp/cfengine-3.0.4 $ export CC=/usr/sfw/bin/gcc
/var/tmp/cfengine-3.0.4 $ ./configure --prefix=/var/cfengine
--with-openssl=/usr/local/ssl --without-sql
--with-berkeleydb=/usr/local/BerkeleyDB/4.4 --enable-static
/var/tmp/cfengine-3.0.4 $ cd src
/var/tmp/cfengine-3.0.4/src $ perl -p -i.sav -e
"s:-ldb:/usr/local/BerkeleyDB/4.4/lib/libdb.a:" Makefile
/var/tmp/cfengine-3.0.4/src $ perl -p -i.sav -e
"s:-lcrypto:/usr/local/ssl/lib/libcrypto.a:" Makefile
/var/tmp/cfengine-3.0.4/src $ perl -p -i.sav -e
"s:-lpcre:/usr/local/lib/libpcre.a:" Makefile
/var/tmp/cfengine-3.0.4/src $ perl -p -i.sav -e
"s:-pthread:-pthreads:" Makefile
/var/tmp/cfengine-3.0.4/src $ cd ..
/var/tmp/cfengine-3.0.4 $ gmake
/var/tmp/cfengine-3.0.4 $ gmake install

Subversion and dependencies. Building apr

/var/tmp $ bunzip2 apr-1.4.2.tar.bz2
/var/tmp $ tar -xf apr-1.4.2.tar
/var/tmp $ cd apr-1.4.2
/var/tmp/apr-1.4.2 $ ./configure --prefix=/usr/local/apr
/var/tmp/apr-1.4.2 $ gmake
/var/tmp/apr-1.4.2 $ sudo gmake install

Building apr-util

/var/tmp $ bunzip2 apr-util-1.3.9.tar.bz2
/var/tmp $ tar -xf apr-util-1.3.9.tar
/var/tmp $ cd apr-util-1.3.9
/var/tmp/apr-util-1.3.9 $ ./configure --with-apr=/usr/local/apr
/var/tmp/apr-util-1.3.9 $ gmake
/var/tmp/apr-util-1.3.9 $ sudo gmake install

Building sqlite

/var/tmp $ tar -xf sqlite-amalgamation-3.6.23.1.tar
/var/tmp/sqlite-3.6.23.1 $ ./configure
/var/tmp/sqlite-3.6.23.1 $ gmake
/var/tmp/sqlite-3.6.23.1 $ gmake install

Building Subversion

/var/tmp $ tar -xf subversion-1.6.12.tar
/var/tmp/subversion-1.6.12 $ echo $LD_LIBRARY_PATH
/usr/lib:/usr/share/lib:/usr/ccs/lib:/usr/sfw/lib:/usr/dt/lib:/usr/openwin/lib:/usr/java/lib:/usr/local/lib:/usr/local/lib/mysql:/usr/local/ssl/lib:/usr/local/apr/lib
/var/tmp/subversion-1.6.12 $ ./configure
--with-apr-util=/usr/local/apr --with-apr=/usr/local/apr
--without-berkeley-db --with-sqlite=/usr/local
/var/tmp/subversion-1.6.12 $ gmake
/var/tmp/subversion-1.6.12 $ gmake install

SMF Manifests / Scripts

I’ve created SMF manifests for cf-execd, cf-monitord, and cf-serverd. Clients should run cf-monitord and cf-execd. Master Policy Servers should run all three daemons. The SMF manifests / scripts for all 3 daemons are exactly the same, substitute the names of the daemons / descriptions. This is Solaris 10 specific.

$ ` svcs -a | grep cfengine`   
online Jun_30 svc:/application/cfengine/cf-serverd:default
online Jun_30 svc:/application/cfengine/cf-monitord:default
online Jun_30 svc:/application/cfengine/cf-execd:default

$ ` svccfg export cf-serverd`   
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM
'/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
<service name='application/cfengine/cf-serverd' type='service'
version='0'>
<create_default_instance enabled='true'/>
<single_instance/>
<exec_method name='start' type='method'
exec='/var/cfengine/etc/cf-serverd.sh %m' timeout_seconds='60'>
<method_context>
<method_credential user='root'/>
</method_context>
</exec_method>
<exec_method name='restart' type='method'
exec='/var/cfengine/etc/cf-serverd.sh %m' timeout_seconds='60'>
<method_context>
<method_credential user='root'/>
</method_context>
</exec_method>
<exec_method name='stop' type='method'
exec='/var/cfengine/etc/cf-serverd.sh %m' timeout_seconds='60'>
<method_context>
<method_credential user='root'/>
</method_context>
</exec_method>
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='contract'/>
</property_group>
<template>
<common_name>
<loctext xml:lang='C'>Cfengine server process</loctext>
</common_name>
<documentation>
<doc_link name='Further information'
uri='http://www.cfengine.org/manuals/cf3-reference.html'/>
</documentation>
</template>
</service>
</service_bundle>

$ ` cat /var/cfengine/etc/cf-serverd.sh`   
#!/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
start)
echo "Starting cf-serverd"
/var/cfengine/bin/cf-serverd
;;

stop)
echo "Stopping cf-serverd"
kill -15 `cat /var/cfengine/cf-serverd.pid`
;;

restart|force-reload)
$ `0 stop`   
sleep 1
$ `0 start`   
;;

*)
N=/var/cfengine/etc/cf-serverd.sh
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
This article was posted by Matty on 2010-07-02 12:06:00 -0400 -0400