Reputation: 1235
I'm currently experimenting with an java "server application", which is supposed to run in the background on a ubuntu server.
The current system isn't perfect, and that's why I want to work on a new system...
The goal is to run the java application in the background (via nohup or a linux service) and still be able to execute commands (stop status etc) to control the behaviour of this app.
I thought of creating a server socket, which is listening on localhost, which enables me to write an java "client" app which sends commands to the server and terminates afterwards...
My question is, if it is possible to avoid having such a "client" app.
It would be ideal, if i just had a way to send a string to the server using bash only (includes tools like curl for example).
Is that possible?
And is my planned system a good plan?
Any help is appreciated!
Upvotes: 0
Views: 436
Reputation: 51
And is my planned system a good plan?
I don't know the scope of your application, but if you are rewriting the code, consider using Spring Boot It is so simple framework, can produce a command line app easily and can be deployed as a linux service
so you will be able to run commands like
service xyz start
service xyz stop
service xyz status
Upvotes: 1
Reputation: 178
You need a protocol for your service.
As you said, "how about use curl"? sure , you can create a web service, with rest api.
a web service is very easy, if you just wanna to have some simple io, you can read https://www.playframework.com/ , and use it in 30 minutes (25 minutes to download the pacakges and 5 minutes to read the doc)
Another method is using "nc" as "client", a simple introduction page can be found here: http://man.openbsd.org/OpenBSD-current/man1/nc.1
you can write
echo "your command" | nc localhost 6666
to send a socket request to server.
However, you should define the protocol by yourself.
Upvotes: 3