1

I have a python file to update an A-Record on my CPanel web host. It imports a module named cpanelapi which is located in the same directory as the ddns.py file.

When I execute ddns.py from the command line /usr/bin/python ddns.py it runs correctly with no errors. However when run from systemd or crontab it fails with ImportError: No module named cpanelapi.

This is the systemd file:

[Unit]
Description=Update A-Record
AssertPathExists=/home/ethan/cpanel-ddns-client
After=network.target

[Service]
Type=simple
User=ethan
WorkingDirectory=/home/ethan/cpanel-ddns-client
ExecStart=/usr/bin/python /home/ethan/cpanel-ddns-client/ddns.py

[Install]
WantedBy=multi-user.target

The script is located at cpanel-ddns-client/ddns.py and the module is located at cpanel-ddns-client/cpanelapi.

I have tried adding the cpanel-ddns-client folder to sys.path which did not work.

  • 1
    Does env - /usr/bin/python ddns.py work in the shell? – Hauke Laging Jun 10 '18 at 14:33
  • @HaukeLaging No, it crashes with an import error – Ethan Brews Jun 10 '18 at 17:33
  • Then the reason for your problem is one or more environment variables which are set in your shell but not by cron or systemd. You have to identify those, then you can configure them for the daemons. – Hauke Laging Jun 10 '18 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.