It’s easiest to use Putty to configure and control your Pi. Learning the command line is a bit hard now, but it will give you an advantage when you start scripting later on. Also, the GUI on the Pi below Pi2 can be quite slow.
This is my startup script:
#!/bin/bash
#
BASE=/tmp
PID=$BASE/blynk.pid
LOG=$BASE/blynk.log
ERROR=$BASE/blynk-error.log
COMMAND="/storage/java/jre/bin/java -jar /storage/blynk/server.jar"
status() {
echo
echo "==== Status"
if [ -f $PID ]
then
echo
echo "Pid file: $( cat $PID ) [$PID]"
echo
ps -ef | grep -v grep | grep $( cat $PID )
else
echo
echo "No Pid file"
fi
}
start() {
if [ -f $PID ]
then
echo
echo "Already started. PID: [$( cat $PID )]"
else
echo "==== Starting"
touch $PID
if nohup $COMMAND >>$LOG 2>&1 &
then
echo $! >$PID
echo "Done"
echo "$(date '+%Y-%m-%d %X'): START" >>$LOG
else
echo "Error"
/bin/rm $PID
fi
fi
}
kill_cmd() {
SIGNAL=""; MSG="Killing "
while true
do
LIST=`ps -ef | grep -v grep | grep server.jar | awk '{print$1}'`
if [ "$LIST" ]
then
echo; echo " $MSG $LIST" ; echo
echo $LIST | xargs kill $SIGNAL
sleep 2
SIGNAL="-9" ; MSG="Killing $SIGNAL"
if [ -f $PID ]
then
/bin/rm $PID
fi
else
echo; echo "All killed" ; echo
break
fi
done
}
stop() {
echo "==== Stop"
if [ -f $PID ]
then
if kill $( cat $PID )
then echo "Done."
echo "$(date '+%Y-%m-%d %X'): STOP" >>$LOG
fi
/bin/rm $PID
kill_cmd
else
echo "No pid file. Already stopped?"
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop ; echo "Sleeping..."; sleep 1 ;
start
;;
'status')
status
;;
*)
echo
echo "Usage: $0 { start | stop | restart | status }"
echo
exit 1
;;
esac
exit 0
Paste this in a file called “blynk.sh” in the same location as server.jar file.
Very important: when you did that, the Linux system needs to know it is a script, so do this:
OpenELEC:~/blynk # chmod +x blynk.sh
OpenELEC:~/blynk #
This will indicate to the system you can execute it, like so:
OpenELEC:~/blynk # ./blynk.sh start
==== Starting
Done
OpenELEC:~/blynk #
Or stop the server:
OpenELEC:~/blynk # ./blynk.sh stop
==== Stop
Done.
Killing 569
All killed
OpenELEC:~/blynk #
Or use the option restart to, well, you guessed it, restart your server. You could add this script to /etc/init.d folder and make it run at start up (https://gist.github.com/naholyr/4275302 see this for example).
I’ve also created an update script:
#!/bin/bash
#
# Update script for Blynk Server on Linux-like systems.
# This script relies on the use of curl for fetching Blynk.jar file
# It also has a reference to "blynk.sh", which is my start script.
#
# My blynk.sh script refers to "server.jar" which is a symbolic link
# to the actual server.jar file. That way it's easy to use in startup
# routines etc.
#
# You can change the variables to your local situation (mine is a Raspberry
# Pi with OpenELEC, hence the Storage path).
#
# This is a really dirty script, it doesn't do RegEx, but just assumes
# that the URL for GitHub will always be the same length (which it
# probably will).
#----------------------------------------------------------
# BEGIN User variables, change these to your situation
#----------------------------------------------------------
# Base path to your Blynk server.jar file
BASE=/storage/blynk
# Startup script name (full path)
STARTUP="$BASE/blynk.sh"
# The symlink used in blynk.sh startup file (full path)
SYMLINK="$BASE/server.jar"
#----------------------------------------------------------
# END USER VARIABLES, change below only if you are sure
# about it ;-)
#----------------------------------------------------------
URL=https://github.com/blynkkk/blynk-server/releases/latest
REDIRECT=`curl $URL`
LATESTVERSION=${REDIRECT:89:6}
DOWNLOAD="http://github.com/blynkkk/blynk-server/releases/download/v$LATESTVERSION/server-$LATESTVERSION-java8.jar"
CURRENT=`readlink $SYMLINK`
CURRENTVERSION=${CURRENT:7:6}
echo "### Current version from Symlink ###"
echo $CURRENTVERSION
echo "### New Version ###"
echo $LATESTVERSION
if [ $CURRENTVERSION = $LATESTVERSION ] ; then
echo "You are up to date"
exit 0
else
echo "New version available, downloading"
wget $DOWNLOAD
fi
echo "Removing old Symlink and making new one"
rm $SYMLINK
ln -s server-$LATESTVERSION-java8.jar server.jar
# Call the other startup script here
echo "Restarting Blynk server"
/bin/bash $BASE/blynk.sh restart
echo "All done!"
Same thing applies, put this in a file called “update.sh” and also chmod +x that file. The update.sh assumes there is a Blynk installation in /storage/blynk (so, adapt this variable in the script to where your server.jar file is!!). It also makes use of the forementioned blynk.sh script to restart the server if a new version is downloaded.