KnpSnappyBundle - stderr: "wkhtmltopdf: cannot connect to X server " stdout: "" - symfony

I'm trying to use the KnpSnappyBundle to create PDF files from twig templates.
I've followed this post to install wkhtmltopdf and it works when I do:
wkhtmltopdf http://www.google.com test.pdf
but when I try to create a PDF file from a controller:
$this->get('knp_snappy.pdf')->generateFromHtml(
$this->renderView('AcmePDFBundle:Default:template.html.twig'),
'../app/var/PDFfiles/PDF.pdf'
);
I'm getting this error:
request.CRITICAL: RuntimeException: The exit status code '1' says something went wrong:
stderr: "wkhtmltopdf: cannot connect to X server
"
stdout: ""
command: /usr/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy532ca2272fba44.73835084.html' '../app/var/files/PDF.pdf'. (uncaught exception) at /home/me/MyServer/project/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php line 304 [] []
Any idea of how to solve it?
This is my configuration for KnpSnappyBundle:
knp_snappy:
pdf:
enabled: true
binary: /usr/bin/wkhtmltopdf
options: []
image:
enabled: false
binary: /usr/bin/wkhtmltoimage
options: []

Resolved installing a precompiled version. now you can get your version from here (inspired by this out of date answer ):
http://wkhtmltopdf.org/downloads.html
and changed my config.yml to:
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
image:
enabled: false
binary: /usr/local/bin/wkhtmltoimage
options: []
and now it works!

You must copy it into directory : /usr/local/bin, make sur it's executable and add symlink of wkhtmltopdf.sh like :
1- the command :
sudo apt-get install wkhtmltopdf
2 - insert the binary in directory /usr/bin so the browser can't have permission to execute in this directory.
You must copy the wkhtmltopdf.sh to directory /usr/local/bin cause the browser have permission in this directory like:
sudo cp /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf.sh
3 - After make sur the binary have permission of execution like :
sudo chmod a+x /usr/local/bin/wkhtmltopdf.sh
4 - so now you can test, it's work like:
/usr/local/bin/wkhtmltopdf.sh http://www.google.com google.pdf
it make download the pdf in the current directory in your terminal
5 - Optional
now you can add symlink in your directory /usr/local/bin like
ln -s /usr/local/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
6 - copy to the /usr/bin/wkhtmltoimage into /usr/local/bin/wkhtmltoimage like:
sudo cp usr/local/wkhtmltoimage usr/local/bin/wkhtmltoimage
8- make sur this is executable too:
sudo chmod a+x /usr/local/bin/wkhtmltoimage
7 - change the directory of binary in configuration of symfony in config/packages/knp_snappy.yaml :
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
image:
enabled: false
binary: /usr/local/bin/wkhtmltoimage
options: []
I Hope it's help you

Related

Env variable not found by R in Azure Pipeline

I'm trying to convert my Travis-based tests to Azure Pipelines, and I'm running into a problem where R doesn't seem to pick up an environment variable.
Here is the yaml:
trigger:
- master
variables:
- group: GH
- name: R_LIBS_USER
value: '$(Agent.BuildDirectory)/R/library'
- name: containerImage
value: rocker/rstudio:latest
pool:
vmImage: 'ubuntu-latest'
container: rocker/rstudio:latest
steps:
- script: |
echo 'options(repos = "https://cloud.r-project.org")' > ~/.Rprofile
mkdir -p ${R_LIBS_USER}
displayName: 'Setup R library directory'
- bash: |
Rscript -e "install.packages(c('remotes', 'rcmdcheck'))" <-- problem here
Rscript -e "remotes::install_deps(dependencies=TRUE)"
displayName: 'Installing package dependencies'
- bash: |
Rscript -e "rcmdcheck::rcmdcheck(args = '--no-manual', error_on = 'error', check_dir = 'check')"
displayName: 'Checking package'
The problem is in the bash step where I install the remotes and rcmdcheck packages, and then run install_deps. For some reason R doesn't see the R_LIBS_USER variable, which should expand to something like /__w/1/R/library. Because of this, it tries to install to the site-wide location /usr/local/lib/R/site-library, which fails because this directory is not user-writeable.
What's happening here?
For whatever reason, R just can't see the environment variable R_LIBS_USER. What finally worked for me was editing the ~/.Rprofile config file to include the user library directory:
steps:
- script: |
echo 'options(repos = "https://cloud.r-project.org")' > ~/.Rprofile
echo ".libPaths(c('$R_LIBS_USER', .libPaths()))" >> ~/.Rprofile
mkdir -p $(R_LIBS_USER)
displayName: 'Setup R library directory'
Now I just need to figure out how to avoid reinstalling several megabytes of dependencies on each run....

SonarQube with Travis not showing issues on dot net core 2 project

I have a simple dotnet core 2.0 project with a simple issue which is failing SonarLint with an unused variable issue.
The code is stored in a public github repository (here). A travis job (here) runs and has the SonarQube plugin and should post to SonarCloud (here).
The problem I have is that this issue is not being picked up by the analysis and published as an issue. I obviously have something set up incorrectly but I dont know what.
My .travis.yml is below
language: csharp
dist: xenial
sudo: required
mono: none
dotnet: 2.0.0
solution: Dibware.Salon.sln
addons:
sonarcloud:
organization: "dibley1973-github" # the key of the org you chose at step #3
token:
secure: $SONAR_TOKEN
branches:
only:
- master
before_script:
- chmod +x build.sh
- chmod +x run-tests.sh
script:
- ./build.sh
- ./run-tests.sh
- sonar-scanner
My sonar-project.properties file is below
# Project identification
sonar.projectKey=Core:Dibware.Salon
sonar.projectVersion=1.0.0.0
sonar.projectName=Dibware.Salon
# Info required for SonarQube
sonar.sources=./Domain
sonar.language=cs
sonar.sourceEncoding=UTF-8
C# Settings
sonar.dotnet.visualstudio.solution=Dibware.Salon.sln
# MSBuild
sonar.dotnet.buildConfiguration=Release
sonar.dotnet.buildPlatform=Any CPU
# StyleCop
sonar.stylecop.mode=
# SCM
sonar.scm.enabled=false
In the travis log I do have:
INFO: 27 files to be analyzed
WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: 0/27 files analyzed
WARN: Missing blame information for the following files:
WARN: *
.
<lots of files>
.
WARN: This may lead to missing/broken features in SonarQube
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 216ms, dir size=381 KB
INFO: Analysis report compressed in 56ms, zip size=89 KB
INFO: Analysis report uploaded in 340ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=Core%3ADibware.Salon
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWo0YQeAUanQDuOXxh79
INFO: Analysis total time: 11.484 s
Is this what is affecting the analysis? If so how do I resolve it? If not what else is stopping the analysis of the files, please?
EDIT:
I can see the following in the log, but it still does not get picked up by SoanrQube..
Chair.cs(17,17): warning CS0219: The variable 'a' is assigned but its value is never used
Edit 2:
I managed to getthe analzed number to go up, see below...
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=6ms
INFO: SCM provider for this project is: git
INFO: 27 files to be analyzed
INFO: 27/27 files analyzed
INFO: Calculating CPD for 0 files
... using the following in my .travis.yml
install:
- git fetch --unshallow --tags
That came from here:
https://stackoverflow.com/a/47441734/254215
Ok, I am not out of the wood yet, but am getting some analysis using the following .travis.yml
language: csharp
dist: xenial
sudo: required
mono: none
dotnet: 2.1.300
solution: Dibware.Salon.sln
addons:
sonarcloud:
organization: "dibley1973-github" # the key of the org you chose at step #3
token:
secure: $SONAR_TOKEN
branches:
only:
- master
install:
- dotnet tool install --global dotnet-sonarscanner
- git fetch --unshallow --tags
before_script:
- export PATH="$PATH:$HOME/.dotnet/tools"
- chmod +x build.sh
- chmod +x run-tests.sh
script:
- dotnet sonarscanner begin /k:"Core:Dibware.Salon" /d:sonar.login="$SONAR_TOKEN" /d:sonar.exclusions="**/bin/**/*,**/obj/**/*" /d:sonar.cs.opencover.reportsPaths="lcov.opencover.xml" || true
- ./build.sh
- ./run-tests.sh
- dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN" || true
In the end the travis.yml file I used which worked is this:
language: csharp
dist: xenial
sudo: required
mono: none
dotnet: 2.1.300
solution: Dibware.Salon.sln
addons:
sonarcloud:
organization: "dibley1973-github" # the key of the org you chose at step #3
token:
secure: $SONAR_TOKEN
branches:
only:
- master
install:
- dotnet tool install --global dotnet-sonarscanner
- git fetch --unshallow --tags
before_script:
- export PATH="$PATH:$HOME/.dotnet/tools"
- chmod +x build.sh
- chmod +x run-tests.sh
script:
- dotnet sonarscanner begin /k:"Core:Dibware.Salon" /d:sonar.login="$SONAR_TOKEN" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" /d:sonar.exclusions="**/bin/**/*,**/obj/**/*,**/Dibware.Salon.Web/**/*" || true
- ./build.sh
- ./run-tests.sh
- dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN" || true
The build file is this.
#!/usr/bin/env bash
dotnet restore
dotnet clean -c Release
dotnet build Dibware.Salon.sln -c Release
The test is this.
# Run the tests and collate code coverage results
dotnet test -c Release --no-build --no-restore Domain/SharedKernel/Dibware.Salon.Domain.SharedKernel.UnitTests/Dibware.Salon.Domain.SharedKernel.UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
I did not use a sonar-project.properties file.
HTH someone, one day

Permission issues with external ntfs HDD, gitlab-ctl reconfigure changing permissions: "Operation not permitted"

I'm using gitlab on a rasberry pi model 3 B. Following some information about my setup (sudo gitlab-rake gitlab:env:info):
System information
System: Raspbian 8.0
Current User: git
Using RVM: no
Ruby Version: 2.3.6p384
Gem Version: 2.6.13
Bundler Version:1.13.7
Rake Version: 12.3.0
Redis Version: 3.2.11
Git Version: 2.14.3
Sidekiq Version:5.0.5
Go Version: go1.3.3 linux/arm
GitLab information
Version: 10.6.0-rc3
Revision: 52fa89e
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: http://gitlab.example.com
HTTP Clone URL: http://gitlab.example.com/some-group/some-project.git
SSH Clone URL: git#gitlab.example.com:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 6.0.3
Repository storage paths:
- default: /mnt/SeagateExpansion/GitLab/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks
Git: /opt/gitlab/embedded/bin/git
After the gitlab update to version 10.6.0 I need to change the url again but when I do the necessary changes in /etc/gitlab/gitlab.rb and run sudo nano gitlab-ctl reconfigure I get the following error messages:
========================================================================
Error executing action `run` on resource 'ruby_block[directory resource:
/mnt/SeagateExpansion/GitLab]'
========================================================================
and
============================================================================
Error executing action `create` on resource
'storage_directory[/mnt/SeagateExpansion/GitLab]'
============================================================================
The result message says:
There was an error running gitlab-ctl reconfigure:
storage_directory[/mnt/SeagateExpansion/GitLab] (gitlab::gitlab-rails line 42) had an error: Mixlib::ShellOut::ShellCommandFailed: ruby_block[directory resource: /mnt/SeagateExpansion/GitLab] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/resources/storage_directory.rb line 33) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of chmod 00700 /mnt/SeagateExpansion/GitLab ----
STDOUT:
STDERR: chmod: changing permissions of ‘/mnt/SeagateExpansion/GitLab’: Operation not permitted
---- End output of chmod 00700 /mnt/SeagateExpansion/GitLab ----
Ran chmod 00700 /mnt/SeagateExpansion/GitLab returned 1
So the problem seems to be, that the execution of the run and create command on the resource storage (GitLab folder on the external HDD [HDD = SeagateExpansion]) expects the permissions to be 700, right?
According to this errors I tried to change the permission of
the external HDD folder /mnt/SeagateExpansion/GitLab see the ls -l output:
drwxrwxrwx 1 root GitLabUser 0 Jan 4 17:55 GitLab
With the help of this post I tried to change the permission with the command:
sudo find /mnt/SeagateExpansion/GitLab -type d -exec chmod 700 {} \;
to the required permission 700. But the changes don't take affect. I also tried chmod -R 700 /mnt/SeagateExpansion/GitLab and executed the commands as root but the changes don't take effect. Even after restarting the raspberry pi. What am I doing wrong?
I also tried to change the options settings/flag of the HDD in /etc/fstab to user but this doesn't help ether.
I'm thankful for every hint and answer :).
Best regards,
Bredjo
I finally figured it out. The solution is to change the mount settings in the /etc/fstab. Because if you have the wrong options settings (see: https://en.wikipedia.org/wiki/Fstab) you are not able to change the permissions because its a ntfs filesystem.
So my old fstab entry was this:
UUID=FE820568820526AD /mnt/SeagateExpansion ntfs defaults,gid=GitLabUser 0 0
And the new entry is this:
UUID=FE820568820526AD /mnt/SeagateExpansion ntfs-3g permissions 0 0
Note that you need to install ntfs-3g to use it in fstab. And the permissions options only comes with ntfs-3g. See: https://www.tuxera.com/community/ntfs-3g-advanced/ownership-and-permissions/
After this change I executed again:
sudo gitlab-ctl reconfigure
Now the error disappeared and the permission 700 of the folder /mnt/SeagateExpansion/GitLab could be set. I also noticed that the owner of the GitLab folder was also changed to user git after the reconfiguration:
drwx------ 1 git root 0 Jan 4 17:55 GitLab
That's because I don't need the option gid=GitLabUserany more.
Now everything works again :).

KnpSnappyBundle - wkhtmltopdf.exe.bat: Permission denied

In dev environment (windows) using xampp my pdf files are generated successfully, but in prod (linux):
string(545) "The exit status code '126' says something went wrong:
stderr: "sh: /home/trainingexperience/beta.trainingexperience.org/app/../bin/wkhtmltopdf.exe.bat: Permission denied"
stdout: ""
command: /home/trainingexperience/beta.trainingexperience.org/app/../bin/wkhtmltopdf.exe.bat --lowquality --encoding 'utf-8' '/home/trainingexperience/beta.trainingexperience.org/app/cache/prod/snappy/knp_snappy5936b3644fdf62.71499624.html' '/home/trainingexperience/beta.trainingexperience.org/app/../web/uploads/company/payments/test_cXrfA4L99zsiKi6Cfl5a.pdf'."
My config:
knp_snappy:
pdf:
binary: %kernel.root_dir%/../bin/wkhtmltopdf.exe.bat
temporary_folder: %kernel.cache_dir%/snappy
Could it be because of Linux? What is the problem?
UPDATE
I tried:
knp_snappy:
pdf:
binary: %kernel.root_dir%/../bin/wkhtmltopdf
temporary_folder: %kernel.cache_dir%/snappy
I got:
No such file or directory
I think could be the problem (composer.json): "wemersonjanuario/wkhtmltopdf-windows": "0.12.2.3". Is there a version to that could work on windows and linux at the same time?
You should define a shell executable for your production environement and your developement environment.
for linux
binary: /usr/local/bin/wkhtmltopdf
for windows
binary: "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\\"
as you can see, You can't sh (execute) a .bat file on linux.

Simple dotfiles install in zsh

How do I symlink all dotfiles on a dir to my home dir using zsh? i.e. I have a dir with .gitconfig in it, and I'd like to symlink it to ~/.gitconfig.
Thanks!
If you want the sym-links at your local dir to your home dir:
cd my-own-local-dir
for ifile in .*(.); do # notice the '(.)' matching only normal files
# rm -fv $ifile # COMMENTED OUT, removing the original...
ln -vs ~/$ifile $ifile # sym-links to your home dir...
done
You should try dotbot. It supports to manage dotfiles by using a yaml file. Easy for mapping :D
For example:
- link:
~/.config/terminator:
create: true
path: config/terminator
~/.vim: vim
~/.vimrc:
relink: true
path: vimrc
~/.zshrc:
force: true
path: zshrc

Resources