root@mountain-lion:/opt/smartfox# ls -lha
total 180K
drwxr-xr-x 8 root root 4.0K 2012-06-01 14:09 .
drwxr-xr-x 4 root root 4.0K 2012-06-01 09:41 ..
drwxr-xr-x 8 root root 4.0K 2009-05-17 21:57 lib
lrwxrwxrwx 1 root root 22 2012-06-01 09:41 logs -> /var/opt/smartfox/logs
-rwxr-xr-x 1 root root 1.4K 2012-06-01 14:28 run.sh
root@mountain-lion:/opt/smartfox# cat run.sh
#!/bin/bash
java -cp "./:./sfsExtensions/:lib/activation.jar:lib/commons-beanutils.jar:lib/commons-collections-3.2.jar:lib/commons-dbcp-1.2.1.jar:lib/commons-lang-2.3.jar:lib/commons-logging-1.1.jar:lib/commons-pool-1.2.jar:lib/concurrent.jar:lib/ezmorph-1.0.3.jar:lib/h2.jar:lib/js.jar:lib/json-lib-2.1-jdk15.jar:lib/json.jar:lib/jsr173_1.0_api.jar:lib/jysfs.jar:lib/jython.jar:lib/nanoxml-2.2.1.jar:lib/wrapper.jar:lib/xbean.jar:lib/javamail/imap.jar:lib/javamail/mailapi.jar:lib/javamail/pop3.jar:lib/javamail/smtp.jar:lib/jetty/jetty.jar:lib/jetty/jetty-util.jar:lib/jetty/jstl.jar:lib/jetty/multipartrequest.jar:lib/jetty/servlet-api.jar:lib/jetty/standard.jar:lib/jsp-2.1/commons-el-1.0.jar:lib/jsp-2.1/core-3.1.0.jar:lib/jsp-2.1/jsp-2.1.jar:lib/jsp-2.1/jsp-api-2.1.jar:lib/jsp-2.1/jstl.jar:lib/jsp-2.1/standard.jar:lib/lsc.jar:lib/commons-io-1.4.jar" \
it.gotoandplay.smartfoxserver.SmartFoxServer > logs/smartfox.out 2>&1 &
JAVAPID=$!
echo "Started Smartfox. JVM PID = $JAVAPID"
trap "echo Stopping Smartfox.; kill $JAVAPID" INT TERM
wait
echo "Smartfox stopped."
root@mountain-lion:/opt/smartfox# start-stop-daemon --start --make-pidfile --pidfile /var/opt/smartfox/smartfox.pid --exec ./run.sh
start-stop-daemon: unable to start ./run.sh (No such file or directory)
为啥找不到start-stop-daemon
脚本?
答案1
我发现最好避免在启动脚本等中使用相对路径。如果事情变得混乱,最好尽可能明确 - 这样您就不会猜测“我想知道执行此脚本的进程认为哪个目录是当前的”。
这也适用于 cron 运行的任何内容。cron 运行的环境与您作为普通用户运行的环境不同。
答案2
替换./run.sh
为pwd
告诉我它将目录更改为/
。我想我需要更改./run.sh
为/opt/smartfox/run.sh
并更新脚本以设置其自己的目录。