For context, I'm trying to run this in a rails environment.
Basically, I have a rails app, and on a certain controller#action, a job will be spun up with ActiveJob, and in that job is where I want to run a shell script that I wrote.
The shell script just clones another repo containing a rails app into a different directory on the server, installs all required deps, and then starts the server.
So, that means at some point, there will be a parent app and a child app (or children apps)
This is what my perform
method looks in the job:
def perform(resource)
fork { exec("#{Rails.root.to_s}/my_shell_script.sh #{resource.app_name}") }
end
and this almost works, but the process isn't separated because fork
inherits the parents terminal. So the child app's rails server will get started, but when I go to my terminal window for the parent app where rails s
was ran, not only do I see logs for the child app, but when i kill the parent's server with Ctrl-c
the child's server also get's killed.
I see two sets of closing messages because both servers are getting killed.
^C- Gracefully stopping, waiting for requests to finish
- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2021-02-06 14:47:46 -0700 ===
- Goodbye!
=== puma shutdown: 2021-02-06 14:47:46 -0700 ===
- Goodbye!
Exiting
Exiting
So my question is how do i separate these? I do not want to see the child app's logs in my server logs and if I kill the parent app's server, I want the child apps to continue to run. Basically, I want them to be completely separated.
What else I've tried
I tried using the system
method since it creates a sub shell, but it's still not a completely separate process.
def perform(resource)
fork do
system("#{Rails.root.to_s}/gensite.sh #{resource.app_name}")
end
end