qubes-core-appvm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. # Reload random seed
  61. qubesdb-read /qubes-random-seed | base64 -d > /dev/urandom
  62. qubesdb-rm /qubes-random-seed
  63. fi
  64. start_meminfo_writer=$(/usr/bin/qubesdb-read /qubes-service/meminfo-writer 2>/dev/null)
  65. if [ "$start_meminfo_writer" != "0" ]; then
  66. MEM_CHANGE_THRESHOLD_KB=30000
  67. MEMINFO_DELAY_USEC=100000
  68. /usr/lib/qubes/meminfo-writer $MEM_CHANGE_THRESHOLD_KB $MEMINFO_DELAY_USEC /var/run/meminfo-writer.pid
  69. fi
  70. success
  71. echo ""
  72. return 0
  73. }
  74. stop()
  75. {
  76. return 0
  77. }
  78. case "$1" in
  79. start)
  80. start
  81. ;;
  82. stop)
  83. stop
  84. ;;
  85. *)
  86. echo $"Usage: $0 {start|stop}"
  87. exit 3
  88. ;;
  89. esac
  90. exit $RETVAL