Service Startup Error with --api-keys

I installed libretranslate using pip. Got it running under Ubuntu 20.04 both on the command line and as a service under systemd. I want to add api keys. When I add the --api-keys and run it on the command line it works fine. When I try to run it with --api-keys as a service it errors.

Invocation line in /etc/systemd/system/libretranslate.service:
/usr/local/bin/libretranslate --host --api-keys

Errors produced when I tail /var/log/syslog:
Cannot update models (normal if you’re offline): module ‘app.language’ has no attribute ‘languages’
Traceback (most recent call last):
File “/usr/local/bin/libretranslate”, line 8, in
File “/usr/local/lib/python3.8/dist-packages/app/”, line 121, in main
app = create_app(args)
File “/usr/local/lib/python3.8/dist-packages/app/”, line 149, in create_app
api_keys_db = Database() if args.api_keys else None
File “/usr/local/lib/python3.8/dist-packages/app/”, line 15, in init
self.c = sqlite3.connect(db_path, check_same_thread=False)
sqlite3.OperationalError: unable to open database file

Anyone have any ideas why it can’t open the database when run as a service?

1 Like

It looks like it’s failing to access the SQLite database file, is it possible the user used by systemd doesn’t have permission to access the file?

If you’re using the LibreTranslate-init script systemd uses a libretranslate user that may be different than the one you created the database file with.

Could also be the permissions on the working directory.

1 Like

I’m running the service as the same user that I use when testing it on the command line.

Here’s the service file

Description=libretranslate service

#ExecStart=/usr/local/bin/libretranslate --host
ExecStart=/usr/local/bin/libretranslate --host --api-keys

1 Like