Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f1648f3c

Von Cem Aydin vor etwa 2 Jahren hinzugefügt

  • ID f1648f3caf7b2e96af8d725c30a1e801f80520b3
  • Vorgänger bb9569ae
  • Nachfolger 7ff07461

OpenDocument PDF Erzeugung: Xvfb wird nicht mehr gebraucht um libreoffice auf dem Server zu starten

- libreoffice wird mit --headless gestartet, das funktioniert auch ohne Xvfb, getestet auch mit openofficeorg_daemon Variante

Unterschiede anzeigen:

.gitignore
23 23
/users/templates-cache/
24 24
/users/templates-cache-for-tests/
25 25
/users/texmf/
26
/users/xvfb_display
27 26
/webdav/*
28 27
crm
29 28
pod2html*
SL/Helper/PrintOptions.pm
101 101
        if ($form->{media} ne 'email');
102 102

  
103 103
  push @FORMAT, grep $_,
104
    ($::lx_office_conf{print_templates}->{opendocument} &&     $::lx_office_conf{applications}->{openofficeorg_writer}  &&     $::lx_office_conf{applications}->{xvfb}
105
                                                        && (-x $::lx_office_conf{applications}->{openofficeorg_writer}) && (-x $::lx_office_conf{applications}->{xvfb})
106
     && !$options->{no_opendocument_pdf}) ?
104
    ($::lx_office_conf{print_templates}->{opendocument} &&     $::lx_office_conf{applications}->{openofficeorg_writer}
105
                                                        && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
106
                                                        && !$options->{no_opendocument_pdf}) ?
107 107
      opthash("opendocument_pdf",    $form->{DF}{"opendocument_pdf"},  $locale->text("PDF (OpenDocument/OASIS)")) : undef,
108 108
    ($::lx_office_conf{print_templates}->{latex}) ?
109 109
      opthash("pdf",                 $form->{DF}{pdf},                 $locale->text('PDF')) : undef,
SL/Template/OpenDocument.pm
582 582
  return $outfile;
583 583
}
584 584

  
585
sub is_xvfb_running {
586
  $main::lxdebug->enter_sub();
587

  
588
  my ($self) = @_;
589

  
590
  local *IN;
591
  my $dfname = $self->{"userspath"} . "/xvfb_display";
592
  my $display;
593

  
594
  $main::lxdebug->message(LXDebug->DEBUG2(), "    Looking for $dfname\n");
595
  if ((-f $dfname) && open(IN, $dfname)) {
596
    my $pid = <IN>;
597
    chomp($pid);
598
    $display = <IN>;
599
    chomp($display);
600
    my $xauthority = <IN>;
601
    chomp($xauthority);
602
    close(IN);
603

  
604
    $main::lxdebug->message(LXDebug->DEBUG2(), "      found with $pid and $display\n");
605

  
606
    if ((! -d "/proc/$pid") || !open(IN, "/proc/$pid/cmdline")) {
607
      $main::lxdebug->message(LXDebug->DEBUG2(), "  no/wrong process #1\n");
608
      unlink($dfname, $xauthority);
609
      $main::lxdebug->leave_sub();
610
      return undef;
611
    }
612
    my $line = <IN>;
613
    close(IN);
614
    if ($line !~ /xvfb/i) {
615
      $main::lxdebug->message(LXDebug->DEBUG2(), "      no/wrong process #2\n");
616
      unlink($dfname, $xauthority);
617
      $main::lxdebug->leave_sub();
618
      return undef;
619
    }
620

  
621
    $ENV{"XAUTHORITY"} = $xauthority;
622
    $ENV{"DISPLAY"} = $display;
623
  } else {
624
    $main::lxdebug->message(LXDebug->DEBUG2(), "      not found\n");
625
  }
626

  
627
  $main::lxdebug->leave_sub();
628

  
629
  return $display;
630
}
631

  
632
sub spawn_xvfb {
633
  $main::lxdebug->enter_sub();
634

  
635
  my ($self) = @_;
636

  
637
  $main::lxdebug->message(LXDebug->DEBUG2, "spawn_xvfb()\n");
638

  
639
  my $display = $self->is_xvfb_running();
640

  
641
  if ($display) {
642
    $main::lxdebug->leave_sub();
643
    return $display;
644
  }
645

  
646
  $display = 99;
647
  while ( -f "/tmp/.X${display}-lock") {
648
    $display++;
649
  }
650
  $display = ":${display}";
651
  $main::lxdebug->message(LXDebug->DEBUG2(), "  display $display\n");
652

  
653
  my $mcookie = `mcookie`;
654
  die("Installation error: mcookie not found.") if ($? != 0);
655
  chomp($mcookie);
656

  
657
  $main::lxdebug->message(LXDebug->DEBUG2(), "  mcookie $mcookie\n");
658

  
659
  my $xauthority = "/tmp/.Xauthority-" . $$ . "-" . time() . "-" . int(rand(9999999));
660
  $ENV{"XAUTHORITY"} = $xauthority;
661

  
662
  $main::lxdebug->message(LXDebug->DEBUG2(), "  xauthority $xauthority\n");
663

  
664
  if (system("xauth add \"${display}\" . \"${mcookie}\"") == -1) {
665
    die "system call to xauth failed: $!";
666
  }
667
  if ($? != 0) {
668
    $self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started (xauth: $!)";
669
    $main::lxdebug->leave_sub();
670
    return undef;
671
  }
672

  
673
  $main::lxdebug->message(LXDebug->DEBUG2(), "  about to fork()\n");
674

  
675
  my $pid = fork();
676
  if (0 == $pid) {
677
    $main::lxdebug->message(LXDebug->DEBUG2(), "  Child execing\n");
678
    exec($::lx_office_conf{applications}->{xvfb}, $display, "-screen", "0", "640x480x8", "-nolisten", "tcp");
679
  }
680
  sleep(3);
681
  $main::lxdebug->message(LXDebug->DEBUG2(), "  parent dont sleeping\n");
682

  
683
  local *OUT;
684
  my $dfname = $self->{"userspath"} . "/xvfb_display";
685
  if (!open(OUT, ">", $dfname)) {
686
    $self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started ($dfname: $!)";
687
    unlink($xauthority);
688
    kill($pid);
689
    $main::lxdebug->leave_sub();
690
    return undef;
691
  }
692
  print(OUT "$pid\n$display\n$xauthority\n");
693
  close(OUT);
694

  
695
  $main::lxdebug->message(LXDebug->DEBUG2(), "  parent re-testing\n");
696

  
697
  if (!$self->is_xvfb_running()) {
698
    $self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started.";
699
    unlink($xauthority, $dfname);
700
    kill($pid);
701
    $main::lxdebug->leave_sub();
702
    return undef;
703
  }
704

  
705
  $main::lxdebug->message(LXDebug->DEBUG2(), "  spawn OK\n");
706

  
707
  $main::lxdebug->leave_sub();
708

  
709
  return $display;
710
}
711

  
712 585
sub _run_python_uno {
713 586
  my ($self, @args) = @_;
714 587

  
......
820 693
    $ENV{'HOME'} = getcwd() . "/" . $self->{"userspath"};
821 694
  }
822 695

  
823
  if (!$self->spawn_xvfb()) {
824
    $main::lxdebug->leave_sub();
825
    return 0;
826
  }
827

  
828 696
  if (!$::lx_office_conf{print_templates}->{openofficeorg_daemon}) {
829 697
    if (system($::lx_office_conf{applications}->{openofficeorg_writer},
830 698
               "--minimized", "--norestore", "--nologo", "--nolockcheck", "--headless",
bin/mozilla/am.pl
582 582

  
583 583
  my @formats = ();
584 584
  if ($::lx_office_conf{print_templates}->{opendocument}
585
      && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
586
      && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
585
      && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})) {
587 586
    push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
588 587
                     "value" => "opendocument_pdf" });
589 588
  }
config/kivitendo.conf.default
158 158
[applications]
159 159
# Location of OpenOffice.org writer
160 160
openofficeorg_writer = oowriter
161
# Location of the X virtual frame buffer used for OpenOffice
162
xvfb = Xvfb
163 161
# Location of the html2ps binary
164 162
html2ps = html2ps
165 163
# Location of the Ghostscript binary

Auch abrufbar als: Unified diff