Mac: Update script to run Client a daemon to

uses Mac OS X's launchd mechanism

svn path=/trunk/boinc/; revision=14490
This commit is contained in:
Charlie Fenton 2008-01-08 07:52:35 +00:00
parent 7a20f7c085
commit ea77567925
2 changed files with 86 additions and 91 deletions

View File

@ -197,6 +197,11 @@ David Jan 7 2007
Charlie Jan 7 2008 Charlie Jan 7 2008
- Mac MGR: if using Mac OS X's launchd mechanism to run Client as a daemon, - Mac MGR: if using Mac OS X's launchd mechanism to run Client as a daemon,
allow time for daemon to launch. allow time for daemon to launch.
- Mac: Update script which sets BOINC up to run as a daemon so it
uses Mac OS X's launchd mechanism. This requires BOINC version
5.10.34 or later and Mac OS 10.4 or later.
clientgui/ clientgui/
BOINCGUIApp.cpp,h BOINCGUIApp.cpp,h
mac_build/
Make_BOINC_Service.sh

View File

@ -23,12 +23,15 @@
## ##
# Script to set up Macintosh to run BOINC client as a daemon / service # Script to set up Macintosh to run BOINC client as a daemon / service
# by Charlie Fenton 7/26/06 # by Charlie Fenton 7/26/06
# revised 1/2/08 # revised 1/6/08 to use launchd
##
## Note: this version of this script requires BOINC 5.10.34 or later
## and OS 10.4 or later.
## ##
## Usage: ## Usage:
## ##
## source Make_BOINC_Service.sh [path_to_client_dir/] [path_to_data_dir/] ## source Make_BOINC_Service.sh [path_to_client_dir] [path_to_data_dir]
## ##
## path_to_client_dir is needed only for stand-alone client or if Manager ## path_to_client_dir is needed only for stand-alone client or if Manager
## is at non-standard location. ## is at non-standard location.
@ -46,12 +49,12 @@
## (4) In the Terminal window, type "source" and a space. ## (4) In the Terminal window, type "source" and a space.
## (5) Drag this script file from the Finder into the Terminal window. ## (5) Drag this script file from the Finder into the Terminal window.
## (6) If using the stand-alone client, or if the Manager is in a non- ## (6) If using the stand-alone client, or if the Manager is in a non-
## standard location, drag the folder containing the client from ## standard location, drag the folder containing the client from
## the Finder into the Terminal window (or type the path including ## the Finder into the Terminal window (or type the path excluding
## the trailing slash). ## the trailing slash).
## (7) If using the stand-alone client, but the client is not in the data ## (7) If using the stand-alone client, but the client is not in the data
## directory, drag the BOINC data folder from the Finder into the ## directory, drag the BOINC data folder from the Finder into the
## Terminal window (or type the path including the trailing slash). ## Terminal window (or type the path excluding the trailing slash).
## (8) Press the return key. ## (8) Press the return key.
## (9) When prompted, enter your administrator password. ## (9) When prompted, enter your administrator password.
## (10) Restart the computer. ## (10) Restart the computer.
@ -63,26 +66,44 @@
## no user is logged in. ## no user is logged in.
## ##
## Note: the BOINC ScreenSaver may not display graphics for some users ## Note: the BOINC ScreenSaver may not display graphics for some users
## when BOINC Client is running as a daemon / service. We hope to fix ## when BOINC Client is running as a daemon / service. Thus will be
## this in the near future. ## fixed with the release of BOINC 6.0 and project applications updated
## to use the BOINC 6 graphics API.
## ##
## Removal (to stop running BOINC as a daemon / service): ##
## (1) In the Finder, browse to the /Library/StartupItems folder. ## When the system has launched BOINC Client as a daemon, you can stop the
## (2) Drag the boinc directory to the trash. (Finder will ask for ## BOINC Client from the Terminal by typing:
## your administrator user name and password). ## sudo launchctl stop edu.berkeley.boinc
## and you can restart the BOINC Client from the Terminal by typing:
## sudo launchctl start edu.berkeley.boinc
##
## Note: The BOINC Client will quit immediately after launch if it detects
## another instance of BOINC Client already running. So these launchctl
## commands will fail if the BOINC Client was started by the BOINC Manager
## or ScreenSaver.
##
## If BOINC Client is not already running when the BOINC Manager is launched,
## the Manager will start BOINC Client. This will happen automatically at
## login if you have BOINC Manager set as a login item for that user. If
## it was started by the Manager, then BOINC Client will quit when the BOINC
## Manager quits.
##
## If BOINC Client is not already running when the BOINC ScreenSaver starts,
## the ScreenSaver will start BOINC Client and will quit BOINC Client when
## the ScreenSaver is dismissed.
##
## REMOVAL:
## To undo the effects of this script (i.e., to permanently stop running BOINC
## as a daemon / service):
## (1) In the Finder, browse to the /Library/LaunchDaemons folder.
## (2) Drag the file edu.berkeley.boinc.plist to the trash. (Finder will ask
## for your administrator user name and password).
## (3) Restart the computer. ## (3) Restart the computer.
## ##
## The system will no longer start BOINC client as a daemon / service ## The system will no longer start BOINC client as a daemon / service
## at system startup. ## at system startup.
##
## Running BOINC Manager will star BOINC Client. This will happen
## automatically at login if you have BOINC Manager set as a login item
## for that user. BOINC Client will quit when the BOINC Manager quits.
##
## If BOINC Client is not already running when the BOINC ScreenSaver
## starts, the ScreenSaver will start BOINC Client and will quit
## BOINC Client when the ScreenSaver is dismissed.
## ##
## If you wish to completely remove BOINC from your computer, first ## If you wish to completely remove BOINC from your computer, first
## complete the above steps, then follow the directions in the web ## complete the above steps, then follow the directions in the web
@ -91,10 +112,10 @@
## ##
if [ $# -eq 0 ] ; then if [ $# -eq 0 ] ; then
PATH_TO_CLIENT="/Applications/BOINCManager.app/Contents/Resources/" PATH_TO_CLIENT="/Applications/BOINCManager.app/Contents/Resources"
PATH_TO_DATA="/Library/Application Support/BOINC Data/" PATH_TO_DATA="/Library/Application Support/BOINC Data"
# Check for BOINC Manager with embedded BOINC Client # Check for BOINC Manager with embedded BOINC Client
if [ ! -f "${PATH_TO_CLIENT}boinc" ]; then if [ ! -f "${PATH_TO_CLIENT}/boinc" ]; then
echo " ***************************** ERROR ***************************" echo " ***************************** ERROR ***************************"
echo " * *" echo " * *"
echo " * Could not find BOINC Manager with embedded BOINC client *" echo " * Could not find BOINC Manager with embedded BOINC client *"
@ -109,7 +130,7 @@ else
PATH_TO_CLIENT="$1" PATH_TO_CLIENT="$1"
PATH_TO_DATA="$1" PATH_TO_DATA="$1"
# Check for stand-alone BOINC Client # Check for stand-alone BOINC Client
if [ ! -f "${PATH_TO_CLIENT}boinc" ]; then if [ ! -f "${PATH_TO_CLIENT}/boinc" ]; then
echo " ***************************** ERROR ***************************" echo " ***************************** ERROR ***************************"
echo " * *" echo " * *"
echo " * Could not find BOINC client at specified directory *" echo " * Could not find BOINC client at specified directory *"
@ -135,82 +156,51 @@ if [ ! -d "${PATH_TO_DATA}" ]; then
return 1 return 1
fi fi
# Create /Library/StartupItems/boinc/ directory if necessary # Delete the old-style boinc daemon StartupItem if present
if [ ! -d /Library/StartupItems/boinc ]; then sudo rm -fR /Library/StartupItems/boinc
sudo mkdir -p /Library/StartupItems/boinc
fi
# Delete old temporary working directory and files if present # Delete old temporary working directory and files if present
rm -f ~/boincStartupTemp/ rm -fR ~/boincStartupTemp
# Create new temporary working directory # Create new temporary working directory
mkdir -p ~/boincStartupTemp/ mkdir -p ~/boincStartupTemp/
# Create the shell script to start BOINC client in temporary directory # Create file edu.berkeley.boinc.plist in temporary directory.
# (For some reason, we can't create the files directly in the final # (For some reason, we can't create the file directly in the final
# destination directory, so we create them here and them move them.) # destination directory, so we create it here and then move it.)
cat >> ~/boincStartupTemp/boinc << ENDOFFILE cat >> ~/boincStartupTemp/edu.berkeley.boinc.plist << ENDOFFILE
#!/bin/sh <?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">
# Start BOINC client as a daemon <dict>
## <key>GroupName</key>
<string>boinc_master</string>
. /etc/rc.common <key>Label</key>
<string>edu.berkeley.boinc</string>
StartService () <key>Program</key>
{ <string>${PATH_TO_CLIENT}/boinc</string>
if [ -x "${PATH_TO_CLIENT}boinc" ]; then <key>ProgramArguments</key>
if [ -d "/Library/Application Support/BOINC Data" ]; then <array>
ConsoleMessage "Starting BOINC client" <string>${PATH_TO_CLIENT}/boinc</string>
"${PATH_TO_CLIENT}boinc" -redirectio -daemon -dir "${PATH_TO_DATA}" & <string>-redirectio</string>
echo \$! > /var/run/boinc.pid <string>-daemon</string>
fi </array>
fi <key>RunAtLoad</key>
} <true/>
<key>UserName</key>
StopService () <string>boinc_master</string>
{ <key>WorkingDirectory</key>
if pid=\$(GetPID boinc); then <string>${PATH_TO_DATA}/</string>
echo PID = "\${pid}" </dict>
ConsoleMessage "Stopping BOINC client" </plist>
kill -TERM "\${pid}"
fi
if [ -e /var/run/boinc.pid ]; then
rm /var/run/boinc.pid
fi
return 0
}
RestartService ()
{
return 0
}
RunService "\$1"
ENDOFFILE ENDOFFILE
sudo mv -f ~/boincStartupTemp/edu.berkeley.boinc.plist /Library/LaunchDaemons/
# Create the BOINC StartupParameters.plist file in temporary directory
cat >> ~/boincStartupTemp/StartupParameters.plist << ENDOFFILE
{
Description = "BOINC client daemon";
Provides = ("BOINC client daemon");
Requires = ("Network");
OrderPreference = "Last";
}
ENDOFFILE
sudo mv -f ~/boincStartupTemp/boinc /Library/StartupItems/boinc/boinc
sudo mv -f ~/boincStartupTemp/StartupParameters.plist /Library/StartupItems/boinc/StartupParameters.plist
# Delete temporary working directory # Delete temporary working directory
rm -fR ~/boincStartupTemp/ rm -fR ~/boincStartupTemp
# Set ownership and permissions as needed # Set ownership and permissions for our plist
sudo chmod +x /Library/StartupItems/boinc/boinc sudo chown root:wheel /Library/LaunchDaemons/edu.berkeley.boinc.plist
sudo chown -R root:wheel /Library/StartupItems/boinc sudo chmod 0444 /Library/LaunchDaemons/edu.berkeley.boinc.plist
return 0 return 0