无法初始化服务器:无法连接:连接被拒绝

无法初始化服务器:无法连接:连接被拒绝

运行时,

#!/bin/bash 
#
# located in /lib/systemd/system-sleep/
# Created 4/2/19
exec 2> /tmp/systemd_suspend_test_err.txt
if [ "${1}" = "pre" ]; then
  # Do the thing you want before suspend here
  echo "we are suspending $(date)." > /home/andy/Downloads/message.txt
elif [ "${1}" = "post" ]; then
  # Do the thing you want after resume here
   echo "and we are back from being suspended $(date)" >> /home/andy/Downloads/message.txt
  #sleep 10
  #notify-send "Computer is returning from suspend." -t 2000
   gxmessage does NOT work and neither does inotify-send
  /usr/bin/gxmessage -fg red -font  'sans 30' -timeout 3  'Back from being suspended.'
fi

我在 /tmp/systemd_suspend_test_err.txt 中得到了这个。

Unable to init server: Could not connect: Connection refused
gxmessage: unable to initialize GTK

答案1

在暂停之前,您可以写入 xhost +,这将允许客户端从任何主机进行连接(不建议在生产环境中使用 - 出于安全考虑)。然后,暂停并恢复,出现带有红色文本的框。

# gxmessage works IF xhost + is run first.
  gxmessage -timeout 5 -fg red -display :0 'Back from being suspended.'

相关内容