Archive

Archive for the ‘Solaris 10’ Category

Create SSH Key for Joyent Server

February 13, 2012 Leave a comment

An SSH key consists of a pair of files. One is the private key, which you should never give to anyone. The other is the public key. You will need a public key to log into most machines you provision.

To generate an SSH key in Ubuntu 11, follow these steps.

  1. Enter the following command in the Terminal window.
    gregg@workstation1:~$ ssh-keygen -t rsa

    This starts the key generation process. The -t option specifies what type of SSH key to generate. When you execute this command, the ssh-keygen tool prompts you to indicate where to store the key.

    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/gregg/.ssh/id_rsa):
  2. Press the ENTER key to accept the default.
  3. The ssh-keygen utility prompts you for a passphrase. Enter a phrase you can remember. You can use a key without a passphrase, but this is not recommended.
    Enter passphrase (empty for no passphrase):
  4. You need to enter the passphrase a second time to continue.
    Enter same passphrase again:

    After you confirm the passphrase, the command generates the key pair

    Your identification has been saved in /home/gregg/.ssh/id_rsa.
    Your public key has been saved in /home/gregg/.ssh/id_rsa.pub.
    The key fingerprint is:
    ae:89:72:0b:85:da:5a:f4:7c:1f:c2:43:fd:c6:44:38 gregg@workstation1
    The key's randomart image is:
    +--[ RSA 2048]----+
    |                 |
    |         .       |
    |        E .      |
    |   .   . o       |
    |  o . . S .      |
    | + + o . +       |
    |. + o = o +      |
    | o...o * o       |
    |.  oo.o .        |
    +-----------------+

Your private key is saved to a file named id_rsa in the .ssh directory.

Never share your private key with anyone!

Your public key is saved to a file named id_rsa.pub. This file contains the information you will add to your JoyentCloud account.

cat ~/.ssh/id_rsa.pub

Categories: Solaris 10

Boot Tomcat at Server Startup/Reboot

February 12, 2012 Leave a comment

I am running Sun Solaris 11 on a Joyent Machine. This may not apply to typical Tomcat setups.

My resources that helped achieve this. Both Peter Black and Peter Tribble are much more articulate in technical writing. So have a look:
1. Joyent Wiki, i forget which article.
2. Peter black: Solaris 10 manifest for starting up tomcat.
3. Peter Tribble: Peter’s Solaris Zone

Create a Manifest File which will be registered with Solaris. Mine looks like this:

<?xml version="1.0" ?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='Tomcat6'>
  <service name='application/servers/tomcat' type='service' version='1'>
    <create_default_instance enabled='false' />
       <single_instance/>
       <exec_method type='method' name='start' exec='/opt/local/java/tomcat6/bin/startup.sh' timeout_seconds='30' >
         <method_context>
           <method_credential user='tomcat' group='tomcat' privileges='basic,net_privaddr' />
           <method_environment>
             <envvar name="CATALINA_BASE" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_HOME" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_TMPDIR" value="/opt/local/java/tomcat6/temp" />
             <envvar name="JAVA_HOME" value="/opt/local/java/sun6" />
           </method_environment>
         </method_context>
       </exec_method>
       <exec_method type='method' name='stop' exec='/opt/local/java/tomcat6/bin/shutdown.sh' timeout_seconds='60' >
         <method_context>
           <method_credential user='tomcat' group='tomcat' />
           <method_environment>
             <envvar name="CATALINA_BASE" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_HOME" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_TMPDIR" value="/opt/local/java/tomcat6/temp" />
             <envvar name="JAVA_HOME" value="/opt/local/java/sun6" />
           </method_environment>
         </method_context>
       </exec_method>
       <stability value='Unstable' />
       <template>
         <common_name>
           <loctext xml:lang='C'> Tomcat </loctext>
         </common_name>
       </template>
   </service>
</service_bundle>

How to customize this manifest file:

Give the service manifest a meaningful name. I chose tomcat6. This can be found in the xml node:

<service_bundle type=’manifest’ name=’Tomcat6‘>

Set the path to file (i think). Here I’ve created the servers directory. And file name is tomcat.xml Note that the .xml extension isnt included in name attribute.
<service name=’application/servers/tomcat‘ type=’service’ version=’1′>

This file is stored in the vendor recommended location on the filesystem:

/var/svc/manifest/application/

And the complete path including the directory and file that I manually created:

/var/svc/manifest/application/servers/tomcat.xml

Next fill in all information regarding your configuration. Such as startup.sh, shutdown.sh scripts and environment variables. Read the Peter Black article for specifics.

Register the Manifest File.

Once the manifest file has been created and saved in the /var/svc/manifest/application/… directory; register it with the Service Management Facility (smf).

To begin, import the file. At terminal command prompt:

svccfg -v import /var/svc/manifest/application/servers/tomcat.xml

A successful import may look like the following:

svccfg: Taking “initial” snapshot for svc:/application/servers/tomcat:default svccfg: Taking “last-import” snapshot for svc:/application/servers/tomcat:default svccfg: Refreshed svc:/application/servers/tomcat:default svccfg: Successful import

Debugging a Manifest File

Originally I had some errors. This required some exploration to understand. Here is what i concluded and this is where Peter Tribble’s Solaris Zone is extremely useful. Specifically he helped me understand how to “correct a fault in a manifest file”.

I attempted to start tomcat svcadm enable tomcat in which nothing happened. So to begin isolating the error I looked at the log file for my service. Take a look:

First attempt to enable my Tomcat service. At this point the manifest file above has been imported. Using the svcadm tool, lets enable tomcat service, check the status, notice its in maintenance mode which means its not running. Then check the logs to determine why its not running and fix accordingly.

svcadm enable tomcat

svcs -lp tomcat

svcs -lp tomcat
fmri svc:/application/servers/tomcat:default
name Apache Tomcat 6.0.35
enabled true
state maintenance
next_state none
state_time February 5, 2012 08:59:59 PM UTC
logfile /var/svc/log/application-servers-tomcat:default.log
restarter svc:/system/svc/restarter:default contract_id

As you can see in the code above, the Tomcat service is in maintenance mode. So Tomcat isnt running. Time to view the log file to see what the issue is. In my case, the environment variables weren’t defined.

cat /var/svc/log/application-servers-tomcat:default.log

I see the log entry below:

Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
[ Feb  5 20:59:59 Method “start” exited with status 1. ]

My fix was to add the environment variables in the manifest file shown above. So hopefully you will not see this error. I was able to add the environment variables to the manifest file and startup the service without any other problems.

At this point, I believe that adding environment variables to any of the traditional files (.bashrc,  .bash_profile, /etc/.profile, etc) is not necessary.

Some commands that might be useful:

Start/Stop Tomcat service.
svcadm enable tomcat
svcadm disable tomcat

View Status of a specific service.
svcs -lp tomcat

View Status of all services.
svcs -a

When the tomcat service is enabled, Apache Tomcat Server will start up when the Server is rebooted.

To correct errors in a manifest file:

1. Edit the manifest file.
sudo vi /var/svc/manifest/application/servers/tomcat.xml

2. Disable the entry:
svcadm -v disable svc:/application/web/tomcat:default

3. Delete the entry:
svccfg -v delete svc:/application/web/tomcat:default

4. Import updated manifest file:
svccfg -v import /var/svc/manifest/application/servers/tomcat.xml

5. Start up entry.
svcadm enable tomcat