2013-11-20 24 views
0

我很好奇su -c「cmd arg」和tomcat在shell腳本中的工作原理。爲什麼我不能在shell腳本中使用catalina啓動tomcat

從CMD線手動,我跑:

su -m tomcat -c /path/to/tomcat/catalina.sh start 

這沒有奏效。但是,如果我把cmd在引號,它的工作

su -m tomcat -c "/path/catalina.sh start" 

在一個shell腳本(試圖所以它會自動開始運行chkconfig的),我有這樣的事情:

START="/path/catalina.sh start" 
... 
... 
su -m tomcat -c "$START" 

的命令是在引號中,因爲我手工發現需要引號。 當我運行該腳本,輸出回來爲:

Using CATALINA_BASE: /apps/local/apache-tomcat-7.0.42 
Using CATALINA_HOME: /apps/local/apache-tomcat-7.0.42 
Using CATALINA_TMPDIR: /apps/local/apache-tomcat-7.0.42/temp 
Using JRE_HOME:  /usr/java/default 
Using CLASSPATH:  /apps/local/apache-tomcat-7.0.42/bin/bootstrap.jar:/apps/local/apache-tomcat-7.0.42/bin/tomcat-juli.jar 
Usage: catalina.sh (commands ...) 
commands: 
    debug    Start Catalina in a debugger 
    debug -security Debug Catalina with a security manager 
    jpda start  Start Catalina under JPDA debugger 
    run    Start Catalina in the current window 
    run -security  Start in the current window with security manager 
    start    Start Catalina in a separate window 
    start -security Start in a separate window with security manager 
    stop    Stop Catalina, waiting up to 5 seconds for the process to end 
    stop n   Stop Catalina, waiting up to n seconds for the process to end 
    stop -force  Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running 
    stop n -force  Stop Catalina, wait up to n seconds and then use kill -KILL if still running 
    configtest  Run a basic syntax check on server.xml - check exit code for result 
    version   What version of tomcat are you running? 
Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined 

這個輸出是一樣,如果我手動運行catalina.sh W/O任何啓動/停止的論點。
爲什麼shell腳本中的開始/停止選項被忽略?是的,我用startup.sh和shutdown.sh替換了catalina.sh,這使腳本能夠正常工作,但我仍然很好奇爲什麼在腳本里面,su -c「cmd arg」似乎忽略了命令的參數部分。

在此先感謝您的解釋。如果它像殼牌擴展和報價移除一樣簡單,我會開槍自己,除非我做一些事情使其不會失去報價。

+0

我不認爲這種現象對Tomcat或catalina.sh腳本有特別的意義。看看'su'手冊頁,它表示'-c'後面跟着一個_single command_。也許這是開發人員以某種不雅的方式陳述,只有緊隨其後的參數將被解釋爲命令,而不是可能跟隨參數。在這方面,它的行爲與例如'ssh'或'rsh',它將shell調用的所有後續參數解釋爲要執行的命令的參數。我想報價是簡單的要求。 –

回答

0

我用下面的在我的tomcat的初始化文件:

... 
su -l $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh 
... 

的-l創建一個登錄shell,並允許你通過你所需要的。

相關問題