Reputation: 105
I'm trying to create a service script in /etc/init.d to run my shell script wich is under /home/user !!
here a part of my script :
#! /bin/sh
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/user/workspace/eattogether/app-server/app.server.core/target/wisdom
DESC="chameleon service"
NAME=chameleon.sh
DAEMON=/home/user/workspace/eattogether/app-server/app.server.core/target/wisdom/$NAME
DAEMON_ARGS="start"
PIDFILE=/home/user/workspace/eattogether/app-server/app.server.core/target/wisdom/CHAMELEON.pid
SCRIPTNAME=/etc/init.d/spheros
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
do_start()
{
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
when I tr to execute this script i got an error : cannot access ./bin/*.jar: No such file or directory
here my other script :
# Check if the RUNNING_PID file is not there already
if [ -f RUNNING_PID ]; then
echo "[error] RUNNING_PID existing. Is this chameleon already running?"
exit 1
fi
#CLASSPATH=$(JARS=("bin"/*.jar); IFS=:; echo "${JARS[*]}")
for i in `ls ./bin/*.jar`
do
CLASSPATH=${CLASSPATH}:${i}
done
if test "$1" = "--interactive"; then
"$JAVA" -cp ${CLASSPATH} ${JVM_ARGS} -Dchameleon.home=$dir org.ow2.chameleon.core.Main "$@"
else
"$JAVA" -cp ${CLASSPATH} ${JVM_ARGS} -Dchameleon.home=$dir org.ow2.chameleon.core.Main "$@" &
echo $! > RUNNING_PID
fi
any idea how to resolve this ?? tell the service to use the directory where the script is located ???
Upvotes: 1
Views: 1431
Reputation: 105
thanks jackman for the reply,
I did found a solution for this issue. I decided to use :
start-stop-daemon --chdir /path/to/my/script
this solved my problem.
Upvotes: 1
Reputation: 246807
You could add this to the daemon script:
cd -P "$(dirname "$0")"
But don't do this:
for i in `ls ./bin/*.jar`
do this instead
for i in ./bin/*.jar
and let the shell expand the filenames for you.
You should quote variables like "$this"
not like ${this}
Upvotes: 0