rothnd wrote:
So I have a group of scripts run by the main.py script of daps. Right now my problem is with using a plist to load main.py so it's always running/accessible and so that it has access to an rclone exec.
What is all of that? What is daps? What is rclone?
What do you mean by "accessible"? You can run some script, that's fine. But is said script providing some kind of service? What is "accessing" it? And how?
Is rclone this thing? https://github.com/rclone/rclone "rsync for cloud storage" - because rsync is just a pleasure to use elsewhere. </sarcasm>
I invoke the main.py manually with
cd /Users/nathan/daps
source .venv/bin/activate
python3 /Users/nathan/daps/main.py
OK. Now we're getting somewhere.
which seems to work fine. However, when I attempt to load main.py in the background and it makes its call to rclone, rclone fails (command not found).
So this daps thingy is supposed to call some other open-source thingy to do something with some 3rd party cloud service? If you ever get this running, maybe wrap it all up into an app and sell it as "Masochist Cloud - the media manager choice for people who want to punish themselves."
My updated 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>Label</key>
<string>com.nathan.daps</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>.venv/bin/python3 main.py</string>
</array>
<key>WorkingDirectory</key>
<string>/Applications/daps</string>
</dict>
</plist>
That's never going to work.
You have to go back your manual execution and figure out what that's doing.
cd /Users/nathan/daps
Change the working directory to the daps directory in your home directory. OK. Fair enough.
source .venv/bin/activate
This is more complicated. It's going to stuff a bunch of stuff into your environment. What kind of stuff?
python3 /Users/nathan/daps/main.py
Run python3 (presumably found in some path stuffed in via step 2) and execute this python script.
That's 3 steps. You can't do that in a launchd script. You could kinda do #1 via WorkingDirectory, but that's such a cop-out. But regardless, you can't do those other 2 steps. I don't know. Maybe you do something funky with "sh" and semicolons. How about we do it properly instead?
What you have to do is merge these into a single script. The script is pretty simple. First it changes to the desired directory. Then it runs "source .venv/bin/activate" and then it runs "python3 /Users/nathan/daps/main.py". Save the three-line script as something named "daps.sh" in some convenient place. Probably shouldn't put it in the existing "daps" directory though.
If you want to be really fancy, you could add a shebang line and make the script executable with "chmod". Then you could just run the script with nothing else. Otherwise, you'll still have to run "sh" to execute it. Since it's a stand-alone script, you don't need the "-c" parameter.
Your plist would look 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>Label</key>
<string>me.nathan.daps</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/Users/nathan/bin/daps.sh</string>
</array>
</dict>
</plist>