0
當我啓動帶./script的服務腳本啓動時,通過代理(已找到環境變量)能夠獲取憑證,如果啓動服務腳本(如服務腳本啓動時無法獲取)通過代理(未找到環境變量),代理沒有找到憑據。我如何通過服務腳本啓動來處理這個腳本?運行服務啓動腳本時環境變量未加載
腳本:
#!/bin/bash -l
# chkconfig: 2345 20 80
if [ "$system" = "redhat" ]; then
## source platform specific external scripts
. /etc/init.d/functions
## set or override platform specific variables
lockfile=${LOCKFILE-/var/lock/subsys/$SERVICE_NAME}
## set or override platform specific functions
start_daemon() {
daemon --user $1 --pidfile $2 "$3 $4"
}
log_daemon_msg() {
echo -n $"$1"
}
echo_ok() {
echo_success; echo
}
echo_fail() {
echo_failure; echo
}
log_success_msg() {
success $"[email protected]"
}
log_failure_msg() {
failure $"[email protected]"
echo $"[email protected]"
}
log_action_msg() {
echo [email protected]
}
fi
if [ -n "$http_proxy" ] ; then
echo "proxy found"
echo $http_proxy | grep "@"
if [ $? -eq 0 ]; then
PROXY_HOST=$(echo $http_proxy | sed 's/http:\/\/.*@\(.*\):.*/\1/')
PROXY_PORT=$(echo $http_proxy | sed 's/http:\/\/.*@.*:\(.*\)/\1/' | tr -d "/")
USERNAME=$(echo $http_proxy | sed 's/http:\/\/\(.*\)@.*/\1/'|awk -F: '{print $1}')
PASSWORD=$(echo $http_proxy | sed 's/http:\/\/\(.*\)@.*/\1/'|awk -F: '{print $2}')
else
PROXY_HOST=$(echo $http_proxy | sed 's/http:\/\/\(.*\):.*/\1/')
PROXY_PORT=$(echo $http_proxy | sed 's/http:\/\/.*:\(.*\)/\1/' | tr -d "/")
fi
fi
start() {
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
CMD="java "
if [ -n "$PROXY_HOST" -a -n "$PROXY_PORT" ] ; then
CMD="java -Dhttps.proxyHost=$PROXY_HOST -Dhttps.proxyPort=$PROXY_PORT"
if [ -n "$USERNAME" -a -n "$PASSWORD" ]; then
CMD="$CMD -Dhttps.proxyUser=$USERNAME -Dhttps.proxyPassword=$PASSWORD"
fi
fi
#nohup $CMD -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
#echo "$PATH_TO_JAR"
echo "$CMD"
nohup $CMD -jar $PATH_TO_JAR 2>> /tmp/glog >> /tmp/glog &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
}
case "$1" in
start)
start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
當我運行此腳本像./script開始,腳本能夠找到代理設置,並通過代理設置。但在使用服務腳本運行時,卻無法找到代理設置。在運行服務腳本時,我錯過了什麼來加載環境變量?