I wrote a program in Java, which uses the RXTX serial port, so I had to include an additional library. At first I ran it from SSH, and it was working properly. After that, I was running some test directly on the given computer, and it also worked normally. At this point, I'm trying to make it work on the specific computer, however, with no display, and it should run automatically (I did it with crontab earlier, and I planned to use it again). So I reused an old script below.
#!/bin/bash
if [ ps x $UID | grep -v grep | grep -c `java` ]; then # process fut, nem kell semmi
exit 0;
else
# export DISPLAY=:0;
exec sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/foo/bar.jar';
fi
pidof java
if [[ $? -ne 0 ]] ; then
#export DISPLAY=:0
exec sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/foo/bar.jar' &
fi
Which worked correctly for an another program before (that one had GUI, this one does not). I can still run it from SSH with the command behind the exec, but when I try to use shell script, it gives
-bash: [: missing `]'
And also the standard error message that I use java in the wrong way, even tough directly it still works
sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/foo/bar.jar'
The script supposed to check if java is running, and restarting my program if it doesn't, in crontab and init.d. However, at this point it does nothing at all. (And it should be able to read from console, right? I cannot check it, since it doesn't run without a display.)
The other programs worked correctly, however they just run java -jar "file", without any additional parameters.
EDIT:
Sep 18 14:03:38 raspberrypi systemd[1]: [/etc/systemd/system/rxtxcomm.service:4] Executable path is not absolute, ignoring: java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar "/home/pi/forgokapu/dist/forgokapu.jar"
Something is fishy. Trying to run with absolute java...
Ok, now it seems to work, except java is throwing error messages, because it's not able to read a new line when it is not supposed to do so. It requires an investigation, but in the Java code. Thanks for your help!
I tried to use the file for systemd you wrote, (with the necessary alterations of course), but it still does not work. The journalctl says there are no journal files, and does not do anything until I cancel it with ctrl+c. I've already tried restarting the system.
– kry Sep 18 '17 at 13:17User=someuser
directive in the service file. Sudo expect a tty to be present which is not true for things run under systemd. The service files should also have the default permissions of 0644, there is no need for them to be executable as they are just config. – Michael Daffin Sep 18 '17 at 15:56systemctl status <service>
to get more information about the process status. – Michael Daffin Sep 18 '17 at 16:03