#Kill Agent before starting Agent.
agentPID=$(ps -ef | awk '$NF~"Unity_Agent.exe" {print $2}')
kill -9 $agentPID

#export DISPLAY=:0
#Set Display via "init" process for current user.
currentuser=$(last -w | grep "logged in" | awk 'NR==1{print $1}') #Current user
initPID=$(ps -u "$currentuser" | awk '$NF=="init" {print $1}') #Get PID of "init" process for current user.
userDP=$(cat /proc/$initPID/environ | tr '\0' '\n' | grep '^DISPLAY=') #Get Display for init process (belonging to current user)
export "$userDP" #Set Display

su - "$currentuser" -c "/opt/ADXBA/Unity/Unity_Service/scripts/start_unity_agent.sh"