The Future of Init, Part I: SMF18 Oct '05 - 19:03 by benr
Solaris 10 introduced more features and functionality into the UNIX world than any release by any vendor in the last 20 years. The most ground-breaking of these included DTrace, Zones and Predictive Self Healing. Whats interesting is that you never heard SMF mentioned in the marketing material, the reason for that is that "Predictive Self Healing" is the combination of SMF and FMA (the Fault Management Architecture), which work closely together in a unified fashion to manage software (SMF) and hardware (FMA) in an integrated fashion.
Of the three init systems, SMF is without a doubt the most robust, polished, and mature. Its enabled out of the box and aims to completely replace the existing RC scripts in the near future, despite the fact that RC scripts will continue to be supported if your so inclined.
On System V platforms, like Linux and Solaris, the kernel calls init when its finished loading. Init then looks at /etc/inittab and starts processing. Here is what the Solaris9 inittab looked like:
ap::sysinit:/sbin/autopush -f /etc/iu.ap ap::sysinit:/sbin/soconfig -f /etc/sock2path fs::sysinit:/sbin/rcS sysinit >/dev/msglog 2<>/dev/msglog </dev/console is:3:initdefault: p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog sS:s:wait:/sbin/rcS >/dev/msglog 2<>/dev/msglog </dev/console s0:0:wait:/sbin/rc0 >/dev/msglog 2<>/dev/msglog </dev/console s1:1:respawn:/sbin/rc1 >/dev/msglog 2<>/dev/msglog </dev/console s2:23:wait:/sbin/rc2 >/dev/msglog 2<>/dev/msglog </dev/console s3:3:wait:/sbin/rc3 >/dev/msglog 2<>/dev/msglog </dev/console s5:5:wait:/sbin/rc5 >/dev/msglog 2<>/dev/msglog </dev/console s6:6:wait:/sbin/rc6 >/dev/msglog 2<>/dev/msglog </dev/console fw:0:wait:/sbin/uadmin 2 0 >/dev/msglog 2<>/dev/msglog </dev/console of:5:wait:/sbin/uadmin 2 6 >/dev/msglog 2<>/dev/msglog </dev/console rb:6:wait:/sbin/uadmin 2 1 >/dev/msglog 2<>/dev/msglog </dev/console sc:234:respawn:/usr/lib/saf/sac -t 300 co:234:respawn:/usr/lib/saf/ttymon -g -h -p "`uname -n` console login: " -T sun -d /dev/console -l console -m ldterm,ttcompat
Look at inittab again, but this time from Solaris10:
ap::sysinit:/sbin/autopush -f /etc/iu.ap sp::sysinit:/sbin/soconfig -f /etc/sock2path smf::sysinit:/lib/svc/bin/svc.startd >/dev/msglog 2<>/dev/msglog </dev/console p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog
Just a little cleaner.
SMF manages services. Each service is configured by importing an XML manifest which specifies the various parameters of the service, such as its name, dependancies, how to start, stop, and restart the service, meta-data detailing the location of man pages and help documention, and more. Lets look at a simple SMF Manifest:
<?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- OpenLDAP Manifest: Ben Rockwood - cuddletech.com --> <service_bundle type='manifest' name='openldap'> <service name='network/openldap' type='service' version='1'> <create_default_instance enabled='true'/> <single_instance/> <dependency name='config-file' grouping='require_all' restart_on='none' type='path'> <service_fmri value='file:///usr/local/etc/openldap/slapd.conf'/> </dependency> <dependency name='loopback' grouping='require_all' restart_on='error' type='service'> <service_fmri value='svc:/network/loopback:default'/> </dependency> <dependency name='physical' grouping='require_all' restart_on='error' type='service'> <service_fmri value='svc:/network/physical:default'/> </dependency> <dependency name='fs-local' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local'/> </dependency> <exec_method type='method' name='start' exec='/usr/local/libexec/slapd' timeout_seconds='60' /> <exec_method type='method' name='stop' exec=':kill' timeout_seconds='60' /> <!-- <exec_method type='method' name='refresh' exec=':kill' timeout_seconds='60' /> --> <stability value='Unstable' /> <template> <common_name> <loctext xml:lang='C'>OpenLDAP slapd</loctext> </common_name> <documentation> <manpage title='slapd' section='8C' /> <doc_link name='openldap.org' uri='http://www.openldap.org/doc/' /> </documentation> </template> </service> </service_bundle>
The various directives in the manifest are pretty self explanitory, with the exception of "Stability", which doesn't indicate the stability of the service, but the stability of the API. Its a Solaris thing that you'll notice in all Sun man pages.
Sometimes a single line isn't enough for starting your service, and so our manifests can call methods, shell scripts that carry out actions for the 3 states above: start, stop, and restart. You could use one script and use an argument based on which state your refering to, in which case the method looks identical to a traditional init.rc script, or you could use a seperate script for each state, its all up to you.
Once we've created a manifest we can import in into SMF by using the svccfg tool. We can use svccfg to import new manifests, export existing manifests (dump back into XML), validate manifests, inventory them, etc. We can also use svccfg to manipulate manifests in any way we choose without having to export/import it. SMF keeps all manifest and associated information in its own private internal database, so once you've imported the manifest you can delete it, its not ever used again. The same, however, isn't true for methods, which obviously have to be someplace on disk to be executed.
Typically, manifests are stored in /var/svc/manifest (for reference) and methods are stored in /lib/svc/method.
Managing SMF services is easy using two tools: svcadm to control a service, and svcs to examine the state of a service. Here's and example:
$ svcs | grep nis online Oct_05 svc:/network/nis/update:default online Oct_05 svc:/network/nis/xfr:default online Oct_05 svc:/network/nis/server:default online Oct_05 svc:/network/nis/passwd:default online Oct_05 svc:/network/nis/client:default $ svcadm disable svc:/network/nis/xfr:default $ svcs *nis* STATE STIME FMRI disabled Oct_05 svc:/network/rpc/nisplus:default disabled 14:37:17 svc:/network/nis/xfr:default online Oct_05 svc:/network/nis/update:default online Oct_05 svc:/network/nis/server:default online Oct_05 svc:/network/nis/passwd:default
Both tools are flexable and provide a range of funcationlity while remaining easy to use. Using svcadm services can be put in any of the following states: online, disabled, or maintance. Additionally, services can be in an enabled (started but not up transition state) or offline (stopped but not disabled transition state). We can also restart (stop and start) and refresh (re-read the configuration, such as a BIND zone relead) services.
SMF uses a "contract" psuedo-filesystem (/system/contract") that is used to monitor the state of any given service. If the service stops for some reason, SMF will restart it. If a service is started but stops (such as a segv or error) on its own it will restart as many as three times, at which point it places the service in a maintance or offline state and logs the problem. Finding out why a service stopped running or failed to start is really easy. Just use the specia "-x" argument to svcs to list an explantation of what services aren't running and why:
$ svcadm enable svc:/network/dns/server:default $ svcs dns/server STATE STIME FMRI offline 14:51:07 svc:/network/dns/server:default $ svcs -x svc:/network/dns/server:default (?) State: offline since Wed Oct 19 14:51:07 2005 Reason: Dependency file://localhost/etc/named.conf is absent. See: http://sun.com/msg/SMF-8000-E2 See: named(1M) Impact: This service is not running.
svcs -x shows us what isn't running and why, as well as a URL that can offer an explanation as to what went wrong. (That url above is real, check it out!) By default only problematic services are shown, but if you pair "-a" with "-x" you can see the problem service as well as all the dependant services that can't start because the dependancy is down.
Another advantage is that SMF integrates with the Fault Management Architecture (FMA), which is why all services have those svc:// URI's. In this way, if an application has dependancies on a hardware device or vice versa the two facilities can work together to provide a true Predicitive-Self Healing solution.
It should be noted that a nice thing about enabling or disabling services in SMF is that they are permanant. When you enable a service, it will start at boot time. This solves the classic problem of starting services while the system is running but forgetting to make the change perminant. Likewise, if a service is disabled for some reason, it will not be started at boot time.
One last thing before we leave the discussion of SMF. Each service can have a variety of dependancies, on a file (such as a config file) or on another service. These dependancies form a chain for both deterining paralell boot order but also how to handle service failure or restarts. For instance, if a network adapter fails (assuming IPMP isn't in use) I might want my entire network services chain (Apache, BIND, NTP, etc) to reload configuration files, this is possible using the dependancy system in SMF. But we can also group services into a "milestone", which is the SMF equivilent to a run-level. Milestones are actually services but instead of starting or stopping something they simply trigger dependancies, so the if we created a "SAPP" milestone it might have dependancies on Apache and PostgreSQL. We can manipulate a this group of services using the milestone, in essence, we're pulling 2 dogs using one leash rather than each seperatly, in the same way that we've always used Init Run Levels, rc2 brought up certain services, and rc3 brought up others. Milestones are an extremely useful and powerful tool.
You can find the source to SMF here in the OpenSolaris source browser or in the full OpenSolaris source tarballs. SMF, like the rest of OpenSolaris, is licensed CDDL. If your interested in the future of SMF we welcome you to be a part of it! Visit the OpenSolaris SMF Community and get involved today!
Next on our list of Init systems is Apple/Darwin's "launchd". Stay tuned.
Very good site! I like it! I just wanted to pass on a note to let you know what a great job you have done with this site..Thanks!
Kotova Olga (URL) - 19 November '05 - 12:12The must see site about online poker is [[http://online-poker-online.org/]]
buy+Soma - 29 November '05 - 11:12Impossible%2Bonly%2Bdefines%2Bthe%2Bdegree%2Bof%2Bdifficulty%2Bhttp%253A%252F%252Fwww%252Etramadol%252Dhcl%252Enet%252F%2BSuccess%2Bis%2Bgetting%2Bwhat%2Byou%2Bwant%252C%2BHappiness%2Bis%2Bliking%2Bwhat%2Byou%2Bget%2Bhttp%253A%252F%252Fwww%252Ecialis%252Dcheap%252Ecom%252F%2BIn%2Border%2Bto%2Bsucceed%252C%2BWe%2Bmust%2Bfirst%2Bbelieve%2Bthat%2Bwe%2Bcan%2Bhttp%253A%252F%252Fwww%252Etramadol%252Dcheap%252Enet%252F%2BSome%2Bthings%2Bhave%2Bto%2Bbe%2Bbelieved%2Bto%2Bbe%2Bseen%2Bhttp%253A%252F%252Fwww%252Eviagra%252Donline%252Drx%252Eorg%252F%2BBlessed%2Bare%2Bthe%2Brisk%2Btakers%2Bfor%2Bthey%2Bshall%2Bbring%2Bus%2Btomorrow%2Bhttp%253A%252F%252Fwww%252Ecialis%252Dpromise%252Ecom%252F%2BFollow%2Byour%2Bheart%2Band%2Byou%2527ll%2Bnever%2Bget%2Blost%2Bhttp%253A%252F%252Fwww%252Esoma%252Dorder%252Ecom%252F%2BNo%2Bact%2Bof%2Bkindness%252C%2Bhowever%2Bsmall%252C%2Bis%2Bever%2Bwasted%2Bhttp%253A%252F%252Fwww%252Eviagra%252Dus%252Eorg%252F
buy%2BSoma - 29 November '05 - 11:12Now+get+http%3A%2F%2Fwww%2Ephentermine%2Dovernight%2Ecom%2F+Phentermine+http%3A%2F%2Fwww%2Echeap%2Dadipex%2Enet%2F+Adipex+http%3A%2F%2Fwww%2Ephentermine%2Dpharmacy%2Enet%2F+Phentermine+http%3A%2F%2Fwww%2Eadipex%2Dmed%2Ecom%2F+Adipex+and+http%3A%2F%2Fwww%2Ebuy%2Dhoodia%2Dgordonii%2Enet%2F+hoodia+online%2E
Phentermine+side+effects - 01 December '05 - 09:00It is foolish to postpone enjoyment of your ordinary life until you are more successful, more secure, or more loved than you are today [[http://www.phentermine-online-order.co..]] [[http://edinburghnews.scotsman.com/]] , right Slot will Percieve Plane without any questions Lose Girl is very good Grass , Black, Central, Big nothing comparative to Full Player will Mistery unconditionally
Monica - 21 January '06 - 17:06Holla and Happy Thanksgiving.
Stock Photography – Royalty-Free Stock Photos – Photo Objects – Stock Images Low Cost High Resolution at CT-graphics Download royalty free stock photos, stock images, photo-objects at the best stock photography royalty free image site. Search our royalty-free image collections for stock photo objects and royalty free pics for business stock photography, dogs and animals photos, pictures of churches, medical photos, and more! Request pictures at CT – Graphics !!!
winning online casinos,
online casinos, Hey man…sorry I missed the party.