Changes

Jump to navigation Jump to search
762 bytes removed ,  02:28, 8 April 2019
m
Line 6: Line 6:     
* First, X software uses SystemV IPC shared memory to exchange data between server and application, thus you'll have to run the whole stuff in IPC namespace;
 
* First, X software uses SystemV IPC shared memory to exchange data between server and application, thus you'll have to run the whole stuff in IPC namespace;
* Second, in order to be restored reliably, it's recommended to run VNC server, window manager and application in a PID namespace;
+
* Second, in order to be restored reliably, it's recommended to run [https://tigervnc.org/ VNC server], window manager and application in a PID namespace;
 
* Third, when started from shell they will inherit session ID and terminal from that shell, which might block dump.
 
* Third, when started from shell they will inherit session ID and terminal from that shell, which might block dump.
   Line 13: Line 13:  
! <code>newns.c</code>
 
! <code>newns.c</code>
 
|-
 
|-
| <syntaxhighlight lang="c">
+
| {{:VNC/newns.c}}
#define _GNU_SOURCE
  −
#include <stdio.h>
  −
#include <stdlib.h>
  −
#include <unistd.h>
  −
#include <string.h>
  −
#include <errno.h>
  −
#include <sys/mount.h>
  −
#include <sys/types.h>
  −
#include <sys/stat.h>
  −
#include <sys/wait.h>
  −
#include <sys/param.h>
  −
#include <sys/mman.h>
  −
#include <fcntl.h>
  −
#include <signal.h>
  −
#include <sched.h>
  −
 
  −
#define STACK_SIZE (8 * 4096)
  −
 
  −
static int ac;
  −
static char **av;
  −
static int ns_exec(void *_arg)
  −
{
  −
int fd;
  −
 
  −
fd = open("newns.log", O_CREAT | O_TRUNC | O_RDWR | O_APPEND, 0600);
  −
if (fd >= 0) {
  −
close(0);
  −
dup2(fd, 1);
  −
dup2(fd, 2);
  −
close(fd);
  −
}
  −
 
  −
setsid();
  −
execvp(av[1], av + 1);
  −
return 1;
  −
}
  −
 
  −
int main(int argc, char **argv)
  −
{
  −
void *stack;
  −
int ret;
  −
pid_t pid;
  −
 
  −
ac = argc;
  −
av = argv;
  −
 
  −
stack = mmap(NULL, STACK_SIZE, PROT_WRITE | PROT_READ,
  −
MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS, -1, 0);
  −
if (stack == MAP_FAILED) {
  −
fprintf(stderr, "Can't map stack %m\n");
  −
exit(1);
  −
}
  −
pid = clone(ns_exec, stack + STACK_SIZE,
  −
CLONE_NEWPID | CLONE_NEWIPC | SIGCHLD, NULL);
  −
if (pid < 0) {
  −
fprintf(stderr, "clone() failed: %m\n");
  −
exit(1);
  −
}
  −
return 0;
  −
}
  −
</syntaxhighlight>
   
|}
 
|}
   Line 83: Line 22:  
#!/bin/bash
 
#!/bin/bash
 
set -m
 
set -m
Xvnc :25 -v -geometry 800x600 -i 0.0.0.0 -SecurityTypes none &
+
Xvnc :25 -v -geometry 800x600 -interface 0.0.0.0 -SecurityTypes none &
 
pid=$!
 
pid=$!
 
trap "kill $pid; wait" EXIT
 
trap "kill $pid; wait" EXIT
Line 91: Line 30:     
with the above "software" the server can be launched like this:
 
with the above "software" the server can be launched like this:
<pre>
+
 
# ./newns ./vnc_server.sh icewm
+
# chmod a+x vnc_server.sh
</pre>
+
# ./newns ./vnc_server.sh icewm
    
After this you will see the process tree like below:
 
After this you will see the process tree like below:
 
<pre>
 
<pre>
 
17854 ?        Ss    0:00 /bin/bash ./vnc-server.sh icewm
 
17854 ?        Ss    0:00 /bin/bash ./vnc-server.sh icewm
17855 ?        Sl    0:00  \_ Xvnc :25 -v -geometry 800x600 -i 0.0.0.0 -SecurityTypes none
+
17855 ?        Sl    0:00  \_ Xvnc :25 -v -geometry 800x600 -SecurityTypes none
 
17863 ?        R      0:00  \_ icewm
 
17863 ?        R      0:00  \_ icewm
 
</pre>
 
</pre>
Line 104: Line 43:  
== Launch VNC client ==
 
== Launch VNC client ==
   −
After this you can start your favorite VNC client (viewer) to see what's inside the server. The latter would be visible on port 5925 (:25 argument).
+
After this you can start your favorite VNC client (viewer) to see what's inside the server. The latter would be visible on port 5925 (:25 argument). For example:
[[File:Vnc.jpg]]
+
 
 +
$ vncviewer localhost:25
 +
 
 +
[[File:Vnc.jpg|400px]]
    
Launch a terminal, then some application. It will attach to X and you'd see it on the screen.
 
Launch a terminal, then some application. It will attach to X and you'd see it on the screen.
Line 112: Line 54:     
Then you should create a directory for image files (e.g. <code>imgs</code>) and dump the tree starting from the VNC launching script
 
Then you should create a directory for image files (e.g. <code>imgs</code>) and dump the tree starting from the VNC launching script
<pre>
  −
# crtools dump -t 17854 --images-dir imgs/ --log-file dump.log -v 4 --tcp-established
  −
</pre>
     −
The <code>-v 4</code> option is required to make crtools more verbose and the <code>--tcp-established</code> one is needed, to make crtools handle active TCP connection -- the one between VNC server and VNC client.
+
# criu dump -t 17854 --images-dir imgs/ --log-file dump.log -v4 --tcp-established
 +
 
 +
 
 +
The <code>-v4</code> option is required to make criu more verbose and the <code>--tcp-established</code> one is needed, to make criu handle active TCP connection -- the one between VNC server and VNC client.
 +
 
 +
Check the criu return code to be 0, or the imgs/dump.log file last message to be
   −
Check the crtools return code to be 0, or the imgs/dump.log file last message to be
+
Dumping finished successfully
<pre>
  −
Dumping finished successfully
  −
</pre>
      
After this the VNC client would see, that the server got stuck and any moving picture(s) in the screen would be frozen. Hurry up and proceed to the restore stage, as TCP timeout may occur and abort the frozen connection.
 
After this the VNC client would see, that the server got stuck and any moving picture(s) in the screen would be frozen. Hurry up and proceed to the restore stage, as TCP timeout may occur and abort the frozen connection.
    
== Restore VNC server ==
 
== Restore VNC server ==
<pre>
  −
# crtools restore -t 17854 --images-dir imgs/ --log-file rst.log -v 4 --tcp-established -d
  −
</pre>
     −
What has changed from the dump command is the action (it's restore now), the log file name (not to mix things up) and the new <code>-d</code> option. It says, that after restoring crtools should exit and make the restored tree of tasks to be reparented to the init task.
+
# criu restore --images-dir imgs/ --log-file rst.log -v4 --tcp-established -d
 +
 
 +
What has changed from the dump command is the action (it's restore now), the log file name (not to mix things up) and the new <code>-d</code> option. It says, that after restoring criu should exit and make the restored tree of tasks to be reparented to the init task.
 +
 
 +
Check the criu return code to be 0, or the imgs/rst.log file last message to be
 +
 
 +
Restore finished successfully. Resuming tasks.
 +
 
 +
== Video Demo ==
 +
 
 +
[https://www.youtube.com/watch?v=j4wlYY7lTDw Dumping video player with CRIU]
 +
 
 +
[https://www.youtube.com/watch?v=roJ91Kqeq5w Example how CRIU can dump and restore a TCP connections]
 +
 
 +
[https://www.youtube.com/watch?v=kjhuzSl6JYc Checkpoint and restore of Firefox with CRIU]
 +
 
 +
== See also ==
   −
Check the crtools return code to be 0, or the imgs/rst.log file last message to be
+
* [[Screen]]
<pre>
+
* [[TCP connection]]
Restore finised successfully. Resuming tasks.
  −
</pre>
      
[[Category: HOWTO]]
 
[[Category: HOWTO]]
277

edits

Navigation menu