Mojo::Server and abs_path and symlinks

49 views
Skip to first unread message

Alex Varyanick

unread,
Apr 5, 2015, 4:24:13 PM4/5/15
to mojol...@googlegroups.com
Hello all,

I wrote a small web application using the awesome Mojolicious framework :)
One of the purposes was to run different profiles of the application based on different config files.
I'm using Gentoo Linux so I decided to use the idea which Gentoo use for init scripts.

I wrote the following:
sub get_config_name {
    my $self = shift;                                                                             
    my $exe  = $0;
    my $fp   = File::Spec->rel2abs($exe);                                                         
    my $base = basename($exe);                                                                    
    my @dir  = File::Spec->splitdir($fp);                                                         

    return File::Spec->catfile($self->home, 'etc', "$base.conf");                                 
}

In this case I was making something like:
cd script
ln -s my_web_app new_instance

And created config file with name: new_instance.conf in "etc" folder.
After that I was running "./script/new_instance daemon" and everything worked as I expected.

Just recently my application grew up a bit and I decided to move to Hypnotoad.
First issue which I met was here (Mojo::Server::Hypnotoad):
 # Remember executable and application for later
  $ENV{HYPNOTOAD_EXE} ||= $0;
  $0 = $ENV{HYPNOTOAD_APP} ||= abs_path $app;
Due to the abs_path (which is making readlink inside) wrong application were running.
I've changed a runner a bit:
    $ENV{'HYPNOTOAD_APP'} = $app;
But got to another issue (Mojo::Server):
  # Clean environment (reset FindBin defensively)
  {
    local $0 = $path = abs_path $path;

So my question is: Is there an intention to use abs_path here instead of File::Spec->rel2abs?
May I expect that Mojo::Server to be patched? Or should I look to another ways of making different instances?
Or maybe you have any suggestions?

p.s. Currently looking into hard links instead of symlinks.

-- 
Thanks,
cono aka Alex

sri

unread,
Apr 5, 2015, 6:43:17 PM4/5/15
to mojol...@googlegroups.com
So my question is: Is there an intention to use abs_path here instead of File::Spec->rel2abs?
May I expect that Mojo::Server to be patched?

I don't believe there was a specific reason, but it has been (successfully) like this for many years now, and this is notoriously hard to test code. So there will certainly be resistance to just changing it, unless there's a very good explanation for why it has to be done, and why it won't cause any portability issues.

--
sebastian

Alex Varyanick

unread,
Apr 5, 2015, 7:17:51 PM4/5/15
to mojol...@googlegroups.com
Hello Sebastian,

I was afraid of the answer like this :)
Totally agree about potential risk of this change (for aaaall applications already written), pretty core change. As you know Mojolicious much better than I am, then I just answer to your question and defer this decision to you.

As for the Reasons:

My intention is to have ability to track the name of the script inside of Mojo app.
This ability will allow to us to make webapps similar to busybox binary (if you are aware what is it). The same idea used a lot in *nix world. As I already said Gentoo linux use this idea for the init script.

e.g. busyxbox
If you create symbolic link to the busybox with the name "ls" it will behave like "ls" command:
% mkdir 1
% cd 1
% ln -s $(which busybox) ls
% ./ls -l
total 4
lrwxrwxrwx    1 cono     cono            12 Apr  6 02:11 ls -> /bin/busybox

e.g. mongodb on gentoo:
% ls -l /etc/init.d/mongodb*
-rwxr-xr-x 1 root root 767 Mar 17 15:43 /etc/init.d/mongodb*
lrwxrwxrwx 1 root root   7 Oct  9  2013 /etc/init.d/mongodb-cfg -> mongodb*

% ls -l /etc/conf.d/mongodb*
-rw-r--r-- 1 root root 549 Mar 17 15:43 /etc/conf.d/mongodb
-rw-r--r-- 1 root root 434 Oct  9  2013 /etc/conf.d/mongodb-cfg

So I can run two instances of the mongodb at the same time with the different configs.

As for the Portability:
I quickly looked to the File::Spec::* modules and I see overrides in Mac, VMS, Unix, OS2 so I making decision its working fine. Dunno if the default behavior (defined in base class) works on other OS like Windows.
But as I can see Windows is not a big deal :)
Mojo::Server::Hypnotoad:
# No Windows support
  _exit('Hypnotoad is not available for Windows.') if $^O eq 'MSWin32';



--
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/OQEH0Aisouo/unsubscribe.
To unsubscribe from this group and all its topics, 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.



--
Varyanick I. Alex
skype: cono..
q...@cono.org.ua

sri

unread,
Apr 5, 2015, 7:21:48 PM4/5/15
to mojol...@googlegroups.com
As you know Mojolicious much better than I am, then I just answer to your question and defer this decision to you.

I'm afraid this will have to go through the proper channels, i can't make this decision alone.


--
sebastian 
Reply all
Reply to author
Forward
0 new messages