F
F
Free4ert2017-01-22 13:18:58
Perl
Free4ert, 2017-01-22 13:18:58

What is the problem with autorun Perl script through SystemD?

When I run my script in the normal way:

/usr/bin/perl /usr/local/scripts/sc_ts.pl /usr/local/scripts/

There are no problems.
But when I use the script above and run through systemd:
systemctl start sc_ts
[Unit]
Description=My Perl Script
After=network.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/perl /usr/local/scripts/sc_ts.pl /usr/local/scripts/
ExecStop=/usr/bin/killall /usr/bin/perl

[Install]
WantedBy=multi-user.target

Errors of this kind, as well as many "not installed" components:
can't locate object method "connect" via package "DBI"
Thread::State 0.09 module is not installed.
File::Scan::ClamAV module is not installed.
Mail::SPF::Query module is not installed.
Tie::RDBM module is not installed - database usage not available

I think there may be problems with environment variables. In init.d autostart worked successfully.
Has anyone migrated Perl scripts from CentOS 6 to CentOS 7?
!# perl -e 'print "$_\n" foreach @INC'
/root/perl5/lib/perl5/5.16.3/x86_64-linux-thread-multi
/root/perl5/lib/perl5/5.16.3
/root/perl5/lib/perl5/x86_64-linux-thread-multi
/root/perl5/lib/perl5
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5


!# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

export PERL_LOCAL_LIB_ROOT="$PERL_LOCAL_LIB_ROOT:/root/perl5";
export PERL_MB_OPT="--install_base /root/perl5";
export PERL_MM_OPT="INSTALL_BASE=/root/perl5";
export PERL5LIB="/root/perl5/lib/perl5:$PERL5LIB";
export PATH="/root/perl5/bin:$PATH";
!# echo $PATH
/root/perl5/bin:/sbin:/bin:/usr/sbin:/usr/bin

Actually, it was necessary to change the environment for running the script through systemd.
[Service]
Environment="PATH=
And add data from .bashrc there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akzhan, 2017-08-27
@akzhan

I would recommend taking all the answers out of the question and adding them as an answer :) It's more convenient for the next seeker to read.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question