Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem on CentOS Stream 9 - OCRmyPDF succeeded with warning(s): sh: line 1: ocrmypdf: command not found, #203

Closed
mrojrti opened this issue May 17, 2023 · 6 comments

Comments

@mrojrti
Copy link

mrojrti commented May 17, 2023

When I try to install ocrmypdf via dnf/yum the packet was not found on the repository even epel installed.

Tried via Snap and Pip but I get the same error above on Nextlocu log:
Screenshot 2023-05-16 at 22 09 30

Can you help me, please?

Thank you

@R0Wi
Copy link
Contributor

R0Wi commented May 17, 2023

Hi @mrojrti, I can't immediately tell you what's wrong but I'd suggest you try the following steps to get closer to a solution:

  1. Login to your server with your regular user (or root) and check if ocrmypdf --help produces any reasonable output. If not, it seems like the installation is somehow completely broken on your system.
  2. Since OCR jobs are executed asynchronously via NC cron: check the way your Nextcloud cron is executed. If it's triggered via system cron, check which user executes the cron.php script. If it's executed via Webcron or Ajax, the user will be the same one running your webserver (in that case, check who is executing apache2 / httpd). If you identified the system user executing your NC cron, open a new shell for that user and try step 1 again (for example sudo -u www-data bash and then again ocrmypdf --help). If that works, everything should be fine. If not, the executing user of the NC cron doesn't have access to the ocrmypdf binary. Try to make it accessible globally on your system by putting the directory where the ocrmypdf binary resides into your PATH or try something else so that this user can properly execute the ocrmypdf command

Hope this helps!

@mrojrti
Copy link
Author

mrojrti commented May 19, 2023

Hi @R0Wi !

All right, I redo some tests and the user apache on terminal can't run the commando ocrmypdf, returns command not found.
When I tried the cron with root, I get this message on log:
Screenshot 2023-05-19 at 18 42 58

So I do: crontab -u apache -e and add: */1 * * * * php -f /var/www/html/cron.php
Now no errors on cron log:
Screenshot 2023-05-19 at 18 45 16

When I run the sudo -u apache ocrmypdf the command returns ok (I change a security configuration on sudoers to get this work)
Screenshot 2023-05-19 at 18 46 35

But still not working on Nextcloud, command not found =(

Screenshot 2023-05-19 at 18 49 46

I managed to get the command work on apacher user, but I don't know how to proceed now, can you help?
Any idea?

Thank you so much.

@R0Wi
Copy link
Contributor

R0Wi commented May 20, 2023

That really sounds like a taff one 😄

To get closer to a solution I'd not work with the crontab but instead call cron.php directly, think it's better for debugging. So:

  1. Make sure your NC cron is configured to cron
  2. Make sure the apache crontab is the only one with something like php -f /var/www/html/cron.php, so that really nothing else executes the cron.php
  3. Remove or comment out the crontab entry for apache for the time debugging
  4. Upload a new file which matches your OCR flow
  5. Open a new console and change your user to apache (sudo -u apache bash) then execute php -f /var/www/html/cron.php.
  6. Inspect the logs
  7. Don't forget to uncomment the crontab after testing

It would also be interesting to know where exactly the ocrmypdf binary resides on your system, because it has to be somewhere, where not every user has access to or doesn't have this location in his PATH. With a user where the ocrmypdf command succeeds, execute whereis ocrmypdf. On my system I get something like:

docker@489f65697e04:/var/www/html$ whereis ocrmypdf
ocrmypdf: /usr/bin/ocrmypdf

So you see it's below /usr/bin, which is part of the system PATH variable. If that's not the case on your system, another approach would be to create a symlink under /usr/bin which points to ocrmypdf (something like ln -s <your-path> /usr/bin/ocrmypdf). This should make the command globally available.

Good luck!

@mrojrti
Copy link
Author

mrojrti commented May 21, 2023

Hi, @R0Wi
I hope you're well.

Finally, it works!!!

1 - The cron config was ok.
2 - Yes, it was the only one
3 to 7 - On this test the problem continue.

Executing whereis ocrmypdf the result was the expected and I had the symbolic link to.

Resolution:
I put the crontab on the root user, but with sudo -u to apache, like this
*/5 * * * * sudo -u apache php -f /var/www/html/cron.php

Now it's working like a charm.

Thank you so much for your attention!

@R0Wi
Copy link
Contributor

R0Wi commented May 21, 2023

Happy to hear things are working now. Sounds to me indeed like in some situations the apache users PATH isn't setup correctly. Good to know 👍

@R0Wi R0Wi closed this as completed May 21, 2023
@mrojrti
Copy link
Author

mrojrti commented May 21, 2023

Yes, I forgot 1 step that I did
As root I ran visudo and add the path /usr/local/bin of ocrmypdf to secure_path.

Screenshot 2023-05-21 at 08 24 12

Thank you!

@R0Wi R0Wi mentioned this issue Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants