Im trying to add a LaunchDeamon on MacOS that is executed on startup.
I made a .sh script which works on direct execution. Its located at /usr/local/libexec/scripts/startup/ This is my script: startup.sh
#!bin/bash # Check if deamon is running if [ "$(ps -ef | grep -v grep | grep clamd | wc -l)" -le 0 ] then #Start deamon /opt/homebrew/Cellar/clamav/0.104.2/sbin/clamd echo "clamd started" else echo "clamd already running" fi Also made a launchd file to run it on startup that looks like this. Its located at /Library/LaunchDaemons/ com.startup.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/bin:/usr/bin:/usr/local/bin</string> </dict> <key>Label</key> <string>com.startup</string> <key>Program</key> <string>/usr/local/libexec/scripts/startup/startup.sh</string> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> <key>StandardOutPath</key> <string>/tmp/startup-scripts.stdout</string> <key>StandardErrorPath</key> <string>/tmp/startup-scripts.stderr</string> </dict> </plist> Now I want to add it to the launchctl list.
sudo launchctl load -w /Library/LaunchDaemons/com.startup.plist
Im looking through the list with sudo launchctl list | grep com.startup and it does exist:
- 78 com.startup Unfortunately when restarting the computer it is not running the script.. There is no output in any of the stdin/out/err files.
Any suggestions why its not running on startup?
Tell me, if I can provide more infos
~/scriptswould be on the protected list), and that you seem to be treatingStandardInPathas if it pointed to an output file rather than an input file (I'd just remove this key). Beyond that, check the system logs andsudo launchctl list com.startup.sudo chmod -xon the script and thought this should be okay. Can you recommand a directory for my scripts?sudo launchctl listoutput) indicates some sort of problem with the executable file, or maybe the I/O files; see this and this. I notice that the shebang line in your script has a typo:#!bin/bashshould be#!/bin/bash; maybe that's the cause?