Score:0

How to start a background process when the server starts and keep it alive

cn flag

Note: I wasn't sure if I should ask this here, stack overflow, or ???

I'm migrating a Ruby on Rails app from Heroku to AWS. The server architecture is fairly vanilla:

  • Database
  • Web Server
  • Worker Server

The Database and Web Server have been successfully migrated to AWS. The Worker Server is on deck.

FWIW: The aws Web Server is running Ubuntu 20.x w/ Passenger / nginx as the http server.

I'm now working on migrating the Worker, which is deployed with the exact same code as the Web Server. The only difference is the Worker is not publicly accessible and uses the Ruby Gem delayed_job to process background requests.

Worker Server

  • Worker server was created from an ami based off the web server.
  • Removed the nginx server config that was an artifact from the web server.

Questions

  1. How do I setup the Worker server to automatically spin up and begin running the background jobs when the server starts?

  2. How do I keep the worker process alive if it happens to fault and shutdown?

In Heroku, the command line starting the worker server:

bundle exec rake jobs:work

After spinning up the Worker server, I can run the above command and the worker process runs great. Just need to figure out how to have the worker process run non-interactively.

FYI: I come from a Windows/.NET background. The Linux / Ruby / Rails environment is still fairly new to me.

user535733 avatar
cn flag
Look up a primer on systemd services.
in flag
This question [has an answer on StackOverflow](https://stackoverflow.com/a/39720001/14952832)
cn flag
@matigo - I have gone through the question you referenced; as well as about 50 others on SO. The question/answer you linked to may work, but it doesn't appear to be a long-term solution if the process fails. I've actually spent about a day researching this and haven't found a good canonical answer. I'm looking at systemd services, and that seems like a good path forward at first glance.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.