Self-Healing SAMP with OpenSolaris 2008.05 and it's SMF

Hi Everybody!

     Today I'm doing a review about the new OpenSolaris 2008.05, the one released from project Indiana on 05/05/2008.
     OpenSolaris 2008.05 has all the benefits of Solaris' Kernel and uses ZFS (the greatest file system of the planet) as its native file system. The first impression I had when I installed was its fastness. It's certainly much faster than Ubuntu 8.04, Fedora 9 and, of course, Windows. I'm using it now to do all my work and I'm really satisfied. See my desktop screen:

     OpenSolaris cames with Java installed, Firefox and ThunderBird, Pidgin, GIMP, eVince and many others Gnu Tools.The Flash plug-in is very easy to install, Firefox is prepared to do everything for you... so, no need to download it apart and then configure Firefox yourself to make it work. It just install and work for you.

     One of the greatest features of Solaris, for me, is it's Service Management Facility, aka SMF, that gives Solaris the Self Healing ability. Different from Linux, the services are not started and managed through the RC scripts manually, they are controlled by SMF, that manages dependencies, status, errors and organizes everything. If something goes wrong, SMF takes an attitude to repair the situation automatically. If it has no autonomy to full repair a problem, it gives great feedback, instructions about possibilities to fix the problem and very useful logs. OpenSolaris is smart!

     To challenge the OpenSolaris way of use, I decided to put a full SAMP platform to work on it, integrating that with Solaris SMF Self Healing System.

And the steps I followed to do it will fit on a single blog Post! ;)

     For those that are not familiar with some terminologies, SAMP means: Solaris+Apache+MySql+PHP ... a fast and furious development platform.

     The First Step was to install Apache, MySql and PHP. OpenSolaris cames with a Package Manager that downloads, configures and installs the packages for us, with no troubles and headaches about dependencies. Next is a screen shot:

     First, I searched for apache and asked the Package Manager to Install Apache 2.2 (SUNWapch22), FastCGI plugin (SUNWapch22m-fcgid), and PHP5 module for Apache (SUNWapch22m-php5). Second, I searched for mysql and asked the manager to install MySql 5 (SUNWmysql5), PHP5 Extension module(Core) to connect to MySQL database (SUNWphp524-mysql) and SUNWmysql-base. The last step was the search for php. I asked Package manager to install PHP Server 5.2.4 (SUNWphp524), Core components of PHP server (SUNWphp524core) and SUNWphp524usr.
     All the Packages are available on repository.

     No headache to install SAMP. The three applications were installed on my system on /usr , /etc and /var directories separating (not that exactly, but...) executables/libs, configuration files and functional data, respectively.

     Then, I stepped to the interesting part: to configure Apache, MySQL and PHP to work together and to be part of SMF! I've started with MySQL.

     Created a my.cnf file at /usr/mysql/5.0 copying the my-small.cnf from /usr/mysql/5.0/share/mysql and renaming it:

# cd /usr/mysql/5.0
#cp ./share/mysql/my-small.cnf .
#mv my-small.cnf my.cnf

     Then, I've run mysql_install_db, running the script inside /usr/mysql/5.0/bin:

#cd /usr/mysql/5.0/bin

After that, just put mysql user as owner of /var/mysql folders:

#cd /var
#chown -R mysql:mysql ./mysql

     So, it was already possible to start MySQL through '/usr/mysql/5.0/bin/mysql_safe &' command. To stop MySQL, we may use 'pkill mysql'. I did it to test if everything was going OK. Then I configured Apache to work with PHP.

     First, I've edited the httpd.conf file on /etc/apache2/2.2 . I've searched on httpd.conf file for ServerName and ServerAdmin variables. I've left the ServerName variable set to, but it can be changed to an specific server name. Then I changed the ServerAdmin value to a valid e-mail.

     Next, I searched for <IfModule mime_module> tag on httpd.conf. And, Near the following lines:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

I've added a third line with: AddType application/x-httpd-php .php

It stayed like that:

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php

     That's all for httpd.conf. Now, there is only php.ini left. I've just copied /etc/php5/5.2.4/php.ini file to /etc/apache2/2.2/:

#cd /etc/apache2/2.2
#cp /etc/php5/5.2.4/php.ini .

And then opened it to edit. I've only needed to find the block:
; Dynamic Extensions ;

And add the following line after the comments:

     So far so good. Everything is configured and working. You can try starting apache through '/usr/apache2/2.2/bin/apacheclt start' and use a little PHP script to test (Start MySQL too). Create a file with these lines:

     echo "Hello World!
     $conexao = mysql_connect('localhost', 'root', '');
     echo $conexao;

and save it inside /var/apache2/2.2/htdocs with a name like myTest.php . Then, open your browser and type "http://localhost/myTest.php" . Apache and MySQL should be running (you may check it using the 'ps' command)! The Browser should display a message like:

     You may see I haven't configured a password for MySQL root user! That's really bad for a real system! You may change root's password on MySQL and create other users to use the databases as you need. But my intention here is just testing.

Now Let's put Apache and MySQL inside SMF!

     To set up a service inside SMF you need a script that knows how to start and stop your service (like the old rc scripts of linux) and a XML manifest file that gives more information about the service to SMF like dependencies and other characteristics. There is not so much headache to create these files. The Method script, as I mentioned, is not very different from an RC script, and for the XML manifest, that could sounds more complicated, there is a tool on that helps you to generate your manifest file automatically, have a look at EASY SMF -

     Anyway, Apache and MySQL are famous services and, because I was in a hurry, I've just searched the Internet to see if there was something already done. And there it was. I've edited the scripts and manifests files from these links to put my services under SMF management.

Thanks to Chris Miles and William Pool for the files!

     I've had to edit the original method scripts and manifest files because many installation details were different from what I found on the originals, like the paths to many important files. So I've adapted them to work directly for OpenSolaris Package Manager Installations.

     So, you can have the method scripts here. Just copy them into /lib/svc/method :

Apache Method: apache2
MySQL Method: svc-mysql

>> After saving them on method directory, chmod them into 555 permission (read and execute) (( '# chmod 555 apache2 svc-mysql' ))

     And here are the Manifest Files. They will be copied into different directories:

Apache2 Manifest: apache2.xml

>> Save it inside '/var/svc/manifest/site' directory and chmod it to 444 permission (read only) (( '# cdmod 444 apache2.xml' ))

MySQL Manifest: mysql.xml

>> Save it inside '/var/svc/manifest/network' directory and chmod it to 444 permission (read only) (( '# cdmod 444 apache2.xml' ))

Good. Now the last step. Import them into SMF through the commands:

# svccfg -v import /var/svc/manifest/site/apache2.xml
# svccfg -v import /var/svc/manifest/network/mysql.xml

If you have Apache2 and MySQL running on the system, turn them off (you may use 'pkill mysql' and 'apacheclt stop'). To start your services, now you may use:

# svcadm -v enable apache2
# svcadm -v enable mysql


# svcadm -v disable apache2
# svcadm -v disable mysql

To turn them off.

     It's possible to see their status through the command:

# svcs -a | grep apache2
# svcs -a | grep mysql

(svcs command list the enabled services; -a option show all the services, enabled and disabled ones)
You may see if there is any problem with your services running the following command:

# svcs -x

If something weird makes your Apache or MySQL go down killing their processes (try it yourself), SMF will take care of it and put the services up and running again!

Nice, isn't it?? And quite easy too!
That's it. Through few steps, now I have my SAMP platform configured and under OpenSolaris Self-Healing system.



Thanks for checking out the Web Stack components in OpenSolaris. Refer to our project page here:

The best news is that using it is much, much, much easier that what you did above!

\* You do NOT have to do anything to configure PHP to work with Apache. As soon as you install SUNWapch22m-php5 it "just works". Check out the conf.d/php5.conf file installed by the package. Just drop your \*.php files under htdoc, no need to edit any config files.

\* You also do NOT have to create any smf manifests, all the Web Stack packages are fully integrated with smf out of the box! (For the moment, you do need to manually import the manifest only because of a bug in pkg, but that should be fixed soon.)

All you needed to do is install the packages and it's ready to go..

Check out the various blogs from the Web Stack community for more pointers:

Posted by Jyri Virkki on Junho 06, 2008 at 02:38 PM BRT #

Hi Jyri. Good News! But...
Anyway, after installing Apache, MySQL and PHPServer, I dropped a \*.php file under htdocs and It did not worked at all! After the addition of 'AddType application/x-httpd-php .php' line on httpd.conf, it started working.
I didn't find the default methods and manifests you mentioned on the folders. I think I've seen the mysql files... but there was nothing for apache there... maybe another name... Anyway, both were not integrated with SMF, I tried 'svcs -a | grep apache' and 'svcs -a | grep mysql' and nothing were listed, thats why I decided to do it myself.
Thanks for the comment! The possibility of a fast and easy install of SAMP as you mentioned is really amazing.

Posted by Jonas Dias on Junho 07, 2008 at 06:23 AM BRT #

> I dropped a \*.php file under htdocs
> and It did not worked at all!

Hi, can you please send an email to describing the steps you did in detail.. it should absolutely work after installing the packages without having to edit any config files by hand. I've never experienced it not working, but if there is some scenario where it does not I want to address it.

The smf manifests are confusing because pkg doesn't load them automatically. Hopefully pkg will be fixed soon so this problem disappears. But meanwhile all you need to do is to import the included manifests manually (I have a couple screencasts showing this but they're too big for my blog, I plan on posting the transcripts into my blog real soon now, so check it out there).

Posted by Jyri on Junho 07, 2008 at 08:24 AM BRT #

Instead of getting individual components, the way I do is
pfexec pkg install amp

check out this link

Posted by Sriram Natarajan on Junho 09, 2008 at 01:01 PM BRT #

Gr888 Really all steps went smoothly without any prob

thx alot Jonas

Posted by muhammad on Junho 24, 2008 at 12:04 PM BRT #

Desculpe mais fiz o teste do exemplo soa que você passou sobre a video aula e esta dando erro você poderia me ajudar xml/entities/NetBeans/DTD_DefaultAttributes_1_0
at org.openide.filesystems.XMLFileSystem$FileObjRef.createAbsoluteUrl(
at org.openide.filesystems.XMLFileSystem$FileObjRef.getInputStream(
at org.openide.filesystems.XMLFileSystem.getInputStream(
at org.openide.filesystems.XMLFileSystem.access$500(
at org.openide.filesystems.XMLFileSystem$Impl.inputStream(
at org.openide.filesystems.StreamPool.createInputStream(
at org.openide.filesystems.AbstractFileObject.getInputStream(
at org.openide.filesystems.MultiFileObject.getInputStream(
at org.netbeans.modules.sun.manager.jbi.util.ServerInstanceReader$1.resolveEntity(
at javax.xml.parsers.DocumentBuilder.parse(
at org.netbeans.modules.sun.manager.jbi.util.ServerInstanceReader.getServerInstances(
at org.netbeans.modules.compapp.catd.util.Util.getServerInstance(
at org.netbeans.modules.compapp.catd.util.Util.sendMessage(
at org.netbeans.modules.compapp.catd.ConfiguredTest$
Caused by: unknown protocol: nbres
at org.openide.filesystems.XMLFileSystem$FileObjRef.createAbsoluteUrl(
... 26 more
java.lang.RuntimeException: Unknown server instance.
at org.netbeans.modules.compapp.catd.util.Util.sendMessage(
at org.netbeans.modules.compapp.catd.ConfiguredTest$
Test HelloTest\\ Failed. (Destination: http://localhost:${HttpDefaultPort}/casaService1/casaPort1)
<Concurrent test thread 0> is Errored. Success rate 0/1

Posted by Allan on Setembro 01, 2009 at 08:58 AM BRT #

Posted by Jonas Dias on Setembro 06, 2010 at 06:52 PM BRT #

Post a Comment:
  • HTML Syntax: NOT allowed

Well... Let's keep this blog updated for now on!!


« Julho 2016