2

How do I let server's users create their own daemons? They should auto-start on boot and otherwise behave just like regular daemons but with lower privileges overall.

I remember I saw a tool that let a user create a file in format similar to a crontab one with his wishes. The tool made sure the programs from the file would be running at all times. But now just couldn't find it's name.

nohup ./app & just doesn't cut because it is won't autostart and the app won't restart automatically. Same as @reboot in user's crontab.

The thing is that I don't want to reinvent a wheel. If there is something that does what I want in full, I would use it. And only if there is nothing, I would fall back to a hand-made approach.

(I am using Debian stable, so I don't have systemd yet, as far as I understand.)

  • "I remember I saw a tool that let a user create a file in format similar to a crontab one" -- you could use crontab for individual users here (see man crontab); just schedule a check to see if the process is running every minute or so. Note that nohup ./app & does not really daemonize a process -- see here for a better idea. – goldilocks Mar 13 '14 at 8:50
  • 1
    " Everyone has his own daemon " old popular thoughts – Kiwy Mar 13 '14 at 8:56
  • @goldilocks sure, if I wouldn't find anything feasible, sure I'll make up something to manage clients' processes. My question is that is there is something already done on the subject. – sanmai Mar 14 '14 at 1:38
3

Make sure the home directories for the users are accessible early (before cron starts) and have them make an entry in crontab:

@reboot /home/username/bin/start_at_boot

This is a standard feature of a cron daemon which should be on your Debian system.

The start_at_boot script can start the users daemons directly, or start some tool that manages and watches the users' daemons (the configuration for which can be under the control of the individual user). I have used several packages for this, e.g. procer that comes with mongrel2. But now tend to use supervisor (being in python makes it easier to understand and extend once the need for that arises).

For other scheduling (or kicking a dormant daemon into activity) the users can make normal entries in their own crontab.

| improve this answer | |
  • @reboot option won't restart a failed process. And yes, I am looking for a tool that manages and watches the users` daemons you're mentioning. – sanmai Mar 14 '14 at 1:34
  • @sanmai I extended the answer, procer is real simple but not much used. supervisor is more powerful, but still simple to maintain. Use its -c option in the crontab to read a per user specific config file, or use a system wide script that does so and tell the users to put that script in their crontab after @reboot – Anthon Mar 14 '14 at 6:30
  • I ended up using supervisor, still not allowing users add their own daemon on their own - they'll need to ask an administrator. – sanmai Dec 15 '16 at 2:27
2

If you are on systemd, it's trivial, because systemd doesn't require the "fork/exec/pidfile" formalism. You just create a service file and systemd takes care of starting the process, restarting a crashed instance and so on. You can also easily allow users to create their own service files (or even run them not as root but as their own user - if that's useful somehow).

On system V initscripts, the most standard way is to start them in /etc/rc.local. Automatic restarting doesn't usually work even for system daemons! You could however write a shell wrapper that runs the process in a loop (possibly with a sleep 1 to avoid problems with constantly failing processes). However in this system, you have very little control over individual daemons.

You could also just create initscripts and put them in a special user-accessible directory in rc.d and modify the service starting system.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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