我有一个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_broker
和meetingsrv
是C可执行文件
make runworker
和make runnotify
是进行运行java程序的调用
这里是工人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调用,但它实际上并没有运行。
答案 0 :(得分:0)
根据我的评论,我创建了一个新的EC2实例,现在一切正常。我现在要把它归结为EC2的怪异,但如果它再次发生,我会深入挖掘。谢谢!