jamfHelper -startlaunchd, -kill, and preventing an installation until jamfHelper is done

robo
New Contributor III
New Contributor III

Hi,

I'd appreciate a little help with jamfHelper, as there doesn't seem to be much documentation on it beyond the -help output, which is a bit terse on some of the options, namely -startlaunchd and -kill. Can someone explain how they are used/what they are for? Running jamfHelper -kill in my terminal, for example, just causes the terminal to hang...

Do these work only as part of a script executed by a policy? And if so, what is the proper usage?

Is it

jamfHelper -other_options foo -startlaunchd

and then a separate

jamfHelper -kill

to end it? Can I send jamfHelper to the background with & and still kill it this way, or should I try to kill it via PID?

My idea is to use this with Self Service so that if a user chooses a policy that should only be run when certain apps are closed, I can present them with a buttonless jamfHelper window that asks them to quit the apps in question. Currently my script sends the jamfHelper process to the background (with &) and then runs a loop checking ps output to see when the app in question is no longer running. At that point, the script kills the jamfHelper dialog and exits (and the rest of the installation policy should proceed).

My initial testing (not using -startlaunchd, and killing by PID) sadly failed. The script worked great when run on my computer manually, but when run in a policy, the jamfHelper window remained open indefinitely and the policy went ahead and executed as if ignoring the script. I was not using the -kill option as I was unsure how it was meant to be used (and as mentioned, running it in my terminal simply caused a terminal hang). Hmm...

I will continue to play around with it, but if someone could explain the proper usage, that would be super helpful.

-r

3 REPLIES 3

mm2270
Legendary Contributor III

Hello.
I've never quite understood how to use the -startlaunchd and -kill flags either when working with jamfHelper. Your best bet may be to just put the jamfHelper process in the background with an & and then locate the PID later and kill it that way. That's generally the way I've been doing it in scripts. Its not the prettiest way to handle it, and I would like to use the flags like above, but they just don't seem to be easy to implement for whatever reason.

If anyone else has a better suggestion or some sure-fire way to get those to work, I'd love to hear it as well.

stevewood
Honored Contributor II
Honored Contributor II

@robo and I were talking on IRC about this and I wanted to make sure it was on the list so it might help others.

This the script he is working with:

#!/bin/bash

# Quick script to prompt users to quit Word before installing Endnote X6.

jh='/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper'
jh_args=(
    -windowType utility 
    -title "Pre-installation Notice" 
    -heading "Please quit Microsoft Word" 
    -icon /System/Library/CoreServices/Installer.app/Contents/Resources/Installer.icns 
    -alignHeading left 
    -description
    )
message="Before the requested installation of Endnote X6 can proceed, you must 
quit Microsoft Word 2011, which is currently open on your computer.

To quit Word, click the Word icon in the Dock, then click on the 'Word' menu 
and select 'Quit Word'.  You may save changes to any open documents when 
prompted.

Installation will proceed automatically when Word is no longer running."

word='/Applications/Microsoft Office 2011/Microsoft Word.app'
wordcheck="/bin/ps -e | grep '$word' | grep -vc grep"

if [[ `eval $wordcheck` -ne 0 ]]; then
    "$jh" "${jh_args[@]}" "$message" &
else
    exit 0
fi

while true; do
    if [[ `eval $wordcheck` -eq 0 ]]; then
        killall jamfHelper
        exit 0
    fi
    sleep 1
done

I tested the script and it appears to work as you expected. You shouldn't need the -startlaunchd flag or the -kill flag at all. From reading the help info, the -kill flag is only for when you are running jamfHelper as a launchd item. So if you had it set to run via a LaunchDaemon at user login, perhaps, you could then give a 'jamfHelper -kill' command to kill the jamfHelper.

robo
New Contributor III
New Contributor III

OK, so I got the script to behave, and figured out part of the source of confusion.

First, the bit of the script that has been changed:

[code]
while true; do if [[ `eval $wordcheck` -eq 0 ]]; then kill -9 $! exit 0 fi sleep 1
done
[/code]

Line 3 in there is changed from using killall to using a kill -9 on the PID of the background jamfHelper process.

This now works as expected.

As for what was confusing me before: the SelfService progress bar keeps moving for cosmetic effect while the 'before' script is running (it seem to keep moving up to 50% before it stops). So that moving progress bar in conjunction with the dialog that never got killed made me think that JAMF was ignoring the fact that the script was still executing, when in fact it was correctly waiting until the script exited.

With the update above, it all works as expected - it remains open until the user goes and quits Word, then 'dismisses itself' and the installation proceeds.

No use of -startlaunchd or -kill needed.

Thanks to stevewood for taking the time to try it out on his machine last night too. Still not sure why the 'killall jamfHelper' worked for him, but not for me, but in any case kill -9 $! gets the job done.