I have a ror project which has been productized. There are several web sites in one ror project I need to set an "enviroment variable" to run different sites, can I do that using mongrel? I tried to use mongrel''s -S option and set the enviroment variable in that file but it seems mongrel runs that file after it calls enviroment.rb I also used apache''s mod_proxy+mod_header to set requestheader but it didn''t work either. Is there a way to set an enviroment variable before mongrel initializes? Thanks Ufuk.
On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote:> > I have a ror project which has been productized. There are several web > sites in one ror project >Question: A) You are serving multiple sites from one rails application? or B) You have multiple instances of your rails application, each one serving a specific web site.> I need to set an "enviroment variable" to run different sites, can I do > that using mongrel? I tried to use mongrel''s -S option and set the > enviroment variable in that file but it seems mongrel runs that file > after it calls enviroment.rbThe answers will be: A) Use something like subdomain accounts: http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys http://www.bigbold.com/snippets/posts/show/1322 B) process your ENV information inside environment, and set your environment variable prior calling mongrel_rails: $ MY_SITE=site1 mongrel_rails start ... or $ export MY_SITE=site1 $ mongrel_rails start ... -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi
What do you exactly mean by "setting environment variables" ? Are your sites running according to them ? On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote:> > > I have a ror project which has been productized. There are several web > sites in one ror project > > I need to set an "enviroment variable" to run different sites, can I do > that using mongrel? I tried to use mongrel''s -S option and set the > enviroment variable in that file but it seems mongrel runs that file > after it calls enviroment.rb > > I also used apache''s mod_proxy+mod_header to set requestheader but it > didn''t work either. > > Is there a way to set an enviroment variable before mongrel initializes? > > Thanks > > Ufuk. > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >-- ?nan? G?m?? Yaz?l?m Dan??man? / Software Consultant +90555 701 74 27 -- --- hidden job market lurking everywhere -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20070206/f5a1722c/attachment.html
If it''s "B", you may use a bash script to do them all at once in there. On 2/6/07, Luis Lavena <luislavena at gmail.com> wrote:> > On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: > > > > I have a ror project which has been productized. There are several web > > sites in one ror project > > > > Question: > > A) You are serving multiple sites from one rails application? > > or > > B) You have multiple instances of your rails application, each one > serving a specific web site. > > > I need to set an "enviroment variable" to run different sites, can I do > > that using mongrel? I tried to use mongrel''s -S option and set the > > enviroment variable in that file but it seems mongrel runs that file > > after it calls enviroment.rb > > The answers will be: > > A) Use something like subdomain accounts: > http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys > http://www.bigbold.com/snippets/posts/show/1322 > > > B) process your ENV information inside environment, and set your > environment variable prior calling mongrel_rails: > > $ MY_SITE=site1 mongrel_rails start ... > > or > > $ export MY_SITE=site1 > $ mongrel_rails start ... > > > -- > Luis Lavena > Multimedia systems > - > Leaders are made, they are not born. They are made by hard effort, > which is the price which all of us must pay to achieve any goal that > is worthwhile. > Vince Lombardi > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20070206/7e5ca282/attachment.html
Luis Lavena wrote:> On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: > >> I have a ror project which has been productized. There are several web >> sites in one ror project >> >> > > Question: > > A) You are serving multiple sites from one rails application? > > or > > B) You have multiple instances of your rails application, each one > serving a specific web site. > > >> I need to set an "enviroment variable" to run different sites, can I do >> that using mongrel? I tried to use mongrel''s -S option and set the >> enviroment variable in that file but it seems mongrel runs that file >> after it calls enviroment.rb >> > > The answers will be: > > A) Use something like subdomain accounts: > http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys > http://www.bigbold.com/snippets/posts/show/1322 > > > B) process your ENV information inside environment, and set your > environment variable prior calling mongrel_rails: > > $ MY_SITE=site1 mongrel_rails start ... > > or > > $ export MY_SITE=site1 > $ mongrel_rails start ... > > >I have one rails application which runs severals sites according to that enviroment variable. http://article.gmane.org/gmane.comp.lang.ruby.rails/14513 The problem is, I can do what you suggest but I want to use mongrel as an NT service (I can create multiple NT services for multiple sites) for that, I have to set this enviroment variable elsewhere. If there is an option to run system commands before mongrel service initializes, that would work for me. Thanks Ufuk
On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: <snip>> I have one rails application which runs severals sites according to that > enviroment variable. > > http://article.gmane.org/gmane.comp.lang.ruby.rails/14513 > > The problem is, I can do what you suggest but I want to use mongrel as > an NT service (I can create multiple NT services for multiple sites) > for that, I have to set this enviroment variable elsewhere. >OK, you forgot to include in your post THAT IMPORTANT part. NT services cannot set environment variables *per-service*, unless you ran your application for every instance in one specific user account (ex. site1 using user1, site2 => user2, etc). That will require set environment for each user account, also making your application code vulnerable to _all_ these accounts (NT security and permissions).> If there is an option to run system commands before mongrel service > initializes, that would work for me. >There isn''t. Mongrel execute the config script after loading rails environment. Could I question your decision base your application/system design in a mail that dates 1 year, 29 weeks, 5 days, 12 hours and 26 minutes old? I got better functionality and less code duplication implementing "instances" versions of my application: All your instances share the same codebase of your application, which is bundled inside a gem. Each instance could be run like a normal rails application, having its own database.yml, but without duplicated models and controllers between instances. That is Fossilize, the base on what Radiant based their gemification distribution. Maybe that approach will suite better your needs. -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi
Luis Lavena wrote:> On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: > <snip> > >> I have one rails application which runs severals sites according to that >> enviroment variable. >> >> http://article.gmane.org/gmane.comp.lang.ruby.rails/14513 >> >> The problem is, I can do what you suggest but I want to use mongrel as >> an NT service (I can create multiple NT services for multiple sites) >> for that, I have to set this enviroment variable elsewhere. >> >> > > OK, you forgot to include in your post THAT IMPORTANT part. > > NT services cannot set environment variables *per-service*, unless you > ran your application for every instance in one specific user account > > (ex. site1 using user1, site2 => user2, etc). > > That will require set environment for each user account, also making > your application code vulnerable to _all_ these accounts (NT security > and permissions). > > >> If there is an option to run system commands before mongrel service >> initializes, that would work for me. >> >> > > There isn''t. Mongrel execute the config script after loading rails environment. > > Could I question your decision base your application/system design in > a mail that dates 1 year, 29 weeks, 5 days, 12 hours and 26 minutes > old? > > I got better functionality and less code duplication implementing > "instances" versions of my application: > > All your instances share the same codebase of your application, which > is bundled inside a gem. > > Each instance could be run like a normal rails application, having its > own database.yml, but without duplicated models and controllers > between instances. > > That is Fossilize, the base on what Radiant based their gemification > distribution. > > Maybe that approach will suite better your needs. > >Thank you for your answer. The fact is, my application is a year old. So that solution was appropriatte back then. I''ll check your suggestion but I won''t be able to change a whole application to that method. Then, I''m stuck here. I doubt i will find a way out of this. Thanks again. Ufuk.
On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote:> Luis Lavena wrote: > > On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: > > <snip> > > > >> I have one rails application which runs severals sites according to that > >> enviroment variable. > >> > >> http://article.gmane.org/gmane.comp.lang.ruby.rails/14513 > >> > >> The problem is, I can do what you suggest but I want to use mongrel as > >> an NT service (I can create multiple NT services for multiple sites) > >> for that, I have to set this enviroment variable elsewhere. > >> > >> > > > > OK, you forgot to include in your post THAT IMPORTANT part. > > > > NT services cannot set environment variables *per-service*, unless you > > ran your application for every instance in one specific user account > > > > (ex. site1 using user1, site2 => user2, etc). > > > > That will require set environment for each user account, also making > > your application code vulnerable to _all_ these accounts (NT security > > and permissions). > > > > > >> If there is an option to run system commands before mongrel service > >> initializes, that would work for me. > >> > >> > > > > There isn''t. Mongrel execute the config script after loading rails environment. > > > > Could I question your decision base your application/system design in > > a mail that dates 1 year, 29 weeks, 5 days, 12 hours and 26 minutes > > old? > > > > I got better functionality and less code duplication implementing > > "instances" versions of my application: > > > > All your instances share the same codebase of your application, which > > is bundled inside a gem. > > > > Each instance could be run like a normal rails application, having its > > own database.yml, but without duplicated models and controllers > > between instances. > > > > That is Fossilize, the base on what Radiant based their gemification > > distribution. > > > > Maybe that approach will suite better your needs. > > > > > > Thank you for your answer. The fact is, my application is a year old. > So that solution was appropriatte back then. I''ll check your suggestion > but I won''t be able to change a whole application to that method. >Fossilize is 1 year old ;-) Original article in spanish: http://rubyargentina.soveran.com/gemrailsapp And the ANN in ruby-forum: http://www.ruby-forum.com/topic/67435#84031> Then, I''m stuck here. I doubt i will find a way out of this. >The only workaround I see for you is hack in the top of your environment file something that based on the port set to start the application, set the constant SITE (used in erb inside database.yml). Since you cannot start 2 instances in the same port, I guess this could work. (You will require look into ARGV and get -p or --port option from it.) The other, easier and less safer way will be use the multiple user accounts option. -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi
Luis Lavena wrote:> On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: > >> Luis Lavena wrote: >> >>> On 2/6/07, ufuk kocolu <ufuk at pilli.com> wrote: >>> <snip> >>> >>> >>>> I have one rails application which runs severals sites according to that >>>> enviroment variable. >>>> >>>> http://article.gmane.org/gmane.comp.lang.ruby.rails/14513 >>>> >>>> The problem is, I can do what you suggest but I want to use mongrel as >>>> an NT service (I can create multiple NT services for multiple sites) >>>> for that, I have to set this enviroment variable elsewhere. >>>> >>>> >>>> >>> OK, you forgot to include in your post THAT IMPORTANT part. >>> >>> NT services cannot set environment variables *per-service*, unless you >>> ran your application for every instance in one specific user account >>> >>> (ex. site1 using user1, site2 => user2, etc). >>> >>> That will require set environment for each user account, also making >>> your application code vulnerable to _all_ these accounts (NT security >>> and permissions). >>> >>> >>> >>>> If there is an option to run system commands before mongrel service >>>> initializes, that would work for me. >>>> >>>> >>>> >>> There isn''t. Mongrel execute the config script after loading rails environment. >>> >>> Could I question your decision base your application/system design in >>> a mail that dates 1 year, 29 weeks, 5 days, 12 hours and 26 minutes >>> old? >>> >>> I got better functionality and less code duplication implementing >>> "instances" versions of my application: >>> >>> All your instances share the same codebase of your application, which >>> is bundled inside a gem. >>> >>> Each instance could be run like a normal rails application, having its >>> own database.yml, but without duplicated models and controllers >>> between instances. >>> >>> That is Fossilize, the base on what Radiant based their gemification >>> distribution. >>> >>> Maybe that approach will suite better your needs. >>> >>> >>> >> Thank you for your answer. The fact is, my application is a year old. >> So that solution was appropriatte back then. I''ll check your suggestion >> but I won''t be able to change a whole application to that method. >> >> > > Fossilize is 1 year old ;-) > > Original article in spanish: > > http://rubyargentina.soveran.com/gemrailsapp > > And the ANN in ruby-forum: > > http://www.ruby-forum.com/topic/67435#84031 > > > >> Then, I''m stuck here. I doubt i will find a way out of this. >> >> > > The only workaround I see for you is hack in the top of your > environment file something that based on the port set to start the > application, set the constant SITE (used in erb inside database.yml). > > Since you cannot start 2 instances in the same port, I guess this could work. > > (You will require look into ARGV and get -p or --port option from it.) > > The other, easier and less safer way will be use the multiple user > accounts option. > >I can hack enviroment.rb but I don''t think I can retrieve startup parameters using ARGV. I checked and logged contents of ARGV and it''s empty. Can I retrieve it some other way (maybe using Rails::Configuration something like that) ?