qubes-core-appvm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. #
  3. # chkconfig: 345 85 85
  4. # description: Executes Qubes core scripts at AppVM boot
  5. #
  6. # Source function library.
  7. . /etc/rc.d/init.d/functions
  8. possibly_run_save_script()
  9. {
  10. ENCODED_SCRIPT=$(qubesdb-read /qubes-save-script)
  11. if [ -z "$ENCODED_SCRIPT" ] ; then return ; fi
  12. echo $ENCODED_SCRIPT|perl -e 'use MIME::Base64 qw(decode_base64); local($/) = undef;print decode_base64(<STDIN>)' >/tmp/qubes-save-script
  13. chmod 755 /tmp/qubes-save-script
  14. Xorg -config /etc/X11/xorg-preload-apps.conf :0 &
  15. while ! [ -S /tmp/.X11-unix/X0 ]; do sleep 0.5; done
  16. DISPLAY=:0 su - user -c /tmp/qubes-save-script
  17. killall Xorg
  18. }
  19. start()
  20. {
  21. type=$(/usr/bin/qubesdb-read /qubes-vm-type)
  22. if [ "$type" != "AppVM" -a "$type" != "DisposableVM" -a "$type" != "TemplateVM" ]; then
  23. # This script runs only on AppVMs
  24. return 0
  25. fi
  26. # Start AppVM specific services
  27. start_cups=$(/usr/bin/qubesdb-read /qubes-service/cups 2> /dev/null)
  28. if [ "$start_cups" != "0" ]; then
  29. /sbin/service cups start
  30. # Allow also notification icon
  31. sed -i -e '/^NotShowIn=.*QUBES/s/;QUBES//' /etc/xdg/autostart/print-applet.desktop
  32. else
  33. # Disable notification icon
  34. sed -i -e '/QUBES/!s/^NotShowIn=\(.*\)/NotShowIn=QUBES;\1/' /etc/xdg/autostart/print-applet.desktop
  35. fi
  36. echo -n $"Executing Qubes Core scripts for AppVM:"
  37. if qubesdb-read /qubes-save-request 2>/dev/null ; then
  38. if [ -L /home ]; then
  39. rm /home
  40. mkdir /home
  41. fi
  42. mount --bind /home_volatile /home
  43. touch /etc/this-is-dvm
  44. mount /rw
  45. possibly_run_save_script
  46. umount /rw
  47. dmesg -c >/dev/null
  48. free | grep Mem: |
  49. (read a b c d ; qubesdb-write /qubes-used-mem $c)
  50. # give dom0 time to read some entries, when done it will shutdown qubesdb,
  51. # so wait for it
  52. qubesdb-watch /stop-qubesdb
  53. # just to make sure
  54. systemctl stop qubes-db.service
  55. # we're still running in DispVM template
  56. echo "Waiting for save/restore..."
  57. # the service will start only after successful restore
  58. systemctl start qubes-db.service
  59. echo Back to life.
  60. fi
  61. start_meminfo_writer=$(/usr/bin/qubesdb-read /qubes-service/meminfo-writer 2>/dev/null)
  62. if [ "$start_meminfo_writer" != "0" ]; then
  63. MEM_CHANGE_THRESHOLD_KB=30000
  64. MEMINFO_DELAY_USEC=100000
  65. /usr/lib/qubes/meminfo-writer $MEM_CHANGE_THRESHOLD_KB $MEMINFO_DELAY_USEC /var/run/meminfo-writer.pid
  66. fi
  67. success
  68. echo ""
  69. return 0
  70. }
  71. stop()
  72. {
  73. return 0
  74. }
  75. case "$1" in
  76. start)
  77. start
  78. ;;
  79. stop)
  80. stop
  81. ;;
  82. *)
  83. echo $"Usage: $0 {start|stop}"
  84. exit 3
  85. ;;
  86. esac
  87. exit $RETVAL