BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Problem with crontab -e

I have rpi zero W and I have problem.(Raspbian Buster-lite)
So when I have added to crontab -e this line through PuTTY:

@reboot java -jar /home/pi/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &

After reboot rpi server doesn’t run.Help me please.

Please do some research and check this first:

When I pasted this line:

java -jar /home/pi/server-0.41.11.jar -dataFolder /home/pi/Blynk &

I have got this error:

Error: Unable to access jarfile /home/pi/server-0.41.11-java8.jar

You have to know where you put your jar file.
You have to test the command in a terminal first to know it’s working before pasting into /etc/rc.local file

For example, you place your jar and Data files in a directory /home/pi/Blynk, you use the following command in your terminal as well as /etc/rc.local

java -jar /home/pi/Blynk/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &

You posted something strange, as the machine complains about no jarfile /home/pi/server-0.41.11-java8.jar, while your command specifying another jarfile /home/pi/Blynk/server-0.41.11.jar

If you have use the correct command specifying correct jarfile location, but still get error:

Error: Unable to access jarfile /home/pi/Blynk/server-0.41.11-java8.jar

then the problem might be you set wrong file permission when install the Blynk Server jarfile.
If this is the case, use sudo chown and/or sudo chmod commands to do the change.

I’m sorry, unwittingly I pasted bad command, but I used correct command and I give chmod 777 on jar file and nothing.To run manually I always have to go to sudo su

So, the problem is that you used root account to install Blynk, the result is all files have owner:group = root:root, and you won’t have the right to access and execute while using pi or another non-root account. That’s why it only works when you’re using sudo su to be root.

The fix now is to change the files’ ownership back to pi or whatever account you’re using. Let’s say pi.
I assume that you have all Blynk server files installed in /home/pi/Blynk. You have to use the following command while you’re using pi account:

# comment, don't run. Go to pi home directory
$cd /home/pi
# comment, don't run. Get ownership:group back to pi:pi
$sudo chown -R pi:pi /home/pi/Blynk
# comment, don't run. Change mode to -rwxr----- for all files.  Not perfect but OK for now for you to run
$chmod -R 740 /home/pi/Blynk

Also please read the note about not using root account unless absolutely necessary in:

One note is that you’d better not use root account in everyday job. One small mistake can destroy your system. Use pi or whatever account you create but root. Whenever you need root privilege, use sudo. Also change the default root and pi password.

pi@raspberrypi-02:~ $ sudo passwd root
pi@raspberrypi-02:~ $ passwd

sudo apt-get install oracle-java8-jdk(Error:This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘oracle-java8-jdk’ has no installation candidate)
This command not working for me. I installed zulu java form this site: https://community.openhab.org/t/howto-install-zulu-embedded-java-on-raspberry-pi-3/22589/44
that’s why I needed sudo su

So is the problem solved now? If not, have you tried to change the ownership:group permission yet?

I was found my problem. I had changed sudo su (https://community.openhab.org/t/howto-install-zulu-embedded-java-on-raspberry-pi-3/22589/44) because command sudo apt-get install oracle-java8-jdk not working Do you know how this repair?

You can use openjdk-8 instead of oracle-java8-jdk by using this command

$sudo apt install openjdk-8-jdk

It’s a hassle to use oracle-java now as they change the model. You have to login to an account, download the package to install. Openjdk java is as good as oracle-java

now I get from /etc/rc.local this: Error: Unable to access jarfile /home/pi/server-0.41.11-java8.jar
I even changed this:

comment, don’t run. Go to pi home directory

$cd /home/pi

comment, don’t run. Get ownership:group back to pi:pi

$sudo chown -R pi:pi /home/pi/Blynk

comment, don’t run. Change mode to -rwxr----- for all files. Not perfect but OK for now for you to run

$chmod -R 740 /home/pi/Blynk

I think you use the wrong command in /etc/rc.local

First, where do you put your server-0.41.11-java8.jar ?
From your error, your command in /etc/rc.local is

java -jar /home/pi/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &

this requires that your server-0.41.11-java8.jar be placed in /home/pi

But I think you put it in /home/pi/Blynk, and the command to put in /etc/rc.local must be

java -jar /home/pi/Blynk/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &

You have to test in a terminal first to see if the command is actually working before putting it in /etc/rc.local

Find out where server-0.41.11-java8.jar is by

$ls -la /home/pi/server-0.41.11-java8.jar
$ls -la /home/pi/Blynk/server-0.41.11-java8.jar
# comment, don't run. Search from /home/pi
$sudo find /home/pi -name server-0.41.11-java8.jar -print

OK I’m idiot. Thank you.You helped me a lot

No, you’re very good. You’ve have finished many complicated steps in order to successfully install and run your own Blynk Local Server. Just a very small mistake means nothing.

Updated December 3rd 2019

I just like to add a note about this crontab -e problem which seems to affect many people running Local Blynk Server. The crontab is started very early in the rebooting process, when the network might not be ready yet. All other commands in crontab running periodically (such as every 5 minutes) will work OK, but the very first one if it relies on Network operation. Certainly all the commands requiring Network operation will fail if no precaution is taken.

For example, the crontab command

@reboot java -jar /home/pi/Blynk/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &

relying on Network normally won’t work when it was started too early in the reboot process.

The solution is to add a sleep command (60s, 90s or 120s), waiting for Network ready, then run Blynk Server to give it a chance to be successful.

The crontab command can be:

@reboot sleep 60 && java -jar /home/pi/Blynk/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &

or

@reboot sleep 90 && java -jar /home/pi/Blynk/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk &