upstart 和 LD_LIBRARY_PATH

upstart 和 LD_LIBRARY_PATH

我是 upstart 新手,需要通过它启动一个进程。但是我遇到了如下所述的错误。

我的脚本内容

description "Server"
author "Neeraj"

expect fork

respawn
respawn limit 5 10

console log

pre-start script
    echo "`/bin/date -u`: start myappname"
end script

script
    env LD_LIBRARY_PATH=/var/packages/myapp/target/bin
    export LD_LIBRARY_PATH
    exec /var/packages/myapp/target/bin/myappname --local-path=/var/lib/myapp
end script

post-stop script
    echo "`/bin/date -u`: stop myappname"
end script

执行脚本后出错

bash-4.3# cat /var/log/upstart/pkg-myappname.log
2016-12-07T15:15:11+0800 Wed Dec  7 07:15:11 UTC 2016: start myappname
2016-12-07T15:15:11+0800 TERM=vt102
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
PWD=/
SHLVL=1
UPSTART_INSTANCE=
UPSTART_JOB=pkg-myappname
_=/bin/env
LD_LIBRARY_PATH=/var/packages/myapp/target/bin
LD_LIBRARY_PATH
2016-12-07T15:15:11+0800 /var/packages/myapp/target/bin/myappname: error while loading shared libraries: libhttp.so: cannot open shared object file: No such file or directory
bash-4.3# vi /etc/init/pkg-myappname.conf
bash-4.3# cat /var/log/upstart/pkg-myappname.log
2016-12-07T15:15:11+0800 Wed Dec  7 07:15:11 UTC 2016: start myappname
2016-12-07T15:15:11+0800 TERM=vt102
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
PWD=/
SHLVL=1
UPSTART_INSTANCE=
UPSTART_JOB=pkg-myappname
_=/bin/env
LD_LIBRARY_PATH=/var/packages/myapp/target/bin
LD_LIBRARY_PATH
2016-12-07T15:15:11+0800 /var/packages/myapp/target/bin/myappname: error while loading shared libraries: libhttp.so: cannot open shared object file: No such file or directory

问题是我的可执行文件依赖于一些共享库,我已将这些共享库的 LD_LIBRARY_PATH 设置为正确的位置。但是一旦执行调用,它就看不到 LD_LIBRARY_PATH 位置并报告错误。

知道我在这里做错了什么吗?

答案1

回答我自己的问题。我不确定这是编写 upstart 脚本的解决方法还是正确的方法。但这就是我解决问题的方法。它现在能够正确定位共享库。

  1. 删除脚本,结束脚本。
  2. 删除了出口声明。

以下是工作脚本。

description "Server"
author "Neeraj"

expect fork

respawn
respawn limit 5 10

console log

pre-start script
    echo "`/bin/date -u`: start myappname"
end script

env LD_LIBRARY_PATH=/var/packages/myapp/target/bin
exec /var/packages/myapp/target/bin/myappname --local-path=/var/lib/myapp

post-stop script
    echo "`/bin/date -u`: stop myappname"
end script

相关内容