Certbot-renewal.service: Failed with result 'exit-code

As continuation of my yesterday’s help request : How to be sure that the automatic certificates renewal process is correctly set? Ubuntu 18.04.02 Server
I executed this command journalctl -u certbot-renewal.service
the last lines of the output are :

Aug 03 11:22:01 pc systemd[1]: Started Certbot Renewal.
Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 3: __requires__: command not found
Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 4: import: command not found
Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 5: import: command not found
Aug 03 11:22:01 pc bash[1857]: from: can't read /var/mail/pkg_resources
Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 9: syntax error near unexpected token `('
Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 9: `    sys.argv[0] = re.sub(r'(-script\.pyw?|
  \.exe)?$', '', sys.argv[0])'
Aug 03 11:22:01 pc systemd[1]: certbot-renewal.service: Main process exited, code=exited, 
  status=2/INVALIDARGUMENT
Aug 03 11:22:01 pc systemd[1]: certbot-renewal.service: Failed with result 'exit-code'.


marco@pc:/etc/systemd/system$ sudo systemctl status certbot 
● certbot.service - Certbot
   Loaded: loaded (/lib/systemd/system/certbot.service; static; vendor preset: enabled)
   Active: inactive (dead) since Sat 2019-08-03 11:16:09 CEST; 14min ago
     Docs: file:///usr/share/doc/python-certbot-doc/html/index.html
           https://letsencrypt.readthedocs.io/en/latest/
  Process: 979 ExecStart=/usr/bin/certbot -q renew (code=exited, status=0/SUCCESS)
  Main PID: 979 (code=exited, status=0/SUCCESS)

 Aug 03 11:16:09 pc systemd[1]: Starting Certbot...
Aug 03 11:16:09 pc systemd[1]: Started Certbot.

marco@pc:/etc/systemd/system$ sudo certbot renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log
-------------------------------------------------------------------------------
No renewals were attempted.
-------------------------------------------------------------------------------
marco@pc:/etc/systemd/system$ 

How to solve the problem?
Looking forward to your kind help.
Marco

Evidently Certbot is being executed by bash instead of Python.

Why I don’t know…

Can you post “head /usr/bin/certbot”?

Why are you creating a certbot-renewal service, though? One named certbot is already installed, isn’t it?

Edit: And what do “systemctl status certbot-renewal” and “systemctl cat certbot-renewal” show?

Edit: According to your previous post, you added /bin/bash to ExecStart. That is why you’re getting this error message.

@mnordhoff Thanks Matt for helping !!

  1. Can you post “head /usr/bin/certbot”?

     marco@pc:/etc/systemd/system$ head /usr/bin/certbot
     #!/usr/bin/python3
     # EASY-INSTALL-ENTRY-SCRIPT: 'certbot==0.23.0','console_scripts','certbot'
     __requires__ = 'certbot==0.23.0'
     import re
     import sys
     from pkg_resources import load_entry_point
    
     if __name__ == '__main__':
         sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
         sys.exit(
    

2.a) Why are you creating a certbot-renewal service, though?
As far as I understood Ubuntu uses systemd as its init system. So I followed the indications found
here: https://stevenwestmoreland.com/2017/11/renewing-certbot-certificates-using-a-systemd-
timer.html
2.b) One named certbot is already installed, isn’t it?
How and where to check if one named ‘certobot’ is already installed?

  1. And what do “ systemctl status certbot-renewal ” and “ systemctl cat certbot-renewal ” show?
    3.a)
    marco@pc:/etc/systemd/system$ systemctl status certbot-renewal
    ● certbot-renewal.service - Certbot Renewal
    Loaded: loaded (/etc/systemd/system/certbot-renewal.service; static; vendor preset: enabled)
    Active: failed (Result: exit-code) since Sat 2019-08-03 11:22:01 CEST; 1h 38min ago
    Process: 1857 ExecStart=/bin/bash /usr/bin/certbot renew --post-hook systemctl restart httpd
    (code=exited, status=2)
    Main PID: 1857 (code=exited, status=2)

      Aug 03 11:22:01 pc systemd[1]: Started Certbot Renewal.
      Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 3: __requires__: command not found
      Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 4: import: command not found
      Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 5: import: command not found
      Aug 03 11:22:01 pc bash[1857]: from: can't read /var/mail/pkg_resources
      Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 9: syntax error near unexpected token `('
      Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 9: `    sys.argv[0] = re.sub(r'(-script\.pyw?|
        \.exe)?$', '', sys.argv[0])'
      Aug 03 11:22:01 pc systemd[1]: certbot-renewal.service: Main process exited, code=exited, 
        status=2/INVALIDARGUMENT
      Aug 03 11:22:01 pc systemd[1]: certbot-renewal.service: Failed with result 'exit-code'.
    

3.b)

    marco@pc:/etc/systemd/system$ systemctl cat certbot-renewal
    # /etc/systemd/system/certbot-renewal.service

    [Unit]
    Description=Certbot Renewal

    [Service]
    ExecStart= ExecStart=/usr/bin/certbot renew --post-hook "systemctl restart httpd"

After removing /bin/bash to ExecStart and daemon-reloading ( systemctl daemon-reload) :

  marco@pc:/etc/systemd/system$ systemctl status certbot-renewal
  ● certbot-renewal.service - Certbot Renewal
     Loaded: loaded (/etc/systemd/system/certbot-renewal.service; static; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2019-08-03 11:22:01 CEST; 1h 43min ago
   Main PID: 1857 (code=exited, status=2)

  Aug 03 11:22:01 pc systemd[1]: Started Certbot Renewal.
  Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 3: __requires__: command not found
  Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 4: import: command not found
  Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 5: import: command not found
  Aug 03 11:22:01 pc bash[1857]: from: can't read /var/mail/pkg_resources
  Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 9: syntax error near unexpected token `('
  Aug 03 11:22:01 pc bash[1857]: /usr/bin/certbot: line 9: `    sys.argv[0] = re.sub(r'(-script\.pyw?|
  \.exe)?$', '', sys.argv[0])'
  Aug 03 11:22:01 pc systemd[1]: certbot-renewal.service: Main process exited, code=exited, 
  status=2/INVALIDARGUMENT
  Aug 03 11:22:01 pc systemd[1]: certbot-renewal.service: Failed with result 'exit-code'.

@mnordhoff what can be wrong with /usr/bin/certbot ?
sudo nano /usr/bin/certbot :

#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'certbot==0.23.0','console_scripts','certbot'
__requires__ = 'certbot==0.23.0'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('certbot==0.23.0', 'console_scripts', 'certbot')()
    )

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.