G
G
green_tree2015-04-05 12:16:32
linux
green_tree, 2015-04-05 12:16:32

How to start thin server on Ubuntu boot?

The server has Ubuntu 14.04 installed, Ruby is installed using rvm as a user
. For thin, I created a config using thin config -C
the server starts as a user thin start --all /etc/thin
. But how to add it to autorun?
added:
ok, I'll put the question differently:
how to start any of the servers offered to choose from in autorun, when all this is installed in ~/.rvm, and /etc/rc.local starts the whole thing from root
all manuals suggest installing these servers along with nginx,
and nginx is already on the server and recompiling it is not an option
. After digging with passenger, I come to the same problem:
I can run it from under the user, but I can’t force it to start at system startup

passenger start --daemonize --user <user> -R config.ru

more added:
app not rails, i use sinatra
just getting started with ruby

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Vsk, 2015-04-05
@viktorvsk

habrahabr.ru/post/120368
https://www.digitalocean.com/community/tutorials/h...
etc.
+ mmonit.com/monit (also like https://github.com/burke/zeus )
And yes, you don't need thin in production. Unicorn, Puma, Passenger, Mongrel...
UPDATE :
Why recompile nginx? Don't have access to nginx config?
Usually they do this:
- There is a web server (apache, nginx)
- There is an application server (puma, unicorn ...)
- The web server works with the application server through a pid file and a socket (unix proxy)
- Monitor the operation of all demons (application/web server) should be something like Monit or God (this is a direct answer to your question "How to add to autostart")
- Also, when there are a lot of processes necessary for the application to work (workers, clocks ...), you can look towards Foreman.
Whether you use Rails or Sinatra doesn't matter. In general, it doesn't even matter if it's python or ruby.
A simple example of .monit cofing to track application performance:

check process puma
  with pidfile /home/user/my_app/shared/tmp/pids/puma.pid
  start program = "/bin/su - user -c 'cd /home/user/my_app/current && BUNDLE_GEMFILE=/home/user/my_app/current/Gemfile bundle exec puma -C config/puma.rb'"
  stop program  = "/bin/su - user -c 'cd /home/user/my_app/current/ && kill -9 $(cat /home/user/my_app/shared/tmp/pids/puma.pid) && rm -f /home/user/my_app/shared/tmp/pids/puma.pid; exit 0;'"
  group puma

N
Nikolai Markov, 2015-04-05
@manameiz

All system service scripts are stored in /etc/init.d.
*nix has different runlevels, each of which works differently ( read more here ).
Each runlevel has its own directory /etc/rcN.d where N is the runlevel. These folders contain scripts that are executed when the system transitions to the appropriate runlevel and are usually just links to scripts in /etc/init.d.
In any system, there are at least two runlevels: 1) responsible for the normal boot of the system and 2) responsible for shutting down.
Do you need to load some script immediately at system startup. You must add it first to /etc/init.d and second to the appropriate rcN.d folder (link).
Adding a script to startup is done as follows
Cancel previous actions
But you don't need all this crap. You have passenger, which is like nginx, only you have to compile it yourself. And running it as root is dangerous and unnecessary (which you yourself already know as you can see). You either need to write your own script for startup (this is such a new trendy thing for running init scripts instead of the old init). Or take another similar tool like runit, which is easier to write scripts on. But here, too, there are some nuances, because. for example, in runit it is necessary that all logs be output to stdout. But at the same time, he knows how to restart the fallen processes himself and he has a web-admin panel where you can see the logs, stop / start services.
In general, it’s not in vain that in all the manuals for deploying applications nothing is said about how to make autoloading, because you don’t need to do it. If something happens to your server (ruby will gobble up all the memory on the server and so you won’t even be able to connect to it via ssh), it will be worse for you because you once decided that you definitely need autorun. You reboot servers 5 times a day, and the reboot command is easy for you to type, and running rails with handles is not comme il faut.
UPD: it was necessary to post with tags on linux and administration. ruby has nothing to do with this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question