I am trying to set up a Thin Ruby application server on my Ubuntu VPS. I have created a specific account, installed rbenv under it along with all gems.

I am looking for a convenient way to obtain the following objectives:

  1. Run my Thin Rack application under my non-privileged user account.
  2. Make the application run as a daemon
  3. Have the daemon run automatically whenever the system boots
  4. Make the daemon restartable
  5. Make the application accessible to Nginx through a unix domain socket.

Objective two and three are the trickiest. Is it possible to define scripts for a user to be run as that user whenever the system boots?

  • The short answer is YES. I do assume that you have and you WILL need support from your server admin to do this. – mdpc Jun 12 '13 at 19:58
  • 1
    I don't have any server admin to consult. I am trying to become my own server admin. – Niels B. Jun 12 '13 at 20:33
  • are you implying you have or have NOT root access? – mdpc Jun 12 '13 at 20:44
  • 1
    I do have root access to my VPS, but I don't want to litter the root account with rbenv, ruby interpreters and gems. And I want the non-privileged thin account to be able to restart the daemons. If I use init.d, it seems the thin account needs to be a sudoer to have its way. – Niels B. Jun 12 '13 at 20:50
up vote 5 down vote accepted

For starting at boot time add a line to your users crontab file (using crontab -e):

@reboot /path/to/your/script with parameters

The actual contents of that script vary with your needs. It might just start the daemon, or it might start a somewhat more intelligent agent that you pass a configuration. That way you can have your service automatically restarted if it for some reason dies unexpectedly.

  • It is tempting to me to give +1 because I didn't know that is possible. But somehow I don't think that this is a good idea for managing daemons... – Hauke Laging Jun 12 '13 at 19:40
  • actually it is possible, with a process manager I have done so on various constellations. It is IMHO one of the nicer ways to start things that do not need root permissions at any time (compared to starting from /etc/init.d) – Anthon Jun 12 '13 at 19:41
  • This is an interesting option that I am experimenting with now. It looks promising. – Niels B. Jun 12 '13 at 20:34
  • 1
    I confirm that it does the job. Thanks. – Niels B. Jun 12 '13 at 20:44
  • @NielsB. How did it work for you? I just tried this and confirmed that @reboot only works for root: unix.stackexchange.com/a/109805/28712 Thanks. – Withheld Jan 17 '14 at 18:44

You just need adapt the start script template of your distro. I am sure everyone has such templates.

If you use systemd then you can give the user to be used in the unit file.

If you use the old init scripts then the script probably uses startproc or start_daemon. You can add parameters to these wrappers for configuring the user ID.

Or you make the program SUID (not for root but the intended user) and restrict the execution rights to trusted users (or root only).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.