0

I put my plist in /Library/LaunchAgents and my exexutive program in /usr/libexec and daemon statrs when system startup . But this daemon is owned by user . I try to put my plist in /Library/LauchDaemons but it's not working and daemon doesn't starts in system startup

I want to know how to make a daemon launch as root when system starts up.What additional jobs should I do to make a daemon launch as root ? Thanks in advance!

  • `launchd` does exactly what you need. –  Mar 28 '13 at 07:01
  • What do you mean? What should I do? I can start a daemon with launchctl load coomand oon terminal . But the daemon lifetime is not over a restart . After the system is rebooted daemon is not launching. –  Mar 28 '13 at 07:05

2 Answers2

4

After you put plist in /Library/LaunchDaemons you need to run command sudo launchctl load -w /Library/LaunchDaemons/your.plist
See man launchctl for the -w flag (it does exactly what you need)
Edit: did you set the RunAtLoad key to true in your plist?
Edit2: I forgot, RunAtLoad has no influence on autolaunch, it is all bout Disabled key.

cody
  • 156
  • 3
  • I try this but give me this error : launchctl: Dubious ownership on file (skipping): /Library/LaunchDaemons/com.apple.mydaemon.plist nothing found to load –  Mar 28 '13 at 07:12
  • They probably don't like you using com.apple in there. – Randy Howard Mar 28 '13 at 07:13
  • You plist must be owned by root:wheel and have 0644 mod (-rw-r--r--) –  Mar 28 '13 at 07:14
  • What exactly should I do to make it work? I will be appreciated if you help me to solve this issue –  Mar 28 '13 at 07:20
  • `sudo chown root:wheel your.plist` and `sudo chmod 0644 your.plist` –  Mar 28 '13 at 07:21
  • Thanks you dear cody . The daemon starts up successfully but it launched as user not as root ? What is the mistake you think? –  Mar 28 '13 at 07:29
  • The daemon doesn't launch as root . I did all jobs you said but it doesn't launch as root ! –  Mar 28 '13 at 07:32
  • why do you think it doesn't launch as root? Try two commands `sudo launchctl list | grep your_daemon_name` and `launchctl list | grep your_daemon_name`. Which one shows you your daemon? –  Mar 28 '13 at 07:38
  • Thank you very much Mr.Cody . I appreciate your help . It is solved . God bless you –  Mar 28 '13 at 08:00
0

Change the directory where you put your plist, like this:

/System/Library/LaunchDeamon

This directory was read from Launchd before the startup of user.

ChrisF
  • 41,278
  • 17
  • 101
  • 154
  • I've tried using this solution right now, but since I've upgraded to El-Capitan I cannot move files to this directory. Is there a solution for this? – Yaron Idan Jan 17 '16 at 08:32