Monday, August 10, 2015

[Updated] Fix for slow shutdown when using Synology CloudStation client on OSX

UPDATE: As of version 3.2-3487 of the CloudStation app the slow shutdown times have been fixed (at least on OSX 10.11 El Capitan). Note that the older versions still had problems on OSX 10.11 El Capitan, and only the listed version seems to fix this on my 2013 13" Retina MBP.

I've noticed that my mac is experiencing slow shutdown times (~30-50 sec slower than usual) when the Synology CloudStation client/app is running. This has been seen on version: 3.2-3482 and one version earlier.

Doing some diagnostics I noticed that the process "cloud-eventd" was not terminated even when the CloudStation client/app was told to terminate. This process would then make the system wait for a graceful termination before continuing the shutdown (or reboot) process. And this is what caused the delay of ~30-50 sec.

I've been in contact with support twice, but so far no fix has been published and I've instead created an AppleScript that is able to detect if both the client/app and the offending process is running and then terminate both.

Upon completion it will then give the possibility of shutting down, restarting or nothing.
Here's a screenshot showing the dialog.

The script is pasted below and I would recommend that the script is exported as an application so you can easily call it from e.g. Spotlight. (I named mine
NOTE: The script needs admin rights to kill the "cloud-eventd" as it is owned by root. As a result there will be a request for an admin password if the process is to be terminated.

set no_action to "- No action performed"
set answer to no_action

set app_name to "CloudStation"
if application app_name is running then
tell application app_name to quit
set answer to "- Application " & app_name & " terminated"
delay 2
end if

set proc_name to "cloud-eventd"
set the_pid to (do shell script "ps ax | grep " & (quoted form of proc_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then
do shell script ("kill -9 " & the_pid) with administrator privileges
if answer is no_action then
set answer to "- Process " & proc_name & " terminated"
set answer to answer & "
" & "- Process " & proc_name & " terminated"
end if
end if

set reaction to the button returned of (display dialog "CloudStation killer:
" & answer buttons {"Shutdown", "Reboot", "Dismiss"} default button 3)

if reaction is "Shutdown" then
tell application "Finder" to shut down
else if reaction is "Reboot" then
tell application "Finder" to restart
end if