From 765d098fd01d9b00f79c7f74c1ff408fde6f7498 Mon Sep 17 00:00:00 2001 From: Wenchi Pan Date: Wed, 21 Feb 2024 23:11:37 +0800 Subject: [PATCH] Site updated: 2024-02-21 23:11:37 --- 2024/02/20/linux-common-command/index.html | 12 ++++++++---- index.html | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/2024/02/20/linux-common-command/index.html b/2024/02/20/linux-common-command/index.html index 6c3e4b4..f9d90e0 100644 --- a/2024/02/20/linux-common-command/index.html +++ b/2024/02/20/linux-common-command/index.html @@ -27,7 +27,7 @@ - + @@ -189,7 +189,7 @@

- + @@ -217,15 +217,19 @@

Show colorful output:

Continuously print new logs

journalctl --follow --no-tail is used when you want all previous lines (better than -n 100000 or arbitrary big line count)

Restrict the output to latest run:

-

TL;DR: Use the one liner: - System level:

1
journalctl _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value service_name.service`
- User level:
1
journalctl _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value service_name.service --user`

+

TL;DR: Use the one liner:

+

Python(conda) in systemd service

Create a systemd Service File: Create a .service file (e.g., my_server.service) in a location of your choice (usually /etc/systemd/system/ for system-level services or ~/.config/systemd/user/ for user-level services). Open the file for editing.

Define the Service:

  1. Add the following content to your .service file:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [Unit]
    Description=My Python Server

    [Service]
    Type=simple
    ExecStart=/path/to/conda/envs/env_name/bin/python python_file.py
    WorkingDirectory=/path/to/working/directory

    [Install]
    WantedBy=default.target
  2. Replace /path/to/conda/envs/env_name with the actual path to your Conda environment. Adjust the WorkingDirectory to the directory where your startup.py resides.
  3. -
  4. Enable and Start the Service:
+

Enable and Start the Service: