change from morbo to hypnotoad for multiple domains

337 views
Skip to first unread message

mjb152

unread,
Apr 25, 2015, 5:03:21 AM4/25/15
to mojol...@googlegroups.com
currently I have 3 domains configured in nginx, which have proxy_pass pointing at ports 3000, 3001, 3002.  Then I have 3 apps running with morbo on each of those ports.
It all works well, but I'm now considering several more domains, and rebuilding a new server, so I think hypnotoad is the forward.
Should I create a hynotoad startup script for each domain as per http://mojolicio.us/perldoc/Mojo/Server/Hypnotoad , then start this up at boot time,   or should I only be running one instance of hypnotoad and running everything off that ? (somehow).

my last question, is how can I tell inside my apps which domain has been used ?  my $host = $self->req->url->to_abs->host;   or is there a variable set in nginx I can refer to ?

Александр Грошев

unread,
Apr 25, 2015, 5:54:44 AM4/25/15
to mojol...@googlegroups.com

You can try to use Mojolicious::Plugin::Mount for solve your problem. One instance with this plugin will load all your apps.

25.04.2015 12:03 пользователь "mjb152" <martin...@gmail.com> написал:
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

mjb152

unread,
Apr 25, 2015, 6:28:48 AM4/25/15
to mojol...@googlegroups.com
now that looks exactly what I'm after, wildcards for subdomains as well !!

thanks for the fast response.

Stefan Adams

unread,
Apr 25, 2015, 8:59:00 AM4/25/15
to mojolicious


On Apr 25, 2015 5:28 AM, "mjb152" <martin...@gmail.com> wrote:
>
> now that looks exactly what I'm after, wildcards for subdomains as well !!

Moreover, check out Toadfarm.

Jan Henning Thorsen

unread,
Apr 25, 2015, 10:22:47 AM4/25/15
to mojol...@googlegroups.com
Thanks Stefan!

mjb152: Good timing, since I just released a much simpler Toadfarm yesterday :)

I think it will fit your needs perfectly. Please let me know if there's anything you think is complicated or not very intuitive about it.

mjb152

unread,
Apr 25, 2015, 12:29:38 PM4/25/15
to mojol...@googlegroups.com
Jan - I'm playing with this now, but hitting an initial problem. 

I generate 2 apps, with: -

mojo generate app Test1
mojo generate app Test2

I then edit both the scripts  (test1/script/test1  and test2/script/test2), adding the following lines so they will start nicely.

use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }

so now I have a directory called /home/mojouser/apps  with 2 apps in subdirectories test1 and test2.
If I type morbo test1/script/test1  then it works, same for test2.  all good.

If I create a file called webfarm, as below and start it, I get an error.  any ideas why ?

webfarm
#!/home/mojouser/perl5/perlbrew/perls/perl-5.20.2/bin/perl
use Toadfarm -dsl;

logging {
  combined => 1,
  file     => "/var/log/toadfarm/app.log",
  level    => "info",
};

mount "/home/mojouser/apps/test1/script/test1"        => {"Host" => "46.101.2.191"};
mount "/home/mojouser/apps/test2/script/test2"        => {"Host" => "46.101.2.191"};

plugin "Toadfarm::Plugin::AccessLog";

start; # need to be at the last line


Error
mojouser@ultron:~/apps$ sudo ./webfarm start
Can't exec "hypnotoad": No such file or directory at /home/mojouser/perl5/perlbrew/perls/perl-5.20.2/lib/site_perl/5.20.2/Toadfarm/Command/start.pm line 44.
Hypnotoad server failed to start. (72057594037927935)






Jan Henning Thorsen

unread,
Apr 25, 2015, 12:41:28 PM4/25/15
to mojol...@googlegroups.com
I'm guessing "sudo" doesn't inherit the PATH from your user, so it doesn't find hypnotoad. I guess I could make Toadfarm a bit more clever when it comes to finding "hypnotoad", but I'm making dinner now so the "improvement" won't be available until tomorrow.

Anyhow, try running "sudo -E" instead or manipulate $ENV{PATH} inside webfarm, like this:

  $ENV{PATH} = "/home/mojouser/perl5/perlbrew/perls/perl-5.20.2/bin:$ENV{PATH}";

I would very much appreciate if you made an issue on github, but I will try to look into this either way.

Martin Bower

unread,
Apr 25, 2015, 12:45:14 PM4/25/15
to mojol...@googlegroups.com
I just renamed webfarm to webfarm.pl, and it started. 
Don't delay dinner !!, I'm running now and starting to play around with it.

thx

--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/WFh3C3elp9Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.

Jan Henning Thorsen

unread,
Apr 26, 2015, 4:18:04 AM4/26/15
to mojol...@googlegroups.com, martin...@gmail.com
I think 0.52 should fix the issue with not finding hypnotoad. It will soon be available on CPAN...


To unsubscribe from this group and all its topics, send an email to mojolicious+unsubscribe@googlegroups.com.

mjb152

unread,
Apr 26, 2015, 8:33:39 AM4/26/15
to mojol...@googlegroups.com, martin...@gmail.com
0.52 works well, thanks !

https://metacpan.org/pod/distribution/Toadfarm/lib/Toadfarm/Manual/Intro.pod   has a typo,  "in any trick you like form the Perl toolbox."

currently I'm just testing with 1 IP address, no domains have been transferred in yet, how can I test with 2 apps mounted and just adjusting the url ?

mount "/home/mojouser/apps/test1/script/test1"        => {"Host" => "46.101.2.191:8080", mount_point => "/"};
mount "/home/mojouser/apps/test2/script/test2"        => {"Host" => "46.101.2.191:8080", mount_point => "/"};

Jan Henning Thorsen

unread,
Apr 26, 2015, 8:37:55 AM4/26/15
to mojol...@googlegroups.com, martin...@gmail.com
The config below is not possible. You can't "merge" two apps at the same mount_point, and you don't need "Host" if you're not trying to filter on the value.

    mount "/home/mojouser/apps/test1/script/test1"        => {mount_point => "/"};
    mount "/home/mojouser/apps/test2/script/test2"        => {mount_point => "/test2"};

The config above will "mount" all the routes inside test1 directly on the root (/) while test2 is available under /test2.

Currently I have no idea how to implement merging of routes from two applications, and I would be very cautious about implementing it even if I knew how. The reason is that I think it will be very confusing.

mjb152

unread,
Apr 26, 2015, 11:22:32 AM4/26/15
to mojol...@googlegroups.com, martin...@gmail.com
that was a bad example from my side, I'll play with the config below and transfer in another domain to test it ..

mount "/home/mojouser/apps/test1/script/test1" => { Host => "domain1.com", };
mount "/home/mojouser/apps/test1/script/test2" => { Host => "domain2.com", };
 

Jan Henning Thorsen

unread,
Apr 26, 2015, 1:44:15 PM4/26/15
to mojol...@googlegroups.com
Please don't say code you haven't run doesn't work or doesn't work the way you expect.

It makes it impossible to help.

--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/WFh3C3elp9Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.

Martin Bower

unread,
Apr 26, 2015, 2:18:32 PM4/26/15
to mojol...@googlegroups.com
ok point taken, apologies, and I do appreciate the help.

taking a step back, maybe I've slightly misunderstood how to configure Toadfarm.

What's confusing me is the mount points, and how I can use those with my configuration.
I've written a few applications, they each have a startup script which uses morbo. some urls are duplicated across the applications e.g domain1.com/login   domain2.com/login
Going to domain1.com , domain2.com, domain3.com works, and there are no problems.  (except that I'm running several instances of morbo, where I would like to run one instance of hypnotoad)

Now I'm struggling to integrate that with Toadfarm, behind nginx as a reverse proxy.  https://metacpan.org/pod/distribution/Toadfarm/lib/Toadfarm/Manual/BehindReverseProxy.pod
If I use the example as stated then it works, but only for domain1.com/myapp .   
Can you advise a simple config for Toadfarm to reflect my usage above ?

mjb152

unread,
Apr 27, 2015, 5:26:30 AM4/27/15
to mojol...@googlegroups.com, martin...@gmail.com
this code works without nginx, and I have 2 questions.

I'd like to mount the first app to pickup both domain1.com , and www.domain1.com , currently it doesn't. Is there a way to achieve that ?
Secondly, no logging is being output to the normal log/development.log (in each app), nor does it go to /var/log/toadfarm , I could combine them both into 1 log, but I'd like to keep them separate if possible ?


mount "/home/mojouser/apps/test1/script/test1" => { Host => "domain1.com",   };
mount "/home/mojouser/apps/test2/script/test2" => { Host => "domain2.com", };

start ["http://*:80"];

Jan Henning Thorsen

unread,
Apr 27, 2015, 5:55:22 AM4/27/15
to mojol...@googlegroups.com, martin...@gmail.com
Pickup domain1 and domain2:

Oh! I've forgot to document that the matching headers can also take a regex. I will fix that later today.

So... you can either of these works:

    # use a regex
    mount "test1" => {Host => qr/domain\d+\.com/};
    # ...or mount the same app twice
    mount "test1" => {Host => "domain1.com"};
    mount "test1" => {Host => "domain2.com"};


I don't know why logging doesn't work. It should be something wrong in test1/test2, as long as you don't use logging(). (But I'm guessing you don't use logging(), since it's not part of your example code). The only way for Toadfarm to take over logging from test1/test2 is if you have specified logging {combined=>1}. See also https://metacpan.org/source/JHTHORSEN/Toadfarm-0.55/lib/Toadfarm.pm#L286 and https://metacpan.org/pod/Toadfarm::Manual::DSL#logging

mjb152

unread,
Apr 27, 2015, 6:29:06 AM4/27/15
to mojol...@googlegroups.com, martin...@gmail.com
regex...works perfectly, thx.

I'm not using logging(), I'll play around some more with different configs, but the config is as basic as the code I posted above.

Martin Bower

unread,
Apr 30, 2015, 10:45:39 AM4/30/15
to mojol...@googlegroups.com
Jan - I'm currently running with 2 apps mounted on different domains, all works well ... except I get absolutely no logging output.
I expected the log files in each app to be written to as normal , unless I override it.  
If I start each app with morbo, then logging works,   but if I use Toadfarm with sudo ./starter.pl start  , then I get no output.  Can you advise why ?
I've built this very basic example to demonstrate the issue I'm having.

On Mon, Apr 27, 2015 at 11:29 AM, mjb152 <martin...@gmail.com> wrote:
regex...works perfectly, thx.

I'm not using logging(), I'll play around some more with different configs, but the config is as basic as the code I posted above.

--

Jan Henning Thorsen

unread,
Apr 30, 2015, 5:18:03 PM4/30/15
to mojol...@googlegroups.com, martin...@gmail.com
I wonder what kind of output you expect...

So when I start the test apps with log level "debug", I see this in test1/log/development.log
[Thu Apr 30 23:09:30 2015] [debug] Routing to a callback
[Thu Apr 30 23:09:30 2015] [debug] Rendering template "index.html.ep"
[Thu Apr 30 23:09:30 2015] [debug] 200 OK (0.001527s, 654.879/s)

...and this is what starter.pl logs:
[Thu Apr 30 23:09:30 2015] [debug] GET "/"
[Thu Apr 30 23:09:30 2015] [debug] Routing to application "Test1"

So... maybe you don't see anything, because hypnotoad (which toadfarm use to run the application) sets the log level to "info"...? The reason why the log level is "info" and not "debug" under hypnotoad is because it will MOJO_MODE=production, unless you have set something custom, which again affect the log level:


Btw (not related): I see that you start the script with "sudo" and listen to port 80. I suggest you have a look at these resources regarding this:


On Thursday, April 30, 2015 at 4:45:39 PM UTC+2, mjb152 wrote:
Jan - I'm currently running with 2 apps mounted on different domains, all works well ... except I get absolutely no logging output.
I expected the log files in each app to be written to as normal , unless I override it.  
If I start each app with morbo, then logging works,   but if I use Toadfarm with sudo ./starter.pl start  , then I get no output.  Can you advise why ?
I've built this very basic example to demonstrate the issue I'm having.
On Mon, Apr 27, 2015 at 11:29 AM, mjb152 <martin...@gmail.com> wrote:
regex...works perfectly, thx.

I'm not using logging(), I'll play around some more with different configs, but the config is as basic as the code I posted above.

--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/WFh3C3elp9Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious+unsubscribe@googlegroups.com.

mjb152

unread,
May 1, 2015, 5:51:43 AM5/1/15
to mojol...@googlegroups.com, martin...@gmail.com
Thanks to Jan for pointing me in the right direction, I replied off list by accident, so apologies for that.
Jan suggested setting the logging level directly in the startup script, and I found that this coupled with combining the logfiles into one place suits my purpose.

Next step is to run this as the user rather than with root, and also go back to nginx and reverse proxy.

$ENV{MOJO_LOG_LEVEL} = "debug";
logging {
  combined => 1,
  path     => "/var/log/toadfarm/app.log",
  level    => "debug",
};

Jan Henning Thorsen

unread,
May 1, 2015, 7:36:12 AM5/1/15
to mojol...@googlegroups.com, martin...@gmail.com
Reply all
Reply to author
Forward
0 new messages