2016-11-24 104 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