The Joyent Community

A place where the Joyent community can gather, help each other out, and stay informed.

You are not logged in.

#1 2006-11-22 16:19:21

mcornick
Member
Registered: 2005-09-06
Posts: 93
Expertise

SMF for Mongrel

OK, here's my first working cut at an SMF manifest for mongrel (mongrel_cluster, actually.)

Things you'll need to change:

  • everywhere I say mongrel/mcornick, change it to mongrel/yourappname (whatever you want)
  • change <method_context working_directory='/home/mcornick/rails/mcornick.org/current'> to point at your rails app's directory
  • change <method_credential user='mcornick' group='other' /> to the user and group you want

    Also, you'll need to have set up your mongrel_cluster.yml file as usual. Once that's done, you can refer to mongrel/yourappname in svcadm. enable, disable and restart all work as expected.

    I would suggest doing a separate manifest for each app, rather than trying to do multiple apps from one manifest. When I tried to do multiple apps, sometimes the mongrels wouldn't get restarted when they were killed.

    I've tested this and it works for me, but as usual, your mileage may vary. Suggestions and improvements are welcome.

    Next up: how to make Capistrano play nice with this setup. Shouldn't be too hard to make it do svcadm calls.

    Code:

    <?xml version='1.0'?>
    <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
    <service_bundle type='manifest' name='mongrel/mcornick'>

    <service name='network/mongrel/mcornick' type='service' version='0'> <create_default_instance enabled='true'/> <single_instance/> <dependency name='fs' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local'/> </dependency> <dependency name='net' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/network/loopback'/> <!-- need nfs/client because the mongrel stuff is on /home which is nfs mounted --> <service_fmri value='svc:/network/nfs/client'/> </dependency> <dependent name='mongrel_multi-user' restart_on='none' grouping='optional_all'> <service_fmri value='svc:/milestone/multi-user'/> </dependent> <exec_method name='start' type='method' exec='/opt/csw/bin/mongrel_rails cluster::start' timeout_seconds='60'> <method_context working_directory='/home/mcornick/rails/mcornick.org/current'> <method_credential user='mcornick' group='other' /> <method_environment> <envvar name="PATH" value="/usr/bin:/bin:/opt/csw/bin" /> </method_environment> </method_context> </exec_method> <exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'> <method_context/> </exec_method> </service>
    </service_bundle>

Offline

 

#2 2006-11-22 16:32:41

mcornick
Member
Registered: 2005-09-06
Posts: 93
Expertise

Re: SMF for Mongrel

Fixing Capistrano was a snap. I'm assuming you already have a working deploy.rb (if you don't, that's another thread.) You just need to redefine the spinner and restart tasks in deploy.rb:

Code:

task :spinner, :roles => :app do

send(run_method, "svcadm start mongrel/yourappname")
end

task :restart, :roles => :app do

send(run_method, "svcadm restart mongrel/yourappname")
end


You also need :use_sudo set to true (it's true by default, but I had it set to false as a relic from when this app was on shared hosting.) And if you were requiring mongrel_cluster/recipes, you don't need that any more.

Last edited by mcornick (2006-11-22 16:43:32)

Offline

 

#3 2006-11-22 19:20:31

benr
Systems Team
From: Silicon Valley
Registered: 2006-09-26
Posts: 119
Website  Expertise

Re: SMF for Mongrel

Very nice. Very very nice.

Offline

 

#4 2006-11-26 19:13:32

tzaharia
New member
Registered: 2006-06-14
Posts: 9
Expertise

Re: SMF for Mongrel

Hi everyone--

I'm pretty new to the TxD containers and Solaris and am currently setting up some instances of Typo with mongrel (not mongrel_cluster yet). We used this example as an SMF (thanks!) for a single mongrel instance of Typo (we'll call it Typo1) and it's running under the owner of Typo1's virtual host. It worked great.

Then we tried to use the same SMF template to get Typo2 running with a single instance of mongrel under its virtual host's owner and for some reason the SMF fails and mongrel isn't run. The service is put under "maintenance" and here's the message we get under svcs -vx:

Code:

svc:/network/mongrel/typo2:default (?)

State: maintenance since Sun Nov 26 10:57:51 2006
Reason: Method failed. See: http://sun.com/msg/SMF-8000-8Q See: /var/svc/log/network-mongrel-typo2:default.log
Impact: This service is not running.


And the *.log file seems to be not much help in this case, because here's all I get:

Code:

[ Nov 26 10:57:51 Enabled. ]
[ Nov 26 10:57:51 Rereading configuration. ]


Here's the SMF file (with names replaced with Typo2):

Code:

<?xml version='1.0'?>

<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>

<service_bundle type='manifest' name='mongrel/typo2.com'>

<service name='network/mongrel/typo2com' type='service' version='0'> <create_default_instance enabled='true'/> <dependency name='fs' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local'/> </dependency> <dependency name='net' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/network/loopback'/> <!-- need nfs/client because the mongrel stuff is on /home which is nfs mounted --> <service_fmri value='svc:/network/nfs/client'/> </dependency> <dependent name='mongrel_multi-user' restart_on='none' grouping='optional_all'> <service_fmri value='svc:/milestone/multi-user'/> </dependent> <exec_method name='start' type='method' exec='/opt/csw/bin/mongrel_rails start -d -p 8001 -e production -P log/mongrel-2.pid' timeout_seconds='60'> <method_context working_directory='/home/typo2/web/blog'> <method_credential user='typo2user' group='typo2group' /> <method_environment> <envvar name="PATH" value="/usr/bin:/bin:/opt/csw/bin" /> </method_environment> </method_context> </exec_method> <exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'> <method_context/> </exec_method> </service>

</service_bundle>


The only difference between Typo2 and Typo1 (the working one) is the replaced names and the name of the pid file. The error in svcs for this was "Method failed", but if I'm in the working directory as the typo2user I can run the exact same method and mongrel will run successfully from the command line. Another thing we can do is run the user/group in the SMF as root/root and it'll run fine, but we want to have these apps run respective of their owners. Does anyone have any ideas what the problem might be or anything I could do to look further into this?

-tieg

Offline

 

#5 2006-11-27 20:37:00

mcornick
Member
Registered: 2005-09-06
Posts: 93
Expertise

Re: SMF for Mongrel

I did find a problem in my manifest that would only affect people running more than one app (which, at the time I posted this, I wasn't. Paper bag for head, please.)

Code:

<dependent name='mongrel_multi-user' restart_on='none' grouping='optional_all'>
<service_fmri value='svc:/milestone/multi-user'/>
</dependent>


The name of the <dependent> has to be unique; therefore, you should change mongrel_multi-user to something unique per app. Once one app with the <dependent> of mongrel_multi-user is running, another one with the same name won't start.

Hope that helps...

Offline

 

#6 2006-11-28 07:02:46

tzaharia
New member
Registered: 2006-06-14
Posts: 9
Expertise

Re: SMF for Mongrel

Thanks for the suggestion Mcornick. It sounded right, but we tried it and unfortunately it didn't work. We've also tried using multi-user-server instead of multi-user as the milestone, but it didn't work either. We tried renaming the dependency every which way to Kansas, but none of the permutations worked.

Eventually I tried taking that whole dependency out of the SMF and it still didn't work, so we thought it might be some other problem. We then tried to replace the credentials in the SMF as the user/group from the Typo1 instance that was working, and it worked... insofar as the service was "online" instead of "maintenance". The mongrel spit out a blank page, but I'm sure that was because that user/group didn't have permissions in that Typo2 directory.

So our thoughts are that it might be because of the way that we setup the Typo2 virtual host with a custom username as the owner (the user and group in the credentials have the same name, btw), so I think our last resort might be to just throw out the virtual host and start that guy from scratch.

Last edited by tzaharia (2006-11-28 07:10:15)

Offline

 

#7 2006-11-29 22:52:25

rainbowsheep
Member
Registered: 2005-01-15
Posts: 584
Expertise

Re: SMF for Mongrel

When you restart mongrel, will it return before the mongrel processes are all running? Isn't that generally bad? Apache seems to barf with 503 errors for some time if it tried to access mongrel before they are all running.

Offline

 

#8 2006-12-13 19:26:36

technoweenie
Member
From: TX
Registered: 2005-01-29
Posts: 66
Website  Expertise

Re: SMF for Mongrel

Good stuff... Here's a quick capistrano mod to make it easier to call svcadm:

Code:

Capistrano::Actor.class_eval do

# svcadm :start, "nginx/foo" def svcadm(action, svc) sudo "svcadm #{action} #{svc}" end
end

Offline

 

#9 2006-12-13 23:16:46

mcornick
Member
Registered: 2005-09-06
Posts: 93
Expertise

Re: SMF for Mongrel

technoweenie wrote:

Good stuff... Here's a quick capistrano mod to make it easier to call svcadm:


That's pretty slick. I'll have to roll that into the "standardized" deploy.rb for containers that I'm working on in my suddenly-copious spare time...

Offline

 

#10 2007-03-13 21:54:41

JustinG
Member
Registered: 2007-02-28
Posts: 42
Website  Expertise

Re: SMF for Mongrel

One change, if you're using the textdrive myprivateip script for your mongrel cluster (I was pointed to it for the BIG-IP setup), you need to add /usr/sbin to <envar name=PATH value="/usr/bin:/bin:/opt/csw/bin:/usr/sbin"/> (ifconfig is used in the script and it's in /usr/sbin).

Offline

 

#11 2007-03-15 04:36:44

rainbowsheep
Member
Registered: 2005-01-15
Posts: 584
Expertise

Re: SMF for Mongrel

How would you modify that SMF to do a restart via 'mongrel_rails cluster::restart'?

Offline

 

#12 2007-03-19 02:30:51

JustinG
Member
Registered: 2007-02-28
Posts: 42
Website  Expertise

Re: SMF for Mongrel

rainbowsheep wrote:

How would you modify that SMF to do a restart via 'mongrel_rails cluster::restart'?


I haven't tried this yet, but couldn't you just add:

Code:

<exec_method name='restart' type='method' exec='/opt/csw/bin/mongrel_rails cluster::restart' timeout_seconds='60'>

<method_context working_directory='/home/your/app/current'> <method_credential user='your_user' group='your_group'/> <method_environment> <envvar name='PATH' value='/usr/bin:/bin:/opt/csw/bin:/usr/sbin'/> </method_environment> </method_context>
</exec_method>


Would there be any advantages or disadvantages to changing the 'stop' exec_method to use 'mongrel_rails cluster::stop' rather than ':kill'?

And, just to make sure I understand correctly, the default behavior for 'restart' (if you don't provide a method) is to run the 'stop' then the 'start' methods, right?

Last edited by JustinG (2007-03-19 02:31:34)

Offline

 

#13 2007-04-04 20:09:57

maui314159
New member
Registered: 2007-04-04
Posts: 3
Expertise

Re: SMF for Mongrel

Hi everyone,

I've implemented a modified version of this manifest. However, I'm running our rails instance from a non-root user. Does anyone know how to grant svnadm sart and restart privileges to a user in OpenSolaris?

Thanks,

Mark

Offline

 

#14 2007-04-04 20:16:36

jason
a chief (i started this place)
From: San Francisco
Registered: 2004-06-01
Posts: 8824
Website  Expertise

Re: SMF for Mongrel

here and here

Offline

 

#15 2007-04-04 20:31:22

maui314159
New member
Registered: 2007-04-04
Posts: 3
Expertise

Re: SMF for Mongrel

Ahh, I see. However, I think the following needs to be added to the manifest XML for these methods to work (before the </service> tag):

Code:

    
<!-- set this service up for management by non-root users -->

<property_group name='general' type='framework'> <propval name='action_authorization' type='astring' value='solaris.smf.manage.APPNAME'/> </property_group>


Replace APPNAME with your application's name.

Please bear in mind I am new to OpenSolaris so this example may not be the optimal way to name the privilege for this service.

Offline

 

#16 2007-06-04 08:16:46

madams
 
From: Edinburgh
Registered: 2005-05-11
Posts: 2075
Website  Expertise

Re: SMF for Mongrel

At the wiki I have generalized mcornick's manifest so that you can have multiple mongrel_cluster instances, one for each Rails app that you might be running.

I would appreciate input on the mongrel_rails cluster:stop vs. :kill as well as the cluster:restart method.

Thanks to mcornick for the original manifest!


Mark
Live in the city, work in the country. | OpenSolaris Immigrant

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson