Autostart JavaFX Application on RaspberryPi - linux

I programmed a JavaFX application which runs on a "Raspberry Pi" (a small ARM based Linux Computer). The OS on the "Pi" is "Raspbian" (a Debian Linux for Raspberry Pi). I installed JDK8 on Raspbian to run graphic JavaFX Application without X-Server. This all works fine :) I can start the Application by entering the following command:
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte
When the application starts it takes full control over mouse an keyboard, so there is no way back into console, but this doesent maters because it is just a monitoring system an i am able to shut the mashine down over ssh.
I now want to start the application directly after booting, so that there is no need for entering username ,passwort and starting the application.
The mashine does nothing else just running the app (of course there runs a ftp, ssh deamon for making updating the app posible)
Please tell me step by step, because i dont work with Linux for a long time.
Thank you very much.

CMD
cd /etc/init.d
sudo nano leitwarte
Enter the following
#! /bin/sh
# /etc/init.d/leitwarte
touch /var/lock/leitwarte
case "$1" in
start)
echo "Starting Leitwarte ... "
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte > /dev/null &
;;
stop)
echo "Killing Leitwarte ..."
killall java
;;
*)
echo "Usage: /etc/init.d/leitwarte {start|stop}"
exit 1
;;
esac
exit 0
then
chmod 755 leitwarte
update-rc.d leitwarte defaults
DONE

I solved this problem
When the application starts it takes full control over mouse an
keyboard, so there is no way back into console
by adding quotes ("") and by giving -Djavafx.platform=gtk for DEFAULT_JVM_OPTS.
For example in my case I replaced this code:
DEFAULT_JVM_OPTS=-XX:+UseG1GC -Dmode=prod_w_updates
to this:
DEFAULT_JVM_OPTS="-XX:+UseG1GC -Dmode=prod_w_updates -Djavafx.platform=gtk"
Hope, it will help

Related

Executing bash script on wakeup

Since some time I have a Prolbem with my Linux distribution (Kubuntu 18.04). Every time my linux comes back from standby modus the touchpad is not working properly anymore (can't grab and drag files or other objects).
I already found a solution for my Problem:
modprobe psmouse -r
modprobe psmouse
This code does solve the problem. However, after this the rightclick area which I always disable at sartup is enabled again.
I have a script that runs on startup which executes the following:
synclient RightButtonAreaLeft=0
synclient RightButtonAreaTop=0
What I am now trying to do, is to write a script that runs whenever the system is waking up form standby modus.
I wrote the script like this:
#!/bin/bash
exec 1> /home/luc/Schreibtisch/update.log 2>&1
set -x
case $1/$2 in
pre/*)
echo "Going to $2..."
# Place your pre suspend commands here, or `exit 0`
# if no pre suspend action required
exit 0
;;
post/*)
echo "Waking up from $2..."
sh /home/luc/Schreibtisch/test.sh
sh /home/luc/Schreibtisch/test2.sh
;;
esac
Where test.sh runs the modprobe commands and test2.sh runs the synclient commands.
After going to standby modus and waking up again I'm getting the following log:
+ case $1/$2 in
+ echo 'Waking up from suspend...'
Waking up from suspend...
+ sh /home/luc/Schreibtisch/test.sh
+ sh /home/luc/Schreibtisch/test2.sh
Failed to connect to X Server.
Failed to connect to X Server.
And the grabing and draging of the files works perfectly but the rightclick is still enabled.
My question is now if it is possible to execute the synclient commands after the X Server is ready?
Kind regards
Pepsilon
It looks like i have found a workaround for the problem of the touchpad not working properly after wakeup.
In my /etc/modprobe.d/blacklist.conf the module i2c_i801 was blacklisted.
After removing this module form the blacklist my touchpad now works fine after standby mode.

ShellScript for Killing and Starting Program every 5hrs

I have a raspberry pi and I want to start a java application for 5 hours, kill it and start it again.
Because I need to login via SSH I thought it was clever to run the java application within screen (because I want to do other things while the program is running).
So without the script I started with:
screen -S java
java -jar program.jar
And then I send the Keys [CTRL] + [A] + [D] to detach.
Now I need to write this in shell.
I started with:
#!/bin/bash
#Check if app runs right now
OUTPUT="$(screen -ls)"
if [[ $OUTPUT == *"javaapp"* ]]
then
#Say that the javaapp is currently running
echo "javaapp is up!";
#Kill the javaapp!
screen -d javaapp #Does not work
fi
#Start it again
But it does not work :/
And I don't even know how to fix it since it's the first script I am trying to write. Is there anyone who can help me?
(Oh: And I would run the shellscript every 5hrs via. cronjob)
Thanks in advance!
Try this trick via cron:
#!/bin/bash
if [[ -f /opt/javaapp.pid ]]
kill -9 `cat /opt/javaapp.pid`
rm /opt/javaapp.pid
fi
nohup java -jar program.jar > /opt/javaapp.log 2>&1&
echo $! > /opt/javaapp.pid
Edit: I'm not sure it works with java apps though, or with apps that tend to fork and spawn other processes. Watch out for zombies if you try this.
Also, if anybody knows a better way, please share it. Now I'm curious.

How to launch a desktop application in Ubuntu/Debian on system startup

I've done a hell lot of research, all of which say something like "add your script in init.d" "link symbol in rc*.d", but I still cannot understand without an example. I've tried many times but all failed.
My problem is as simple as:
How to launch /usr/bin/gedit on Ubuntu/Debian (desktop version) startup (after user login)?
Any help is greatly appreciated!
Edit: So here is what I have done so far:
1) I added a new line /usr/bin/gedit before exit 0 in /etc/rc.local, and ran sudo chmod a+x /etc/rc.local. However, when I reboot and logged in to the desktop, nothing happened.
2) (Having clear the new line added in /etc/rc.local) I created a script /etc/init.d/gedit, of which the content is:
case "$1" in
start)
/usr/bin/gedit
;;
stop)
killall gedit
;;
restart)
$0 stop
sleep 5
$0 start
;;
reload|force-reload)
esac
And then I ran sudo chmod a+x /etc/init.d/gedit. Next, I ran sudo update-rc.d gedit defaults, which gave me the following output:
update-rc.d: warning: /etc/init.d/gedit missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScript>
Adding system startup for /etc/init.d/gedit ...
/etc/rc0.d/K20gedit -> ../init.d/gedit
/etc/rc1.d/K20gedit -> ../init.d/gedit
/etc/rc6.d/K20gedit -> ../init.d/gedit
/etc/rc2.d/S20gedit -> ../init.d/gedit
/etc/rc3.d/S20gedit -> ../init.d/gedit
/etc/rc4.d/S20gedit -> ../init.d/gedit
/etc/rc5.d/S20gedit -> ../init.d/gedit
Then I tried invoke-rc.d gedit start, and gedit popped up as intended. However, when I reboot and logged in to the desktop, again nothing happened.
P.S. Setting up in Startup Applications of Ubuntu does work, but what I want is actually a more general approach which can be used when distributing my own software package.
Did you try to add gedit at System > Preferences > Startup Applications?
Also look here: https://help.ubuntu.com/community/AddingProgramToSessionStartup
This might be of help
Running a Program at Linux Startup

autolaunch of application in ubuntu

I created the script file -
#!/bin/sh
echo "my application is here"
./helloworld # helloworld is our application
after creating the script file i copied it in init.d
I gave the command chmod +x /etc/init.d/vcc_app (vcc_app is the name of script which I have created)
Then I gave the command ln -s /etc/init.d/vcc_app /etc/rc.d/vcc_app (rc.d is the run level directory)
But when i reboot the board my application is not executed automatically. Can anyone help me out?
Scripts that are in /etc/init.d need to be LSB-compliant.
If you simply want to automatically run commands at the end of the boot process, try placing them in /etc/rc.local instead.
Not all linux systems use the same init daemon (ubuntu uses upstart: http://upstart.ubuntu.com/getting-started.html), but they all use start and stop functions in the script. Other common functions are status and restart, but again, there is no true across the board standard. Eg:
!#/bin/sh
start () {
echo "application started";
./helloworld # you should use an absolute path here instead of ./
}
stop () {
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage start|stop";
esac
exit $?
The last bit is a switch based on the first command line arg, since init will invoke the script myrcscript start.
In order to use stop() (and the also often useful restart()) you need to keep, or be able to get, the pid of the process launched by start(); sometimes this is done with a little "pid file" in /tmp (text file containing the pid, eg, /tmp/myscript.pid created in start()).
The "upstart" init daemon used on Ubuntu has its own specific features, but unless you need to use them, just keep it stop/start minimal and it will (probably) work anywhere.

commands at ubuntu shutdown

How to execute one or more commands and scripts when ubuntu shutdown? Is there any script like /etc/profile and ~/.bashrc at system starting?
I know linux shutdown may have many causes, in addition to dealing with the kill signal, where can I get for this reason?
Is there any script like /etc/profile and ~/.bashrc at system starting?
The SysV Init scripts (/etc/init.d/*) are invoked at startup. A trivial/easy way to invoke some activity at system startup is to put it into /etc/init.d/local (/etc/rc.local for some other distros). See also: RcLocalHowto.
How to execute one or more commands and scripts when ubuntu shutdown?
It sounds as if you want to create a real init script that gets started on entering runlevels X-Z and stopped on exiting them. See also: UbuntuBootupHowto.
I know linux shutdown may have many causes, in addition to dealing with the kill signal, where can I get for this reason?
To do this noninteractively is not straightforward. You can grep through the system logs, looking for indications from shutdown.
There is a ~/.bash_logout file that executes when you log out of Ubuntu 11.04
I am not sure, but assume there is a similar script in 10.04
Hope this helps.
You can put your script in /etc/rc0.d (for halt) and /etc/rc6.d/ (for reboot). Make sure script has executable permission.
There is differents run level :
* 0 System Halt
* 1 Single user
* 2 Full multi-user mode (Default)
* 3-5 Same as 2
* 6 System Reboot
Run level 0 is the system halt condition. When run level 0 is reached all scripts in /etc/rc0.d are exectute.
Run level 6 is used to signal system reboot. This is the same as run level 0 except a reboot is issued at the end of the sequence instead of a power off.
If you want to execute your script on hibernate or on sleep, put your script in /etc/pm/sleep.d/
This is a example of script :
#!/bin/sh
WLANSTATUS=`cat /sys/class/ieee80211/phy*/rfkill*/state`
test -z $WLANSTATUS && exit 1
case $1 in
hibernate)
# Do something before hibernate
;;
suspend)
# Do something before sleep
;;
thaw)
# Do something after hibernate
;;
resume)
# Do something after sleep
if [ $WLANSTATUS = 0 ]; then
echo 0 > /sys/devices/platform/asus_laptop/wlan
elif [ $WLANSTATUS = 1 ]; then
echo 1 > /sys/devices/platform/asus_laptop/wlan
fi
;;
*) echo "somebody is calling me totally wrong."
;;
esac
Have fun !

Resources