Reputation: 1764
I just started using Ansible and I am having trouble running a server.
I have a server which can be started using java -jar target/server-1.0-SNAPSHOT.jar
. However, this will start the server and keep running forever displaying output, so Ansible never finishes.
This is what I tried that never finishes:
- name: Start server
command: chdir=~/server java -jar target/server-1.0-SNAPSHOT.jar
What is the proper way to do this?
Upvotes: 4
Views: 2281
Reputation: 1136
Put that in a PID and send the output to nohup.
Something like this:
nohup java -jar target/server-1.0-SNAPSHOT.jar &
In your playbook:
If you want kill the process kill -9 #numerofpid.
Upvotes: 0
Reputation: 5350
As @Petro026 suggested, your choices are asynchronous task or creating a service.
I would strongly suggest against the asynchronous task approach. It's a very fragile solution:
Your best bet is to create a service for it, and probably the easiest approach for it would involve using a process control system like supervisord, which is supported by ansible.
From the supervisor docs:
Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.
Upvotes: 2
Reputation: 1309
Either create a service, as @udondan suggests, or use an asynchronous task to launch your server. http://docs.ansible.com/ansible/playbooks_async.html
Upvotes: 3