B4J Question Raspiberry Pi how to auto start java server app?

dragonguy

Active Member
Licensed User
Longtime User

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi, what is /tmp ?

nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
I have a script as following,It jusy as that example.
I could run it as following
/etc/init.d/kiosk start
/etc/init.d/kiosk stop


But it is nothing when i typing /etc/init.d/kiosk. How can i pass "start" as argment when i auto booting by init.d ?


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

# Actions
SERVICE_NAME=AsiaIOT
PATH_TO_JAR=/home/linaro/asia/asia_iot1.jar
PID_PATH_NAME=/tmp/AsiaIOT-pid
case $1 in
start)
    echo "Starting $SERVICE_NAME ..."
    if [ ! -f $PID_PATH_NAME ]; then
    nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
    # Change Here the filename of the .log file
    # if no Logfile is neded then comment the next line with #
    # nohup 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 java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is not running ..."
fi
;;
esac
 
Last edited:
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
Step2:
sudo chmod +x /etc/init.d/<name of your start script>

Step3:
sudo update-rc.d <name of your start script> defaults

after doing this, your script will start automatic when system boot.
 
Upvote 0
Top