En este documento crearemos un nuevo servicio SMF en un Solaris 10.

Dicho servicio montará filesystems con el formato "lofs" leyendo un fichero llamado "vfstab.lofs".

Creamos fichero vfstab.lofs

En este fichero pondremos todos los puntos de montajes que queremos montar. El formato del fichero es el mismo que el de "/etc/vfstab":

vi /etc/vfstab.lofs
/var/www   -   /opt/www   lofs   -   yes   -
/var/images - /opt/www/images lofs - yes -
/var/scripts - /opt/www/cgi-bin lofs - yes -


Creamos el servicio SMF

1.- Creamos el script "fs-lofs" para arrancar, parar y reiniciar el servicio :

vi /lib/svc/method/fs-lofs 
#!/bin/sh
# DESC: SMF method definitions/wrapper.
# VERSION: $id$
#
# Sebastian Suarez
# 22/06/2008

. /lib/svc/share/smf_include.sh

case "$1" in
start)
cat /etc/vfstab.lofs |grep -v "#"|grep -v '^$' |while read MOUNTLINE;do
DEVICE=`echo $MOUNTLINE |awk '{print $1}'`
MOUNTPOINT=`echo $MOUNTLINE |awk '{print $3}'`
FSTYPE=`echo $MOUNTLINE |awk '{print $4}'`

/etc/mount -F $FSTYPE $DEVICE $MOUNTPOINT
done

if test "$?" = "0"
then
exit $SMF_EXIT_OK
elif test "$?" = "2"
then
echo "lofs filesystems: mount fail."
exit $SMF_EXIT_ERR_FATAL
else
echo "An unexpected error occured while trying to start lofs filesystems."
exit $SMF_EXIT_ERR_FATAL
fi
;;

stop)
cat /etc/vfstab.lofs |grep -v "#"|grep -v '^$' |while read MOUNTLINE;do
DEVICE=`echo $MOUNTLINE |awk '{print $1}'`
MOUNTPOINT=`echo $MOUNTLINE |awk '{print $3}'`
FSTYPE=`echo $MOUNTLINE |awk '{print $4}'`

/etc/umount $MOUNTPOINT
done
;;

refresh)
;;
esac

exit $SMF_EXIT_OK  

 

2.- Creamos el SMF manifiest del servicio que contiene los métodos para arrancar, parar, reiniciar, definición de dependencias, etc:

vi /var/svc/manifest/system/filesystem/lofs-fs.xml 
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type='manifest' name='lofs'>

<service
name='system/filesystem/lofs'
type='service'
version='1'>

<create_default_instance enabled='false' />

<single_instance/>

<dependency name='multi-user-server' type='service' grouping='require_all' restart_on='none'>
<service_fmri value='svc:/milestone/multi-user-server' />
</dependency>

<exec_method type='method' name='start' exec='/lib/svc/method/fs-lofs start' timeout_seconds='10' />
<exec_method type='method' name='stop' exec='/lib/svc/method/fs-lofs stop' timeout_seconds='10' />
<exec_method type='method' name='refresh' exec='/lib/svc/method/fs-lofs start' timeout_seconds='10' />

<stability value='Unstable' />

<template>
<common_name>
<loctext xml:lang='C'>
Servicio SMF de ejemplo sobre SunONE
</loctext>
</common_name>
<documentation>
<manpage title='Documentos Web Server' section='1M'
manpath='/software/documentacion' />
</documentation>
</template>
</service>

</service_bundle>

Nuestro servicio dependerá del servicio "milestone/multi-user-server". 

 

3.- Importamos el servicio en XML a SMF:

svccfg -v import  /var/svc/manifest/system/filesystem/lofs-fs.xml 
svccfg: Taking "initial" snapshot for svc:/system/filesystem/lofs:default.
svccfg: Taking "last-import" snapshot for svc:/system/filesystem/lofs:default.
svccfg: Refreshed svc:/system/filesystem/lofs:default.
svccfg: Successful import.

 

4.- Verificamos que el servicio se ha cargado correctamente y lo arrancamos:

svcs -l  svc:/system/filesystem/lofs 
svcadm enable svc:/system/filesystem/lofs