I've been trying to get this to work but haven't had any success.
I have this jar file: /Users/ivanmorelos/Documents/guiprueba.jar
I also made this sh file:
#!/bin/bash
java -jar guiprueba.jar
the path to this sh is: /Users/ivanmorelos/Documents/guiprueba.sh
If I run this script from the terminal like
bash /Users/ivanmorelos/Documents/guiprueba.sh
then the jar executes perfectly.
Now I went to /Library/LaunchDaemons/ and made the following com.ivan.gui.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple$
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ivan.gui</string>
<key>ProgramArguments</key>
<array>
<string>/Users/ivanmorelos/Documents/guiprueba.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
*I made the sh executable and it belongs to ivanmorelos, so does the jar file.
*The plist belongs to root.
As I understand this should make my jar execute at boot time and therefor, before the login screen comes up. Am I correct? But any way nothing happens and I don't know where the error is. Could you please help me? I would really appreciate it.
EDIT
I made the following change in the script:
java -jar guiprueba.jar
for
touch texto.txt
to create a simple file but it still doesn't do it.
So I finally found the solution to this problem.
I left my jar at /Users/ivanmorelos/Documents/ owned by root:wheel. A ls -l shows this:
-rw-r--r-- 1 root wheel 2365 Jul 29 11:27 guiprueba.jar
Then moved my plist to /System/Library/LaunchDaemons/ with the following permissions:
-rw-r--r-- 1 root wheel 372 Jul 29 12:49 com.ivan.plist
Also moved my script to /usr/sbin/ with the following permissions:
-rwxr-xr-x 1 root wheel 129 Jul 29 13:07 /usr/sbin/guiprueba
and as the ls -l shows I removed the .sh
And that's it. Now my script and jar execute at boot time.
This is the final plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs$
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ivan</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/guiprueba</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Related
I have a launch daemon plist that runs a python script. The problem is that it is unable to run the script because it does not have access to python.
I am trying to make a launch daemon to change mac address (https://github.com/feross/SpoofMAC)
Here is the 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>MacSpoof</string>
<key>ProgramArguments</key>
<array>
<string>/Users/username/.asdf/shims/spoof-mac.py</string>
<string>randomize</string>
<string>en0</string>
</array>
<key>StandardOutPath</key>
<string>/Users/username/Projects/MAC/out.log</string>
<key>StandardErrorPath</key>
<string>/Users/username/Projects/MAC/err.log</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The Error Log reads:
No version is set for command spoof-mac.py
Consider adding one of the following versions in your config file at
python 3.11.1
My tool_version does include Python, how can I make this work?
Okay, I kinda got it working. I moved the plist file from /Library/LaunchDaemons to /Library/LaunchAgents and it works because LaunchAgents run after the user is logged in. It's not exactly what I wanted, but it works.
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 a way to automatically do a vagrant up command inside my directory /Users/user/Dropbox/Development/Homestead
Does anyone know how this can be achieved?
You can write an automator application (i.e. workflow) and in that application have it run the shell script with your desired vagrant command. Then go to System Preferences -> Accounts -> Login items and add that application as a login item.
With a LaunchD item. Put a file containing this in your /Library/LaunchDaemons directory:
<?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>UserName</key>
<string>user</string>
<key>Label</key>
<string>org.xyzzy.vagrantsrc</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
</dict>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/vagrant</string>
<string>up</string>
</array>
<key>RunAtLoad</key><true/>
<key>UserName</key><string>jenkins</string>
<key>WorkingDirectory</key><string>/Users/user/Dropbox/Development/Homestead</string>
</dict>
</plist>
It needs to be owned by root and called something.plist
I'm trying to run an executable on my machine (mbp retina osx mountain lion) on startup.
This is what the script looks like:
<?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.netresponsibility.daemon</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/net-responsibility</string>
<string>--daemon</string>
</array>
<key>OnDemand</key>
<true/>
</dict>
</plist>
I put it in the /System/Library/LaunchDaemons/ directory. It's named com.netresponsibility.daemon.plist and has the same permissions as all the others.
-rw-r--r-- 1 root wheel 420 Oct 11 12:39 com.netresponsibility.daemon.plist
When I restart the executable is not called. Any ideas as to what I'm missing?
First, you shouldn't ever put anything in /System/Library. That path is reserved for OS X files. You should put your files in /Library/LaunchDaemons/.
Second, you need to tell the system to load your plist, it's not enough to just put it there. To do that, you use launchctl:
$ sudo launchctl load -w /Library/LaunchDaemons/com.netresponsibility.daemon.plist
For more information, man launchctl.
I am trying to use launchd to run a python script every 10 minutes. This is easy with cron, but I have been trying for several hours to understand how to operate launchd and I have been unsuccessful. I am using a version of python located in /Users/turtle/bin/. Here is what my launchd file (com.foobar) looks like:
<?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.foobar</string>
<key>ProgramArguments</key>
<array>
<string>/Users/turtle/bin/python</string>
<string>/Users/turtle/code/baz.py</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>10</integer>
</dict>
</dict>
</plist>
When I run:
launchctl load /Library/LaunchAgents/com.foobar
I get:
launchctl: Couldn't stat("/Library/LaunchAgents/com.foobar"): No such file or directory nothing found to load
Can anyone help me? Thanks for your time.
StartCalendarInterval with the key Minute : the script run at the 10th minutes of every hour.
You must use StartInterval : job to be started every N seconds
<key>StartInterval</key>
<integer>600</integer>
launchctl load -w /Library/LaunchAgents/com.foobar
Does that work?