To run ./loki-linux-amd64
with the --config.file=loki-config.yaml
flag in the background, you can use similar approaches as with Prometheus. Here’s how you can do it:
Run the Loki process in the background using &
:
./loki-linux-amd64 --config.file=loki-config.yaml &
Use nohup
to ensure the process continues running even if the terminal is closed:
nohup ./loki-linux-amd64 --config.file=loki-config.yaml > loki.log 2>&1 &
nohup
: Prevents the process from being terminated when the terminal session ends.> loki.log
: Redirects standard output toloki.log
.2>&1
: Redirects standard error to the same file as standard output.
Run Loki in a session manager for better control.
- Start a new session:
screen -S loki
- Run the command:
./loki-linux-amd64 --config.file=loki-config.yaml
- Detach the session by pressing
Ctrl+A
, thenD
. - Reattach the session later with:
screen -r loki
- Start a new tmux session:
tmux new -s loki
- Run the command:
./loki-linux-amd64 --config.file=loki-config.yaml
- Detach the session by pressing
Ctrl+B
, thenD
. - Reattach the session later with:
tmux attach -t loki
Set up Loki as a service for consistent and reliable management.
-
Create a new service file:
sudo nano /etc/systemd/system/loki.service
-
Add the following content:
[Unit] Description=Loki Service After=network.target [Service] ExecStart=/path/to/loki-linux-amd64 --config.file=/path/to/loki-config.yaml WorkingDirectory=/path/to Restart=always User=your_user Group=your_group [Install] WantedBy=multi-user.target
-
Replace
/path/to
with the actual path to your Loki binary and configuration file.
- Reload systemd:
sudo systemctl daemon-reload
- Start Loki:
sudo systemctl start loki
- Enable it to start at boot:
sudo systemctl enable loki
- View service status:
sudo systemctl status loki
For production environments, using systemd is highly recommended for reliability, automatic restarts, and better integration with system tools. For quick testing or development, nohup
or tmux
/screen
is more straightforward.