JAVA - Raspberry-pi - Application as a service who start then stop immediately

家住魔仙堡 提交于 2019-12-04 05:34:43

问题


I need to start a Java app on raspberry's startup, but i can't figure how?!

  • I've retreive the PbxMan's script to run it as a service : https://stackoverflow.com/a/21283530/5066919

  • I've made a simple script that launch the app in background

  • I've pushed it in a crontab at reboot...

I play a sound on the first line of the main and in the addShutdownHook(). So i can hear that each time, the app start then stop immediately...

Of course i don't have this problem when I launch it in CLI! :@


回答1:


Problem solved,

I post what i've found if some one have the same ;)

My app run a Thread, waiting for keyboards entries to run live tests and shutdown app when this loop is break with 'q',

while( scanner.hasNext() ){
  ...
}

"This method may block while waiting for input to scan" say the JavaDoc, ... may block...

In a case of a service, or when you put the app in background, "has next" don't block, so my app thinks 'q' was send and shutdown.

I've just added a starting parameter to use app asService or not, which disable or not this waiting loop..!

That's all folk!



来源:https://stackoverflow.com/questions/33178619/java-raspberry-pi-application-as-a-service-who-start-then-stop-immediately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!