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

[Linux] Switch systemd service unit to EnvironmentFile and start providing it in the repository instead #3516

Open
C0rn3j opened this issue Apr 6, 2024 · 0 comments

Comments

@C0rn3j
Copy link

C0rn3j commented Apr 6, 2024

What are you trying to do?

Run Llama service on Linux via systemd and being able to configure it without unit overrides through a configuration file.

How should we solve this?

Stop using Environment, use EnvironmentFile instead in

ollama/scripts/install.sh

Lines 100 to 116 in cb03fc9

status "Creating ollama systemd service..."
cat <<EOF | $SUDO tee /etc/systemd/system/ollama.service >/dev/null
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=$BINDIR/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"
[Install]
WantedBy=default.target
EOF

https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#EnvironmentFile=

Edit documentation accordingly - https://github.com/ollama/ollama/blob/main/docs/faq.md#setting-environment-variables-on-linux

Stop carrying the unit file in install.sh, add it to the repository, this allows distributions to cleanly package the unit.

Download the new configuration file as /etc/ollama.conf.example and if /etc/ollama.conf does not exist, copy the example there, otherwise keep user configuration intact.

[Service]
EnvironmentFile=/etc/ollama.conf

This also allows for having all of the options in the configuration neatly visible, instead of having to wade through help/documentation for simple things.

Example config of mine:

# /etc/ollama.conf

# The host:port to bind to (default "127.0.0.1:11434")
OLLAMA_HOST=0.0.0.0:11434           

# A comma separated list of allowed origins.
OLLAMA_ORIGINS=*://localhost,*://192.168.1.40,*://192.168.1.10

# The path to the models directory (default is "~/.ollama/models")
OLLAMA_MODELS=/models/ollama

HOME=/var/lib/ollama
GIN_MODE=release

What is the impact of not solving this?

Distribution packaging is hard and configuration of ollama has to be done by overriding systemd units.

Anything else?

Adapting hardening from the Arch Linux unit might be a good idea, already saw people in this repository trying to give Ollama permissions to their home folders which the unit prevents.

https://gitlab.archlinux.org/archlinux/packaging/packages/ollama/-/blob/7418e63fb87fd43277a6051466325081680d1627/ollama.service

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