you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 3 months ago (2 children)

I see! But there's still much more than service management, not all of it packaged into the "init" part of systemd. And each of these things need to be learned. I'm not saying it's impossible, but it's just one more big headache on top of what Linux already is.

Also, out of curiosity from someone who barely touched Void - how do you create a custom service? Is writing run and finish scripts sufficient?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 3 months ago (1 child)

    Yeah, that's all there is to it. The finish script is optional, and rememer to make your links. You can have user level services by making links for runsvdir-USERNAME. This creates a service that manages your services.

    It could probably be more robustn but here's my setup:

    $ readlink {/etc/sv,/var/service}/runsvdir-$USER | sed "s:$USER:USERNAME:g"
    /home/USERNAME/.dotfiles/runsvdir-USERNAME
    /etc/sv/runsvdir-USERNAME
    
    $ print -l /etc/sv/runsvdir-$USER/*(.)
    /etc/sv/runsvdir-USERNAME/conf
    /etc/sv/runsvdir-USERNAME/finish
    /etc/sv/runsvdir-USERNAME/run
    
    $ print -l /etc/sv/runsvdir-$USER/*(.) | to -b -C '#' -A $'\n' cat | sed "s:$USER:USERNAME:g"
    # /etc/sv/runsvdir-USERNAME/conf
    #!/bin/sh
    
    set -eu
    
    self="$(realpath "$0")"
    root="$(dirname "$self")"
    user="$(basename "$root" | sed 's:^runsvdir-::')"
    home="/home/$user"
    
    groups="$(id -Gn "$user" | tr ' ' ':')"
    svdir="$home/service"
    #
    
    # /etc/sv/runsvdir-USERNAME/finish
    #!/usr/bin/env sh
    
    set -eu
    
    self="$(realpath "$0")"
    root="$(dirname "$self")"
    
    [ ! -e "$root/conf" ] || . "$root/conf"
    
    sv -w600 force-stop "$svdir/"\*
    #
    
    # /etc/sv/runsvdir-USERNAME/run
    #!/bin/sh
    
    # start up for user-level service configuration
    
    set -eu
    
    exec 2>&1
    
    root="$(realpath "$0" | xargs -d '\n' dirname)"
    [ ! -e "$root/conf" ] || . "$root/conf"
    
    exec chpst -u "$user:$groups" runsvdir -P "$svdir"
    #
    
    

    For clarity, the to command is an xargs alternative that's not out, yet.

  • source
  • parent
  • hideshow 1 child comment