2016-11-24 135 views
-1

我有此內容的示例文件:創建的init.d腳本文件

#!/bin/bash 

# Setting environment 

CLASSPATH="." 
CLASSPATH="$CLASSPATH:props" 
CLASSPATH="$CLASSPATH:cfg" 
CLASSPATH="$CLASSPATH:./bin/*" 
CLASSPATH="$CLASSPATH:./wslib/*" 
CLASSPATH="$CLASSPATH:./oalib/*" 

JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8" 

# RAM usage settings 
JAVA_OPTS="$JAVA_OPTS -Xms1024m -Xmx1024m" 

# Settings of GC 
JAVA_OPTS="$JAVA_OPTS -XX:ParallelGCThreads=2" 

# Print of memory usage 
JAVA_OPTS="$JAVA_OPTS -Xloggc:./log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution" 

# setting config 
JAVA_OPTS="$JAVA_OPTS se.highex.ebe.adaptor.Adapter -config cfg/config_gw_ws.xml" 

echo $CLASSPATH 
echo $JAVA_OPTS 

export CLASSPATH 
export JAVA_OPTS 

java $JAVA_OPTS 

文件在/app/somepath/stpa.sh

定位我怎麼可以創建一個文件init.d中爲開始/停止/重新啓動嗎?

我發現這個tutorial,但在服務stpa開始命令在終端沒有任何消息,我想,我的腳本不工作。但找不到原因。

P.S.對不起,我的英語不好!

編輯: 這是我STPA文件在/etc/init.d

#!/bin/sh 
# 
# chkconfig: 2345 90 60 

name="STPA_WS" 
command="/app/STPAdapterPG/stpa_ws.sh" 
command_args="" 
daemon="/usr/local/bin/daemon" 

[ -x "$daemon" ] || exit 0 
[ -x "$command" ] || exit 0 

daemon_start_args="" 
pidfiles="/var/run" 
user="" 
chroot="" 
chdir="" 
umask="" 
stdout="daemon.info" 
stderr="daemon.err" 

case "$1" in 
    start) 
     if "$daemon" --running --name "$name" --pidfiles "$pidfiles" 
     then 
      echo "$name is already running." 
     else 
      echo -n "Starting $name..." 
      "$daemon" --respawn $daemon_start_args \ 
       --name "$name" --pidfiles "$pidfiles" \ 
       ${user:+--user $user} ${chroot:+--chroot $chroot} \ 
       ${chdir:+--chdir $chdir} ${umask:+--umask $umask} \ 
       ${stdout:+--stdout $stdout} ${stderr:+--stderr $stderr} \ 
       -- \ 
       "$command" $command_args 
      echo done. 
     fi 
     ;; 

    stop) 
     if "$daemon" --running --name "$name" --pidfiles "$pidfiles" 
     then 
      echo -n "Stopping $name..." 
      "$daemon" --stop --name "$name" --pidfiles "$pidfiles" 
      echo done. 
     else 
      echo "$name is not running." 
     fi 
     ;; 

    restart|reload) 
     if "$daemon" --running --name "$name" --pidfiles "$pidfiles" 
     then 
      echo -n "Restarting $name..." 
      "$daemon" --restart --name "$name" --pidfiles "$pidfiles" 
      echo done. 
     else 
      echo "$name is not running." 
      exit 1 
     fi 
     ;; 

    status) 
     "$daemon" --running --name "$name" --pidfiles "$pidfiles" --verbose 
     ;; 

    *) 
     echo "usage: $0 <start|stop|restart|reload|status>" >&2 
     exit 1 
esac 

exit 0 
+0

你可以嘗試運行'/etc/init.d/stpa start'來查看腳本是否正確調用。 – Inian

回答

0

我覺得你沒完成的init.d腳本格式,你只是需要添加的內容像你提到的教程:

case "$1" in 
    start) 


    #here do something you need when start 
    ;; 

stop) 
    #here do something you need when stop 

    ;; 

restart|reload) 


    ;; 

status) 

    ;; 

*) 

    echo "usage: $0 <start|stop|restart|reload|status>" >&2 

    exit 1 
esac