Run MyMedia as a Daemon on Mac OS X

40 views
Skip to first unread message

krakin

unread,
Feb 6, 2011, 11:33:53 AM2/6/11
to MyMedia Roku Developers
Great project folks, thanks for putting together.

I was a bit tired of running this manually so setup a daemon to run
when I login on Mac OS X. Just a tip for anyone that might want to
setup mymedia to run as a launch daemon, you can follow the tips
below.

Please note that there are a few edits you'll need to make to the
files to get your PATHing right, also this could just as easily be
configured as a system launchagent if you put it in the /Library/
LaunchAgents directory rather than your individual user accounts.

****
Step 1: Create the "runmymedia.sh" file and put it somewhere, I
recommend in the MyMedia/server directory.

=== runmymedia.sh file begins below this line ===
#!/bin/sh
##

#set the MYMEDIA_DIR variable to the install location of your MyMedia
folder
#
# example
# MYMEDIA_DIR=/Applications/MyMedia
MYMEDIA_DIR=<put full path of the MyMedia directory here>

echo "MYMEDIA SERVER: starting ... "

ping -t 1 -q -o rokumm.appspot.com 2>&1 > /dev/null
if [ $? -ne 0 ]; then
echo "MYMEDIA SERVER: ERROR -- no network available -- exiting in 30
seconds"
sleep 30 #delay 30 seconds before exiting to prevent constant rerun
of daemonagent
exit 1
fi

cd $MYMEDIA_DIR/server
/usr/bin/python mymedia.py
=== runmymedia.sh file ends above this line ===


*****
Step 2: make the runmymedia.sh file executable

From command line run
chmod +x runmymedia.sh

*****
Step 3: create the mymedia.plist file in your ~/Library/LaunchAgents
directory

Again please note that this file requires you to identify the location
of the runmymedia.sh file

=== mymedia.plist file begins above this line ===
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mymedia</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/MyMedia/server/runmymedia.sh</string>
</array>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
=== mymedia.plist file ends above this line ===

again make sure you change the "/Applications/MyMedia/server/
runmymedia.sh" string to match your location

******
Step 4. Logout and login again to test .. or manually load by running
the appropriate launchctl commands below

launchctl
launchd% load ~/Library/LaunchAgents/mymedia.plist
launchd% start mymedia
launchd% exit
ps -ef | grep mymedia

<at this point you should see runmymedia and mymedia.py running>



--- hope that helps someone

Also note this will log to the console so if you bring up the console
viewer you will see activity as well as any error messages generated.
Reply all
Reply to author
Forward
0 new messages