Git Product home page Git Product logo

user-systemd-service-actions-workflow's Introduction

GitHub Actions workflow to demonstrate how to run a user systemd service

The tested echo server container ghcr.io/eriksjolund/socket-activate-echo supports socket activation.

Using socket activation has the advantage that there is no need for the client to use /usr/bin/sleep combined with a while-loop to check if the server is online.

The file .github/workflows/demo.yml contains:

name: Echo server demo with podman and systemd
on: 
  push:
    branch:
      - main
jobs:
  systemd_podman_echo_server_demo:
    runs-on: ubuntu-22.04
    permissions:
      contents: read
    steps:
      - name: Run actions/checkout for this repo
        uses: actions/checkout@v3
        with:
          path: checkout
          persist-credentials: false
      - name: Run an echo server with podman in a user systemd service
        run: |
          sudo apt-get update
          sudo apt-get install -y socat
          podman pull ghcr.io/eriksjolund/socket-activate-echo:latest
          mkdir -p ~/.config/systemd/user
          podman create --rm --name echo --network none ghcr.io/eriksjolund/socket-activate-echo
          podman generate systemd --name --new echo > ~/.config/systemd/user/echo.service
          cp checkout/echo.socket ~/.config/systemd/user/
          systemctl --user daemon-reload
          systemctl --user start echo.socket
          echo hello | socat - tcp4:127.0.0.1:3000
          echo hello | socat - tcp6:[::1]:3000
          echo hello | socat - udp4:127.0.0.1:3000
          echo hello | socat - udp6:[::1]:3000
          echo hello | socat - unix:$HOME/echo_stream_sock
          echo hello | socat - VSOCK-CONNECT:1:3000

user-systemd-service-actions-workflow's People

Contributors

eriksjolund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

user-systemd-service-actions-workflow's Issues

Remove the "sleep 1" after "loginctl enable-linger runner"

My experimenting showed that a sleep 1 is needed between the commands:

loginctl enable-linger runner

and

XDG_RUNTIME_DIR=/run/user/$UID systemctl --user enable --now webserver.service

Instead of adding the command sleep 1, it would of course be better to find a real solution to the race condition problem.
I sent a question about it to the systemd-devel mailing list and got a reply:
https://lists.freedesktop.org/archives/systemd-devel/2021-January/045861.html

It seems that systemd now supports the syntax

systemctl --user [email protected]

The feature is not yet available in any systemd release as it was added quite recently (December 2020).

When I get the chance I will later try to replace

XDG_RUNTIME_DIR=/run/user/$UID systemctl --user enable --now webserver.service

with

XDG_RUNTIME_DIR=/run/user/$UID systemctl --user [email protected] enable --now webserver.service

and see if it works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.