Solaris: Adding Samba to the Service Management Facility

I am a bit new to the Service Management Facility (SMF) introduced into Solaris 10, but after getting my feet wet I kinda like it. These steps came in handy for me when I needed to add Samba to SMF.

Backup and Remove samba rc* scripts

bash-3.00# tar cvpf - /etc/rc?.d/???samba | gzip -c > /var/tmp/etc-rc-samba.tar.gz
a /etc/rc0.d/K03samba 1K
a /etc/rc1.d/K03samba link to /etc/rc0.d/K03samba
a /etc/rc2.d/K03samba link to /etc/rc0.d/K03samba
a /etc/rc3.d/S90samba link to /etc/rc0.d/K03samba
a /etc/rcS.d/K03samba link to /etc/rc0.d/K03samba

Verify the archive:

bash-3.00# gunzip < /var/tmp/etc-rc-samba.tar.gz | tar -tvpf -

Wait!! Let’s hold off on removing the samba rc* files until everything is working properly.

The following version and components of samba were installed at the time of this writing:

bash-3.00# pkginfo -l | grep samba
NAME: samba - A Windows SMB/CIFS fileserver for UNIX (client)
DESC: samba - A Windows SMB/CIFS fileserver for UNIX (client) 3.0.11
NAME: samba - A Windows SMB/CIFS fileserver for UNIX (Root)
DESC: samba - A Windows SMB/CIFS fileserver for UNIX (Root) 3.0.11
NAME: samba - A Windows SMB/CIFS fileserver for UNIX (Usr)
DESC: samba - A Windows SMB/CIFS fileserver for UNIX (Usr) 3.0.11

Create and edit the smb.conf file
In the /etc/sfw directory copy the example smb.conf-example file to smb.conf and edite to your liking. I like to copy the sample file to smb-<server_name>.conf.

bash-3.00# pwd
/etc/sfw
bash-3.00# ls -l
total 66
...edited...
-rw-r--r-- 1 root bin 9975 Feb 12 11:01 smb.conf-example

bash-3.00# cp smb.conf-example smb-<server_name>.conf
bash-3.00# vi !$

Creating the control script
The control script: /lib/svc/method/samba will contain the following:

bash-3.00# cat > /lib/svc/method/samba

#! /sbin/sh
#

. /lib/svc/share/smf_include.sh

case “$1″ in
‘start’)
echo ‘Starting samba services: ‘
/usr/sfw/sbin/smbd -s /etc/sfw/smb-<server_name>.conf -D
/usr/sfw/sbin/nmbd -s /etc/sfw/smb-<server_name>.conf -D
;;
‘stop’)
/usr/bin/pkill smbd
/usr/bin/pkill nmbd
exit 0
;;
‘refresh’)
echo ‘Refreshing samba services:’
/usr/bin/pkill -HUP smbd
/usr/bin/pkill -HUP nmbd
exit 0
;;
*)
echo “Usage: $0 { start | stop | refresh }”
exit 1
;;
esac
#EOF

Change Permissions and ownership for the Control Script:
The control script needs to be executable.

bash-3.00# ls -l "/lib/svc/method/samba"
-rw-r--r-- 1 root root 465 Feb 12 13:52 /lib/svc/method/samba
bash-3.00# chown :bin "/lib/svc/method/samba"
bash-3.00# chmod +x "/lib/svc/method/samba"
bash-3.00# ls -l !$
ls -l "/lib/svc/method/samba"
-rwxr-xr-x 1 root bin 465 Feb 12 13:52 /lib/svc/method/samba

The manifest: /var/svc/manifest/network/samba.xml

Create the manifest file and edit where appropiate:

bash-3.00# cat > /var/svc/manifest/network/samba.xml
<?xml version=”1.0″?>
<!DOCTYPE service_bundle SYSTEM “/usr/share/lib/xml/dtd/service_bundle.dtd.1″>
<service_bundle type=”manifest” name=”SUNWsmbar:samba”>
<service name=”network/samba” type=”service” version=”1″>
<create_default_instance enabled=”false”/>
<single_instance/>
<!–
First of all, if the config file is not present,
then we needn”t bother with anything else.
–>
<dependency name=”config-file” grouping=”require_all” restart_on=”none” type=”path”>
<service_fmri value=”file:///etc/sfw/smb-server_name.conf”/>
</dependency>

<!–
If there”s no network, then there”s no point in running
–>
<dependency name=”loopback” grouping=”require_all” restart_on=”error” type=”service”>
<service_fmri value=”svc:/network/loopback:default”/>
</dependency>
<dependency name=”physical” grouping=”optional_all” restart_on=”error” type=”service”>
<service_fmri value=”svc:/network/physical:default”/>
</dependency>

<!–
Since Samba may be providing a home directory service,
it is as well that we ensure that the file-systems are
all mounted before it is started. This is not essential
but in general it is a good thing and doesn”t really hurt.
–>
<dependency name=”fs-local” grouping=”require_all” restart_on=”none” type=”service”>
<service_fmri value=”svc:/system/filesystem/local”/>
</dependency>

<!–
now we have the start stop and refresh methods
–>
<exec_method type=”method” name=”start” exec=”/lib/svc/method/samba start” timeout_seconds=”60″/>
<exec_method type=”method” name=”stop” exec=”/lib/svc/method/samba stop” timeout_seconds=”60″/>
<exec_method type=”method” name=”refresh” exec=”/lib/svc/method/samba refresh” timeout_seconds=”60″/>

<property_group name=”samba” type=”application”>
<stability value=”Evolving”/>
</property_group>
<property_group name=”startd” type=”framework”>
<propval name=”ignore_error” type=”astring” value=”core,signal”/>
</property_group>

<stability value=”Evolving”/>
<!–
A description of the Service
–>
<template>
<common_name>
<loctext xml:lang=”C”>Samba Server</loctext>
</common_name>
<documentation>
<manpage title=”samba” section=”1M”/>
<doc_link name=”samba.org” uri=”http://www.samba.org/docs/”/&gt;
</documentation>
</template>
</service>
</service_bundle>
# EOF


Double-check the manifest for errors

bash-3.00# svccfg validate /var/svc/manifest/network/samba.xml
bash-3.00#

If there are errors in the file you will get an error like the below, just double-check the file for correctness. If no complaints from validating then all should be good.
bash-3.00# svccfg validate /var/svc/manifest/network/samba.xml
svccfg: couldn't parse document

Importing the Manifest in order to start and stop samba

bash-3.00# svccfg import /var/svc/manifest/network/samba.xml
bash-3.00#

Enabling Samba

bash-3.00# svcadm -v enable samba
svc:/network/samba:default enabled.
bash-3.00# svcs | grep samba
online 14:31:10 svc:/network/samba:default
bash-3.00# svcs -l samba
fmri svc:/network/samba:default
name Samba Server
enabled true
state online
next_state none
state_time Mon Feb 12 14:31:10 2007
logfile /var/svc/log/network-samba:default.log
restarter svc:/system/svc/restarter:default
contract_id 31
dependency require_all/none file:///etc/sfw/smb-server_name.conf (online)
dependency require_all/error svc:/network/loopback:default (online)
dependency optional_all/error svc:/network/physical:default (online)
dependency require_all/none svc:/system/filesystem/local (online)

If all want well, verify that samba is running by trying to access a share through Windows (Start->Run, then enter the name of your server. E.g., \\server_name). You can also check the output of ps, though this may not mean everything is working.

bash-3.00# ps -ef | grep smb
root 269 1 0 14:31:10 ? 0:00 /usr/sfw/sbin/smbd -s /etc/sfw/smb-server_name.conf -D
root 273 269 0 14:31:10 ? 0:00 /usr/sfw/sbin/smbd -s /etc/sfw/smb-server_name.conf -D
root 276 1 0 14:31:10 ? 0:00 /usr/sfw/sbin/nmbd -s /etc/sfw/smb-server_name.conf -D
root 688 643 0 15:26:59 pts/1 0:00 grep smb
Removing the older samba rc* files
Ok. If everything sent well, then old samba rc* files can be removed, but they do not have to be.

bash-3.00# rm -i /etc/rc?.d/???samba
rm: remove /etc/rc0.d/K03samba (yes/no)? yes
rm: remove /etc/rc1.d/K03samba (yes/no)? yes
rm: remove /etc/rc2.d/K03samba (yes/no)? yes
rm: remove /etc/rc3.d/S90samba (yes/no)? yes
rm: remove /etc/rcS.d/K03samba (yes/no)? yes

Don’t forget to remove /etc/init.d/samba

bash-3.00# rm -i /etc/init.d/samba
rm: remove /etc/init.d/samba (yes/no)? yes
bash-3.00#

The below resources helped me greatly and provide more in depth information than what I provide here.

URL: http://forum.sun.com/jive/thread.jspa?threadID=106458&messageID=366067
URL: http://blogs.sun.com/tdw/date/20050211#more_smf
URL: http://www.sunfreeware.com/sshsol10.html
URL: http://www.oreillynet.com/pub/a/sysadmin/2006/04/13/using-solaris-smf.html?page=4

About these ads
This entry was posted in *Nix. Bookmark the permalink.

2 Responses to Solaris: Adding Samba to the Service Management Facility

  1. Shaun says:

    Useful. Thanks!

  2. Anonymous says:

    It works, yes.
    i had to replace all quotes due to utf-8-replacements in the .xml-text,
    but once fixed, it worked

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s