Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"
The current working directory in Perl should be retrieved using Cwd, not $ENV{PWD}. Regardless, putting paths in your program based on CWD is a bug, since the program could be run with any CWD and that should not change its behavior. I wrote a similar module to the FindBin interface using the same method as lib::relative for creating arbitrary file paths relative to the current file: https://metacpan.org/pod/Path::This With an up to date Mojolicious, curfile can of course solve both these problems. -Dan On Fri, Apr 30, 2021 at 10:50 AM llaro...@gmail.com wrote: > Thanks to both of you, I managed to get past loading modules while > starting the service from systemd. Now there is another bug regarding > relative paths and I wonder how to solve it, it seems lib::relative might > not do the trick > > my $homedir = $ENV{'HOME'}; > my $cwd = $ENV{'PWD'}; > my $log = Mojo::Log->new(path => $cwd . '/log/ccdapi.log', level => > 'info'); > > Use of uninitialized value $cwd in concatenation (.) or string at > /srv/ccdapi/VM01/PROD/v1/ccdapi.pl line 21. > Apr 29 16:16:19 vl-vm-sr824.lb ccdapi[65656]: Can't load application from > file "/srv/ccdapi/VM01/PROD/v1/ccdapi.pl": Can't open file > "/log/ccdapi.log": No such file or directory at > /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccd > Apr 29 16:16:19 vl-vm-sr824.lb ccdapi[65656]: Compilation failed in > require at (eval 81) line 1. > > Cheers ! > > On Thursday, 29 April 2021 at 14:26:01 UTC-4 dim0xff wrote: > >> Here is my Service with perlbrew >> [Service] >> Type=forking >> User=backend >> Group=backend >> WorkingDirectory=/home/backend/app >> Environment=PERLBREW_ROOT=/home/backend/perl5/perlbrew >> ExecStart=/home/backend/perl5/perlbrew/bin/perlbrew exec -q --with >> perl-5.28.0 hypnotoad /home/backend/app/app_backend.pl >> ... >> >> >> Here is perlbrew info: >> $ > perlbrew info >> Current perl: >> Name: perl-5.28.0 >> Path: /home/backend/perl5/perlbrew/perls/perl-5.28.0/bin/perl >> Config: -de -Dprefix=/home/backend/perl5/perlbrew/perls/perl-5.28.0 >> -Aeval:scriptdir=/home/backend/perl5/perlbrew/perls/perl-5.28.0/bin >> Compiled at: Jul 8 2018 23:47:31 >> >> perlbrew: >> version: 0.84 >> ENV: >> PERLBREW_ROOT: /home/backend/perl5/perlbrew >> PERLBREW_HOME: /home/backend/.perlbrew >> PERLBREW_PATH: >> /home/backend/perl5/perlbrew/bin:/home/backend/perl5/perlbrew/perls/perl-5.28.0/bin >> >> PERLBREW_MANPATH: /home/backend/perl5/perlbrew/perls/perl-5.28.0/man >> >> >> On Thu, 29 Apr 2021 at 00:28, llaro...@gmail.com >> wrote: >> > >> > Hi, I'm trying to register my hypnotoad daemon as a service in >> > >> > cat /lib/systemd/system/ccdapi.service >> > [Unit] >> > Description=MY CCDAPI LAB >> > Requires=network.target >> > After=network.target >> > User=ccdapi >> > Group=ccdapi >> > # put here other service requirements >> > >> > [Service] >> > User=ccdapi >> > Group=ccdapi >> > Type=simple >> > Restart=always >> > SyslogIdentifier=ccdapi >> > PIDFile=/home/srv/ccdapi/v1/etc/ccdapi.pid >> > ExecStart=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad >> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl -f >> > ExecStop=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad >> -s /srv/ccdapi/VM01/PROD/v1/ccdapi.pl >> > ExecReload=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad >> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl >> > KillMode=process >> > WorkingDirectory=/srv/ccdapi >> > >> > [Install] >> > WantedBy=multi.user.target >> > >> > When I try to start the service I get >> > >> > -- Unit ccdapi.service has begun starting up. >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: Can't >> locate Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) >> (@INC contains: >> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux >> >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: BEGIN >> failed--compilation aborted at >> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad >> line 2. >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: >> ccdapi.service: main process exited, code=exited, status=2/INVALIDARGUMENT >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: Can't >> locate Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) >> (@INC contains: >> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux >> >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: BEGIN >> failed--compilation aborted at >> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad >> line 2. >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: >> ccdapi.service: control process exited, code=exited status=2 >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Unit >> ccdapi.service entered failed state. >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service >> failed. >> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service >> holdoff time over, scheduling restart. >> > Apr 28
Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"
Thanks to both of you, I managed to get past loading modules while starting the service from systemd. Now there is another bug regarding relative paths and I wonder how to solve it, it seems lib::relative might not do the trick my $homedir = $ENV{'HOME'}; my $cwd = $ENV{'PWD'}; my $log = Mojo::Log->new(path => $cwd . '/log/ccdapi.log', level => 'info'); Use of uninitialized value $cwd in concatenation (.) or string at /srv/ccdapi/VM01/PROD/v1/ccdapi.pl line 21. Apr 29 16:16:19 vl-vm-sr824.lb ccdapi[65656]: Can't load application from file "/srv/ccdapi/VM01/PROD/v1/ccdapi.pl": Can't open file "/log/ccdapi.log": No such file or directory at /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccd Apr 29 16:16:19 vl-vm-sr824.lb ccdapi[65656]: Compilation failed in require at (eval 81) line 1. Cheers ! On Thursday, 29 April 2021 at 14:26:01 UTC-4 dim0xff wrote: > Here is my Service with perlbrew > [Service] > Type=forking > User=backend > Group=backend > WorkingDirectory=/home/backend/app > Environment=PERLBREW_ROOT=/home/backend/perl5/perlbrew > ExecStart=/home/backend/perl5/perlbrew/bin/perlbrew exec -q --with > perl-5.28.0 hypnotoad /home/backend/app/app_backend.pl > ... > > > Here is perlbrew info: > $ > perlbrew info > Current perl: > Name: perl-5.28.0 > Path: /home/backend/perl5/perlbrew/perls/perl-5.28.0/bin/perl > Config: -de -Dprefix=/home/backend/perl5/perlbrew/perls/perl-5.28.0 > -Aeval:scriptdir=/home/backend/perl5/perlbrew/perls/perl-5.28.0/bin > Compiled at: Jul 8 2018 23:47:31 > > perlbrew: > version: 0.84 > ENV: > PERLBREW_ROOT: /home/backend/perl5/perlbrew > PERLBREW_HOME: /home/backend/.perlbrew > PERLBREW_PATH: > > /home/backend/perl5/perlbrew/bin:/home/backend/perl5/perlbrew/perls/perl-5.28.0/bin > PERLBREW_MANPATH: /home/backend/perl5/perlbrew/perls/perl-5.28.0/man > > > On Thu, 29 Apr 2021 at 00:28, llaro...@gmail.com > wrote: > > > > Hi, I'm trying to register my hypnotoad daemon as a service in > > > > cat /lib/systemd/system/ccdapi.service > > [Unit] > > Description=MY CCDAPI LAB > > Requires=network.target > > After=network.target > > User=ccdapi > > Group=ccdapi > > # put here other service requirements > > > > [Service] > > User=ccdapi > > Group=ccdapi > > Type=simple > > Restart=always > > SyslogIdentifier=ccdapi > > PIDFile=/home/srv/ccdapi/v1/etc/ccdapi.pid > > ExecStart=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad > /srv/ccdapi/VM01/PROD/v1/ccdapi.pl -f > > ExecStop=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad -s > /srv/ccdapi/VM01/PROD/v1/ccdapi.pl > > ExecReload=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad > /srv/ccdapi/VM01/PROD/v1/ccdapi.pl > > KillMode=process > > WorkingDirectory=/srv/ccdapi > > > > [Install] > > WantedBy=multi.user.target > > > > When I try to start the service I get > > > > -- Unit ccdapi.service has begun starting up. > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: Can't locate > Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) (@INC > contains: > /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: BEGIN > failed--compilation aborted at > /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad line 2. > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service: > main process exited, code=exited, status=2/INVALIDARGUMENT > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: Can't locate > Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) (@INC > contains: > /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: BEGIN > failed--compilation aborted at > /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad line 2. > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service: > control process exited, code=exited status=2 > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Unit > ccdapi.service entered failed state. > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service > failed. > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service > holdoff time over, scheduling restart. > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: start request > repeated too quickly for ccdapi.service > > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Failed to start > MY CCDAPI LAB. > > -- Subject: Unit ccdapi.service has failed > > -- Defined-By: systemd > > > > > > So I've double-checked Mojo::Base exists ... > > > > [ccdapi@vl-vm-sr824 ~]$ find . | grep 'Mojo.*Base.pm' > > ./VM01/PROD/perl5/lib/perl5/Mojo/Base.pm > > ./VM01/perl5/lib/perl5/Mojo/Base.pm > > ./temp/report/bin/lib/Mojo/Base.pm > > ./.cpan/build/Mojolicious-7.37-yGj97y/blib/lib/Mojo/Base.pm > > ./.cpan/build/Mojolicious-7.37-yGj97y/lib/Mojo/Base.pm > >