Here she comes...
<?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>Titan Server</string>
<key>ProgramArguments</key>
<array>
<string>/Users/Ian/Titan/bin/titan.sh</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/Users/Ian/Titan</string>
</dict>
</plist>
If I go into terminal and do...
launchctl load "Titan Server.plist"
... it says ...
/Library/LaunchAgents/Titan Server.plist: Operation already in
progress
Huh?
If I navigate to the working directory manually and type the command it works ok.
Related
I'm setting up plist files to run a python script daily at 9am with plist.
When the file contains StartInterval and set 10 as int it works well and runs every 10s.
<?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.gmtwitter.gm</string>
<key>ProgramArguments</key>
<array>
<string>/Users/marc/mambaforge/envs/main_env/bin/python</string>
<string>/Users/marc/code/automation/twitter/twitter.py</string>
</array>
<key>StartInterval</key>
<integer>10</integer>
</dict>
</plist>
However when I replace it by StartCalendarInterval, the file never runs. I followed doc and tutorials but can't find why it doesn't work.
<?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.gmtwitter.gm</string>
<key>ProgramArguments</key>
<array>
<string>/Users/marc/mambaforge/envs/main_env/bin/python</string>
<string>/Users/marc/code/automation/twitter/twitter.py</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>18</integer>
<key>Minute</key>
<integer>57</integer>
</dict>
</dict>
</plist>
This is my launchd 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>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.localhost.hexo</string>
<key>ProgramArguments</key>
<array>
<string>/Users/frankg/dev/bin/start-hexo.sh</string>
</array>
<key>UserName</key>
<string>frankg</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/frankg/hexo</string>
<key>StandardOutPath</key>
<string>/Users/frankg/hexo</string>
</dict>
</plist>
This is my bash script
hexo server --cwd /Users/frankg/dev/code/apps/blog >> /tmp/MyLaunchdTest.out
This is working. How can I avoid the use of a bash script.
Specify the full path to the hexo executable, followed by each argument to it as a separate string in the ProgramArguments array. I'm a bit confused by the various output redirects -- in the current .plist you specify output to /Users/frankg/hexo, but in the script you redirect it to /tmp/MyLaunchdTest.out instead; I assume the latter is what you actually want? AIUI you could also use the WorkingDirectory key to replace the --cwd option. Something 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>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.localhost.hexo</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/hexo</string>
<string>server</string>
</array>
<key>UserName</key>
<string>frankg</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/frankg/hexo</string>
<key>StandardOutPath</key>
<string>/tmp/MyLaunchdTest.out</string>
<key>WorkingDirectory</key>
<string>/Users/frankg/dev/code/apps/blog</string>
</dict>
</plist>
I want to run a script when my application moved into trash folder and I come to know that using launch agents its possible, I googled and made the plist but its not working or not calling the 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>com.meet.anywhere</string>
<key>WatchPaths</key>
<array>
<string>~/.Trash</string>
</array>
<key>ProgramArguments</key>
<array>
<string>/Users/eclit/Desktop/DeleteScript.scpt</string>
</array>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
launchd cannot run the applescript directly. You need to use the command line tool osascript to run the applescript. As such your ProgramArguments portion should look like the following. Also, there's no need for the KeepAlive section. It does nothing so I'd remove it.
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/eclit/Desktop/DeleteScript.scpt</string>
</array>
<?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.meet.anywhere</string>
<key>WatchPaths</key>
<array>
<string>~/.Trash/AppName.app</string>
</array>
<key>ProgramArguments</key>
<array>
<string>osascript</st
<string>/Users/eclit/Desktop/DeleteScript.scpt</string>
</array>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
I want to create a LaunchDaemon on OSX Mavericks for my Gitblit, this is my file (org.gitblit.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>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.gitblit.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>--baseFolder</string>
<string>data</string>
<string>-jar</string>
<string>/Applications/gitblit/gitblit.jar</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
It's not working, but when I try java -jar gitblit.jar --baseFolder data on /Applications/gitblit everything works fine. Am I missing something?
The Gitblit GO distribution comes with a shell script gitblit.sh that will work for this purpose. This is the version of the LaunchAgent plist ~/Library/LaunchAgents/org.gitblit.plist I used.
Note the addition of the WorkingDirectory key, as well as log files in case of errors.
<?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>org.gitblit.plist</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Applications/gitblit/gitblit.sh</string>
</array>
<key>WorkingDirectory</key>
<string>/Applications/gitblit/</string>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/Applications/gitblit/stdout.txt</string>
<key>StandardErrorPath</key>
<string>/Applications/gitblit/sterr.txt</string>
</dict>
</plist>
So I finally ended up cheating like this:
I saved this script on /opt/scripts/start_gitblit.sh:
#!/bin/bash
cd /Applications/gitblit/
java -jar gitblit.jar --baseFolder data
Then I stored this property list on ~/Library/LaunchAgents/org.gitblit.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>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.gitblit.plist</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/opt/scripts/start_gitblit.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Everything is working now.
I have an application which i want to run as service on MacOS X. I used JSVC as wrapper and currently it starts in console just fine, shutdown process is correct, etc. So now i have to register it as service. Found some manuals, wrote .plist file. Next i executed
sudo launchctl load /Library/LaunchDaemons/my.service.plist
sudo launchctl start my.service
And nothing happened. Service didn't started.
plist contents:
<?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>my.service</string>
<key>ProgramArguments</key>
<array>
<string>/servertest/MYService</string>
<string>-jvm</string>
<string>server</string>
<string>-outfile</string>
<string>out.txt</string>
<string>-errfile</string>
<string>err.txt</string>
<string>-verbose</string>
<string>-debug</string>
<string>-home</string>
<string>/System/Library/Frameworks/JavaVM.framework/Home</string>
<string>-cp</string>
<string>./lib/hsqldb.jar:./lib/my-wrapper.jar:./lib/commons-daemon-1.0.8.jar</string>
<string>my.service.DaemonMac</string>
</array>
<key>WorkingDirectory</key>
<string>/servertest</string>
<key>StandardOutPath</key>
<string>/servertest/stdout.log</string>
<key>StandardErrorPath</key>
<string>/servertest/stderr.log</string>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
What am i doing wrong?
Okay, nobody knows, i guess. Anyway, i handled it myself. Here's example which worked for me:
<?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>
<false/>
<key>Label</key>
<string>myserver</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/opt/MYServer/MYServer</string>
<string>-server</string>
<string>-outfile</string>
<string>/opt/MYServer/out.txt</string>
<string>-errfile</string>
<string>/opt/MYServer/err.txt</string>
<string>-verbose</string>
<string>-debug</string>
<string>-nodetach</string>
<string>-home</string>
<string>/System/Library/Frameworks/JavaVM.framework/Home</string>
<string>-cp</string>
<string>/opt/MYServer/lib/hsqldb.jar:/opt/MYServer/lib/my-wrapper.jar:/opt/MYServer/lib/commons-daemon-1.0.8.jar</string>
<string>my.service.DaemonMac</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/opt/MYServer/stderr.log</string>
<key>StandardOutPath</key>
<string>/opt/MYServer/stdout.log</string>
<key>WorkingDirectory</key>
<string>/opt/MYServer</string>
</dict>
</plist>