2

I have a case where I want to start Spring Scheduled job from Linux Terminal. Is there some way to trigger it from the terminal?

For example can I use Spring Shell to start the Scheduled job?

user51
  • 8,843
  • 21
  • 79
  • 158
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • This question is too vague. What did you try? What does your project and Scheduled job look like? Do you want to do this from the terminal on the server it's running on or any terminal? – DCTID Apr 10 '19 at 23:36
  • My Java application is running on Wildly server. I would like from Linux terminal to start and stop Scheduled job. – Peter Penzov Apr 11 '19 at 05:24

1 Answers1

0

can I use Spring Shell to start the Scheduled job?

Yes, theoretically you can (you can see a simple example here), but I am not sure it will fit your usecase if an application server is involved - invoking spring shell commands outside of the running shell process is more complex.

I would look into exposing start/stop functionality to Spring Scheduled Jobs as a REST api. You can still execute it from command line using curl and you can implement some authentication protocol around spring-security (or not if it's not needed).

Just wrap your start/stop methods with controller methods and expose those as REST api.

hovanessyan
  • 30,580
  • 6
  • 55
  • 83
  • REST API is not a good option because I want strong security. What if I use some internal JVM communication protocol for communication? Is there something available? – Peter Penzov Apr 11 '19 at 14:54
  • You can have the endpoints protected by spring security (e.g. OAuth2), so before invoking the endpoints you will have to make a call, passing credentials, to acquire an access token and use the token in subsequent calls when invoking the commands. – hovanessyan Apr 11 '19 at 14:58
  • I am not aware of internal JVM communication protocols. Maybe you're looking for RMI based solution. – hovanessyan Apr 11 '19 at 14:59