我有一个包含此内容的示例文件:
#!/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
如何为start / stop / restart创建init.d文件呢?
我找到了这个tutorial,但是在 service stpa start 命令后,终端中没有任何消息,我认为我的脚本无效。但无法找到原因。
P.S。抱歉我的英语不好!
修改 这是我/etc/init.d
中的 stpa 文件#!/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 :(得分: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