mpanighetti / install-or-defer

A framework for prompting users of Jamf Pro-managed Macs to install Apple software updates.
Apache License 2.0
147 stars 28 forks source link

Soft Restart doesn't work #20

Closed master-vodawagner closed 4 years ago

master-vodawagner commented 5 years ago

Hi,

I keep getting the following error when the script attempts the soft restart commands launchctl asuser "$USER_ID" osascript -e "tell application \"System Events\" to restart"

syntax error: Expected end of line but found end of script. (-2741)

homebysix commented 5 years ago

Hi @master-vodawagner - Could you put an echo before the line that starts with launchctl asuser in the script, run on one of your affected Macs, and let me know what output you see? I'm interested in what command is actually running that would cause an "end of script" error.

master-vodawagner commented 5 years ago

Sorry my coding is basic atm, would the below work for what you need?

echo "launchctl asuser "$(USER_ID)" osascript -e "tell application \"System Events\" to shutdown""

homebysix commented 5 years ago

Sort of. In the current master branch, the line you'd want to prefix with echo is 238. That would look like this:

echo launchctl asuser "$USER_ID" osascript -e "tell application \"System Events\" to $1"

Making that change and re-running the script on an affected Mac should allow us to see what user ID and AppleScript syntax is being used.

master-vodawagner commented 4 years ago

Tue Jan 14 21:57:45 GMT 2020: Attempting a "soft" shutdown... launchctl asuser 502 osascript -e tell application "System Events" to shutdown Tue Jan 14 21:57:45 GMT 2020: Waiting 5 minutes before forcing a "hard" shutdown

If I run that command manually it errors out

X1900345:~ root# launchctl asuser 502 osascript -e tell application "System Events" to shutdown 4:4: syntax error: Expected expression but found end of script. (-2741)

master-vodawagner commented 4 years ago

Would these be a better idea than the tell command?

Line 238

echo launchctl asuser "$USER_ID" osascript -e "tell application \"System Events\" to $1" >> /var/log/install_or_defer.log

if [[ "$1" = "restart" ]]; then
    shutdown -r
elif [[ "$1" = "shutdown" ]]; then
    shutdown -h
fi

Line 261

echo launchctl asuser "$USER_ID" osascript -e "tell application \"System Events\" to $1" >> /var/log/install_or_defer.log

if [[ "$1" = "restart" ]]; then
    shutdown -r now
elif [[ "$1" = "shutdown" ]]; then
    shutdown -h now
fi
# Mac should restart/shutdown now, ending this script and installing updates.
homebysix commented 4 years ago

Hi @master-vodawagner - Could you try again with the latest master branch? You can download the current master here. We've made a couple changes since you reported the issue, and the "Expected expression but found end of script" error makes me think you were missing a piece of the code.

Regarding the soft/hard shutdowns, I think shutdown -r and shutdown -h is unnecessarily rough, and haven't heard of any reports of the script failing to hard-restart after the delay passes. The kill -9 that runs just prior to the restart/shutdown should alleviate issues with most stuck processes.

master-vodawagner commented 4 years ago

@homebysix - I am on you latest version 2.3.3

mpanighetti commented 4 years ago

@master-vodawagner Are you making any changes to the script? Haven't heard any reports of this happening with the vanilla payload as provided in our releases. Also recommend trying again with the latest build (v2.3.4), which addresses an issue that was preventing the restart/shutdown step from completing. Thanks!