How do I create a daemon for *nix machines that starts up when the OS boots up? On MacOS, I am guessing the best option would be a brew service. What are the best options for linux?

closed as too broad by Michael Homer, Romeo Ninov, Anthon, Jeff Schaller, Rui F Ribeiro Jul 13 '17 at 12:04

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Which Linux distro? – Emmanuel Rosa Jul 12 '17 at 1:19
  • all desktop/developer flavors - I have to write some generic, library code, but it doesn't need to run on servers, just desktop machines that developers use. – Alexander Mills Jul 12 '17 at 19:10
  • I don't appreciate a downvote without a comment mentioning why :) such that I can potentially rephrase the question, etc. – Alexander Mills Jul 12 '17 at 19:12
  • 1
    That can happen when the impression is that the OP didn't do enough research/thinking, which frankly is what it looks like, no offense. To Nick's point, it's the "init system" that you code daemons for. It's impossible to write daemons for "all" anything because there's really no standard init system. So you first need to review each distro you need to support and check which init system it uses. Note: by daemon I really mean the init system specific component; which typically delegates to the real daemon. – Emmanuel Rosa Jul 12 '17 at 19:22
  • 1
    It's good that you did some Google searches, but what I'm saying is, that fact is not apparent in your question. I'm not saying that's why you got a down-vote, but it's quite possible given that: knowledge is acquired through effort. And since you can't pay knowledge here, the best "thank you" is to demonstrate that you seek to earn expertise. And you do that by showing you've done your homework. It didn't happen to you, but questions like this typically get a response of "And what have you done so far?" The "Software Recommendations" site is for when seeking new solutions. – Emmanuel Rosa Jul 12 '17 at 21:33

It depends on the distro, but many distros nowadays are moving towards systemd as the init service. For that case, you'd create a systemd service: see the systemd.directives(7) manpage, the systemd homepage and google for "systemd service example". Here's one example (see example 9.18 in this section) which starts emacs as a daemon :

Description=Emacs: the extensible, self-documenting text editor

ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"


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