gpt4 book ai didi

java - bash 脚本问题启动程序

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:27:58 24 4
gpt4 key购买 nike

我有一个 bash 脚本,它在 AWS EC2 ubuntu 实例启动时执行,使用以下命令通过 AWS 服务器启动配置(本质上也是 bash 脚本)

sudo -u ubuntu /vagrant/test/startAll.sh

我看到的问题是,如果 java 程序是 bash 脚本中的最后一个条目,则它们不会运行,但如果不是最后一个条目,则可以正常运行。我有点困惑为什么会这样。

这是 bash 脚本...

startAll.sh

#!/bin/bash

# set -x

brokerSrvDIR="/vagrant/test/ppp"
meetingSrvDIR="/vagrant/test/clone"
notifySrvDIR="/vagrant/test/notification/production/notificationsrv"
workerDIR="/vagrant/test/ppp/production/ppworker2"

#( cd $workerDIR && { make runworker >>log/out.txt 2>&1 & } )

( cd $brokerSrvDIR && { ./ppp_broker >>log/out.txt 2>&1 & } )

( cd $notifySrvDIR && { make runnotify >>log/out.txt 2>&1 & } )

( cd $meetingSrvDIR && { ./meetingsrv > /dev/null 2>>log/out.txt & } )

( cd $workerDIR && { make runworker >>log/out.txt 2>&1 & } )

#( sleep 10s && cd $brokerSrvDIR && { ./ppp_broker >>log/out.txt 2>&1 & } )

ppp_brokermeetingsrv 是 C 可执行文件
make runworkermake runnotify是运行java程序的Make调用

这是 worker java 程序的 Makefile

生成文件

DLIBS=-lzmq -lczmq
LDFLAGS=
CFLAGS=-DDEBUG
CPFLAG=-cp /usr/local/share/java/*:.
CPFLAGDB=-cp /usr/local/share/java/*:. -XX:+HeapDumpOnOutOfMemoryError -XX:ErrorFile=log/hs_err_pid_%p.log
CPFLAGP=-cp /usr/local/share/java/*:. -

JFLAGS = -g
JAVAC=javac
sources = $(wildcard *.java)
classes = $(sources:.java=.class)

all: $(classes)

clean :
rm -f *.class

%.class : %.java
#export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):/usr/local/lib/*
#export CLASSPATH=$(CLASSPATH):/usr/local/share/java/*:.
$(JAVAC) $(JFLAGS) $(CPFLAG) $<

.ONESHELL:
runworker :
export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):/usr/local/lib/*
export CLASSPATH=$(CLASSPATH):/usr/local/share/java/*:.
java $(CPFLAGDB) -Djava.library.path=/usr/local/lib/ ppworker2

更新:设置 x 输出

ubuntu@ip-xxxx:/vagrant/test$ /vagrant/test/startAll.sh 
+ brokerSrvDIR=/vagrant/test/ppp
+ meetingSrvDIR=/vagrant/test/clone
+ notifySrvDIR=/vagrant/test/notification/production/notificationsrv
+ workerDIR=/vagrant/test/ppp/production/ppworker2
+ cd /vagrant/test/ppp
+ cd /vagrant/test/notification/production/notificationsrv
+ ./ppp_broker
+ cd /vagrant/test/clone
+ make runnotify
+ cd /vagrant/test/ppp/production/ppworker2
+ ./meetingsrv
ubuntu@ip-xxxx:/vagrant/test$ + make runworker

运行上述命令后 ps 的输出:

ubuntu@ip-xxxx:/vagrant/test$ ps -ef | grep make
ubuntu 2104 1 0 18:06 pts/0 00:00:00 make runnotify
ubuntu 2144 1479 0 18:06 pts/0 00:00:00 grep --color=auto make

所以bash脚本根据set x执行make call,但实际上并没有运行。

最佳答案

根据我的评论,我启动了一个新的 EC2 实例,现在一切正常。我暂时将其归结为 EC2 怪异,但如果它再次发生,我将深入挖掘。谢谢!

关于java - bash 脚本问题启动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31569644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com