B4J Question Trying try get b4j program to run at startup

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi all.

Trying to get my b4j app to run at startup. I have read and re-read ideas on the forum and just cannot get this script to work. I can type at the command line and start the program fine.

B4X:
nohup /home/jre1.8.0_91/bin/java -jar /home/cloud-kvs/CloudKvs_Server.jar > nohup.out &[]

If I use this script and check the log I get 'Error: Unable to access jarfile /home/cloud-kvs/CloudKvs_Server.jar'

Any ideas?

B4X:
#!/bin/sh
### BEGIN INIT INFO
# Provides: Cloud KVS Server
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Cloud KVS Server
# Description: Cloud KVS Server
### END INIT INFO

# Actions
SERVICE_NAME=CloudKvsServer
PATH_TO_JAR=/home/cloud-kvs/CloudKvs_Server.jar
PID_PATH_NAME=/tmp/cloudkvs-pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
#nohup /home/jre1.8.0_91/bin/java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
nohup /home/jre1.8.0_91/bin/java -jar $PATH_TO_JAR > nohup.out &
# Change Here the filename of the .log file
# if no Logfile is neded then comment the next line with #
# nohup /home/jre1.8.0_91/bin/java -jar $PATH_TO_JAR /tmp 2>> /var/log/gpio.log >> /var/log/gpio.log &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
;;
stop)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stoping ..."
kill $PID;
echo "$SERVICE_NAME stopped ..."
rm $PID_PATH_NAME
else
echo "$SERVICE_NAME is not running ..."
fi
;;
restart)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stopping ...";
kill $PID;
echo "$SERVICE_NAME stopped ...";
rm $PID_PATH_NAME
echo "$SERVICE_NAME starting ..."
#nohup /home/jre1.8.0_91/bin/java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
nohup /home/jre1.8.0_91/bin/java -jar $PATH_TO_JAR > nohup.out &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is not running ..."
fi
;;
esac
 

udg

Expert
Licensed User
Longtime User
Hi Jake,
did you double-checked path and filename with special regard to hyphen/underscore and capital/lowercase letters?

udg
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
What is the result when you run the script from the command line?

B4X:
sh /path/to/script.sh start

Sounds like a permissions issue. Do you use a different role to start the jar at startup ?
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Still fails. I am not even worried about running it at startup. :) I just want it to work.
I am logged in as root.

Works
nohup /home/jre1.8.0_91/bin/java -jar /home/cloud-kvs/CloudKvs_Server.jar > nohup.out &

Fails
/path/to/script.sh start
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Jake,

KVS is all capital in filename..

don't know why

nohup /home/jre1.8.0_91/bin/java -jar /home/cloud-kvs/CloudKvs_Server.jar > nohup.out &

works..
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
AAAAAAAAAAAAAAAAAAAAAAAAAAAaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

4 freek-in hours wasted. I think I am just getting to old for this. :(
 
Upvote 0

udg

Expert
Licensed User
Longtime User
to old for this

Unrecognized expression. Try again. :D

Well, it seems it happened again.. did you mean "too old"? eheh

udg
 
Upvote 0
Top