MI have just installed Grav locally and would like it to run as a daemon. Apparently on Macs that's done in ~/LauchAgents
I have tried to setup the .plist but it's not working. As I am new to Macs I wondered if anyone knew how to setup a local service? Here is what I have so far...
<?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>Label</key>
<string>grav</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/php</string>
<string>~/grav/php -S system/router.php</string>
<string>--httpListenAddress=127.0.0.1</string>
<string>--httpPort=8000</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Related
I've just started looking into using Consul and was following the consul-devops-handbook. It had some details on auto-starting Consul, however this was only for Ubuntu.
Is it possible someone has a guide for achieving this for macOS?
With macOS I'm imagining it has something to do with adding it to LaunchDaemon perhaps?
Can achieve this by adding a .plist file in /Library/LaunchDaemons/:
<?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>Label</key>
<string>consul</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/consul</string>
<string>agent</string>
<string>-config-dir</string>
<string>/etc/consul.d/client</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>StandardOutPath</key>
<string>/var/log/consul.log</string>
<key>StandardErrorPath</key>
<string>/var/log/consul_err.log</string>
</dict>
</plist>
I've made an Automator app that finds people that has birthdays on a given day and saves the names of those in a text-file. It runs in a bash script that also alerts me when someone has a birthday. This works fine when i initiate the script from terminal. But when it runs through my ~/Library/LaunchAgents the birthday list is always empty. Does anybody have a clue, what could be the cause of this?
this is my agent-script
<?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>Label</key>
<string>dk.emmajohnsen.birthdaygreetings</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Users/Emma/Projects/scripts/project_happy_birthday/orchestrateBirthdayAlert</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>08</integer>
<key>Minute</key>
<integer>17</integer>
</dict>
</dict>
</plist>
I want to rsync my /var/repo backup to a remote machine when it changes.
I made a ssh key pairs to make my machine can ssh login to remote without password(ignore details).
I added a file com.ph.rsync2.plist in ~/Library/LaunchAgents.
The content is
<?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>Label</key>
<string>com.ph.rsync2.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/rsync</string>
<string>-avz</string>
<string>--rsh=ssh</string>
<string>/var/repo</string>
<string>flora#192.168.19.28:/var/ph_backups/</string>
</array>
<key>WatchPaths</key>
<array>
<string>/var/repo</string>
</array>
</dict>
Then I launchctl load com.ph.rysnc2.plist.
When /var/repo has any change, it will trigger rsync to work
but I always get the error log in Console.app
It reads like
11/3/15 2:15:26.399 PM com.apple.xpc.launchd[1]:
(com.ph.rsync2.plist) Service only ran for 1 seconds. Pushing respawn out by 9 seconds.
And I tried to move the rsync commands to a script, then let launchd exec my script. but it's still the same
I can't figure out which part of settings make all these fail.
Anyone can give me a clue?
Comments will mess up the formatting, so I'll post how to setup the StandardErrorPath key as an answer.
Modify your job definition like this:
<?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>Label</key>
<string>com.ph.rsync2.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/rsync</string>
<string>-avz</string>
<string>--rsh=ssh</string>
<string>/var/repo</string>
<string>flora#192.168.19.28:/var/ph_backups/</string>
</array>
<key>StandardErrorPath</key>
<string>/tmp/com.ph.rsync2.plist.stderr</string>
<key>WatchPaths</key>
<array>
<string>/var/repo</string>
</array>
</dict>
</plist>
Check the file /tmp/com.ph.rsync2.plist.stderr after reloading and starting the job.
I need to run an mac app daily without any user interaction using launchd, i created a .plist file and pasted it in /system/LaunchDaemons and after that how to execute the plist file, can any one please tell me the step by step working process on how to work with launchd it will helpful for me, I pasted my .plist file below.
<?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>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>myapp.restart</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/myapp.app</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>16</integer>
<key>Minute</key>
<integer>40</integer>
</dict>
</dict>
</plist>
You'll probably need the name of your program like this rather than ProgramArguments:
<key>Program</key>
<string>/Applications/myapp.app/Contents/MacOS/myapp</string>
I am trying to develop a Mac LaunchAgent and am testing with this, which should start the console:
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.depthmine.test</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Utilities/Console.app/Contents/MacOS/Console</string>
</array>
</dict>
</plist>
The file appears to load (no errors in the Terminal) but the console does not start and there does not seem to be a process in Terminal either. I also tried a PHP script and that didn't start either.