1

I know this question has been asked and answered many times, and I've read every Q&A on this subject, but I am still totally confused.

I am a Ruby noob, trying to get a Ruby app built (by someone else) with Sinatra and Strava to run as a service in Linux. It's a gateway that handles syncing Transifex language translations with github. I have forked the original code and fixed a number of bugs, to the point that it now works well. My repo is here:

https://github.com/Fabrik/txgh

The original docs only showed how to run it from the command line using "bundle exec rackup". I tried daemonizing by simply backgrounding the bundle command from rc.local, but that doesn't work. I'm not religious about using bundle, as this is running on a dedicated little Amazon ECS instance, and I won't be installing any other Ruby on it, so no danger of versioning problems. So a solution which doesn't use bundle is fine.

I'm guessing that the answer is probably to use the 'daemons' gem, and I have tried, but am getting nowhere.

If anyone could take a look at that github repo, and point me in the right direction, I would greatly appreciate it. I swear I've given this my best shot, and spent many hours googling and experimenting!

UPDATE

Since posting this, the Transifex authors have picked up development of this txgh gateway, merged the changes I needed, and tweaked it to be able to run on Heraku. Anyone needing to gateway between github and Transifex should go here:

A server that integrates Transifex with GitHub

1 Answers1

0

EDIT

Although I doubt this is a very good answer, it's a great way to test what's happening...

I believe that once your container's main process (the Amazon instance) is done, there's a shutdown and cleanup process that kills the service, putting it to "sleep" until it's needed again.

I assume this is actually a "feature" related to the "elastic" aspect of the system, much like Heroku shutting down Dynos dynamically when "auto-scaling".

To test this theory, once the service is setup to run in the background, start a different application in the foreground (so that the main process is still active and hangs).

i.e.:

# do whatever you need to setup the service, i.e.:
bundle exec rackup &
# hang the main process for infinity:
ruby -e "sleep"

If your service doesn't shutdown the same way it did before, I think it's safe to say that the balme lies with Amazon shutting you down.

I expect your service's shutdown to takes a longer amount of time when the main process is "busy". Still, I assume all services shut down when not receiving requests, so I doubt any "elastic" container lives forever.

original answer, when I still hadn't understood the question

I might not have understood your question properly... but...

you can probably use the & sign at the end of the command to run a process in the background (it's a unix/linux OS thing).

try:

bundle exec rackup &

Another issue is ... Why? Why not let the server run as the main Docker container service? Why demonize the application?

Myst
  • 18,516
  • 2
  • 45
  • 67
  • I tried backgrounding it, as mentioned in my post, and at the end of the README in the repo, with ... – Hugh Messenger Nov 06 '15 at 08:50
  • (Ooops, didin't know about the 5 minute edit limit. My first StackOverflow question.) su - ec2-user -c 'cd /home/ec2-user/txgh && /home/ec2-user/bin/bundle exec rackup &' ... and that runs ... for a few minutes. No idea what is killing it, it leaves no spoor. I've been a UNIX admin for about 30 years, and it's a head scratcher. Hence needing to work out a way of truly daemonizing it with something like the daemons gem. I'm not using Docker, this is just a simple ECS t2-micro instance. – Hugh Messenger Nov 06 '15 at 08:57
  • Well, you are not running a server, you are running a docker container. I assume that once the Docker container's main process quotes, there's a shutdown and cleanup process that kills the service. Why run it in the background? it's super rare to do so. – Myst Nov 06 '15 at 14:46
  • Nope, no Docker. It's a vanilla EC2 t2.micro Linux instance. – Hugh Messenger Nov 08 '15 at 04:11
  • Just a heads up, the confusion re Docker is because you kept referring to ECS when I think you meant EC2. Oh Amazon and their naming :) – Glenn Gillen Nov 11 '15 at 01:33
  • @GlennGillen - Lol... yes, I never got their naming :-p – Myst Nov 11 '15 at 01:51
  • Yeah, sorry, I get ACS (Acronym Fatigue Syndrome) dealing with Amazon. I'll guess I'll accept the answer, even though I did say in my question I was backgrounding already, as it looks like this is the only way to do it running in a simple server instance. – Hugh Messenger Nov 25 '15 at 03:27
  • Hugh, thank's for the feedback. I really hope I could have helped more. By the way, the ACS joke made me lough out loud in the middle of the coffee-shop... some people were staring at me... :-D ... but it's just so true! Amazon's acronyms can drive me insane. – Myst Nov 25 '15 at 09:43