我正在使用一个使用Go,NodeJS,Java和Scala的控制台模式程序(比方说abc).
为了让abc使用这些语言,我要声明以下语句:
a)在/ etc / environment中:
PATH =在/usr/local / sbin中:在/usr/local / bin目录:/usr/sbin目录:在/usr/bin中:/ sbin目录:/ bin中:在/ usr /本地/去/ BIN”
CLASSPATH = $CLASSPATH:/usr/share/java/scala-library.jar
b)在/etc/login.defs中
ENV_SUPATH PATH = /usr/local / sbin:/usr/local / bin:/usr/sbin:/usr/bin:/ sbin:/ bin:/usr/local / go / bin
ENV_PATH PATH = /usr/local / sbin:/usr/local / bin:/usr/sbin:/usr/bin:/ sbin:/ bin:/usr/local / go / bin
c)a)在/ etc / sudoers中:
`#env_reset
默认值为secure_path =“/usr/local / sbin:/usr/local / bin:/usr/sbin:/usr/bin:/ sbin:/ bin:/usr/local / go / bin”
然后,当我从终端启动abc时,一切都很好,我可以使用上述4种语言中的任何一种.
但是,如果我在/etc/init.d中放置了一个在启动过程中启动abc的脚本(即在启动GUI之前),使用abc中的Java仍然可以,但使用Go,NodeJS或Scala不再起作用了.
然后,我想在启动过程中,在/ etc / sudoers,/ etc / environment和/etc/login.defs中设置的不同环境变量被加载之前,执行启动abc的/etc/init.d中的脚本.
所以,我的问题是:如何在启动我的脚本启动abc之前强制加载环境变量?
任何有关此主题的帮助和建议都将受到全面的赞赏.
TIA.
干杯.
再次感谢Mark和Danila.
下面是我在/etc/init.d中放入的Danila修改后的“abc”脚本文件
#!/bin/sh ##### EDIT: ADD THIS VARS DEFINITIONS: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin" CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar "ENV_SUPATH PATH"="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin" "ENV_PATH PATH"="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin" "Defaults secure_path"="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin" ##### EXPORT this VARS so they are accessible to children:" export "PATH" "CLASSPATH" "ENV_SUPATH PATH" "ENV_PATH PATH" "Defaults secure_path" ### BEGIN INIT INFO # Provides: abc # required-Start: $remote_fs $syslog # required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: abc initscript # Description: This initscript starts and stops abc ### END INIT INFO # Author: Fnux,fnux.fl at gmail dot com # Version: 1.2 # Note: (edit ABC_PATH if abc isn't installed in /opt/abc) NAME=abc ABC_PATH=/opt/abc START="-d" STOP="-k" VERSION="-v" SCRIPTNAME=/etc/init.d/$NAME STARTMESG="\nStarting abc in deamon mode." UPMESG="\n$NAME is running." DOWNMESG="\n$NAME is not running." STATUS=`pidof $NAME` # Exit if abc is not installed [ -x "$ABC_PATH/$NAME" ] || exit 0 case "$1" in start) echo $STARTMESG cd $ABC_PATH ./$NAME $START ;; stop) cd $ABC_PATH ./$NAME $STOP ;; status) if [ "$STATUS" > 0 ] ; then echo $UPMESG else echo $DOWNMESG fi ;; restart) cd $ABC_PATH ./$NAME $STOP echo $STARTMESG ./$NAME $START ;; version) cd $ABC_PATH ./$NAME $VERSION ;; *) echo "Usage: $SCRIPTNAME {start|status|restart|stop|version}" >&2 exit 3 ;; esac :
现在,当执行此脚本(即.dodo service abc start)时,我收到以下错误消息:
fnux@fx8150-1204-3:~$sudo service abc start /etc/init.d/abc: 4: /etc/init.d/abc: ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin: not found /etc/init.d/abc: 5: /etc/init.d/abc: ENV_PATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin: not found /etc/init.d/abc: 6: /etc/init.d/abc: Defaults secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin: not found /etc/init.d/abc: 7: export: ENV_SUPATH PATH: bad variable name fnux@fx8150-1204-3:~$
那么,我哪里错了?
TIA解释如何修复此脚本.
干杯. 原文链接:/linux/395622.html