Skip to content

Instantly share code, notes, and snippets.

@udomsak
Created May 6, 2021 04:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udomsak/218bc926075a771192dabd7cda31bf15 to your computer and use it in GitHub Desktop.
Save udomsak/218bc926075a771192dabd7cda31bf15 to your computer and use it in GitHub Desktop.
loki systemd unit file for ubuntu 18.04
[Unit]
Description=Loki service
After=network.target
[Service]
Type=simple
User=loki
ExecStart=/usr/local/bin/loki --config.file /etc/grafana/loki/loki-local-config.yaml
[Install]
WantedBy=multi-user.target
@udomsak
Copy link
Author

udomsak commented May 6, 2021

Pre-pare and configure Loki on Grafana server.

#Default loki running with BoltDB and store on file system -> /tmp
wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml

#Download loki from release page. github
https://github.com/grafana/loki/releases

#this note use 2.2.1
curl -O -L "https://github.com/grafana/loki/releases/download/v2.2.1/loki-linux-amd64.zip"
mkdir -pv /etc/grafana/loki
cp loki-local-config.yaml /etc/grafana/loki/
sudo useradd --system loki
sudo vim  /etc/systemd/system/loki.service
# test 
sudo -s
su loki -c '/usr/local/bin/loki --config.file  /etc/grafana/loki/loki-local-config.yaml'

#Apply configuration
systemctl daemon-reload
systemctl enable loki
systemctl start loki
systemctl status loki

@Eli-Tarrago
Copy link

Currently, this is my version of the systemd unit file:

[Unit]
Description = loki server service
After = network-online.target
After = syslog.target

[Service]
Type = simple
User = loki
Group = loki
ExecStart = /opt/loki/loki-linux-amd64 -config.file=/opt/loki/loki-local-config.yaml -log.level=info -server.log-source-ips-enabled=true
ExecReload = /bin/kill -HUP $MAINPID
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec = 120
Restart = on-failure
RestartSec = 2
# This creates a specific slice which all services will operate from
#  The accounting options give us the ability to see resource usage through
#  the `systemd-cgtop` command.
Slice = loki.slice
# Set Accounting
CPUAccounting = True
BlockIOAccounting = True
MemoryAccounting = True
TasksAccounting = True
# Set Sandboxing
PrivateTmp = True
PrivateDevices = False
PrivateNetwork = False

[Install]
WantedBy = multi-user.target

@m-rtijn
Copy link

m-rtijn commented Mar 27, 2023

Thanks for sharing this. I had one question: what is the purpose of enabling systemd resource accounting if you are not setting any quota's, restrictions or caps on CPU/IO/memory usage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment