Situation :
I have jar file on server PC (PC act as server), a.jar, which will be running infinite loop to listen for TCPIP connection from client PC. When connection has been made, client PC can send a zip file to server PC, a.jar will unzip it and execute a script with that zip, which will start another full screen display java file, b.jar.
a.jar will also trying to run b.jar during bootup, if b.jar already exist.
Approach 1:
I wrote a script in /etc/init.d/ to start a.jar, as it’s infinite loop, the system hang forever during bootup (in terminal screen, can’t even get into GUI). I have to boot into single user mode to remove that script in order to boot up normally.
Approach 2:
When I changed the script to run a.jar as a daemon, it runs normally, listen for connection, I can connect to the server pc and send zip file.
Problem:
- b.jar is not executed even when execution permission and files are all correctly set.
- After I sent a zip file, b.jar is executed (because it is connected to a device and that device is activated). But the full screen display is not shown like it did when executed via terminal.
Reasons of doing so
It may seems a bit complicated, but because b.jar will be constantly updated and it has to be auto start when after update, thus I use a.jar to unzip and execute new version fo b.jar.
And b.jar is required to run as root as it needs to access serial port.
(Server pc is required to be automated, thus it is required to start b.jar during startup and remotely controlled)
Question
May I know is there any better way of doing this? Or what did I do wrong? Can someone show me a better script to start it during startup?
Approach 1 should work but you must run the java process in the background by adding
&to the command.But there are better solutions to run java apps as a deamon. The above can be considered as a quick fix.