• [^] # Re: Une mode ?

    Posté par . En réponse au journal Les problèmes d’un desktop sans systemd ?. Évalué à 3.

    Je ne sais pas si systemd répond à un besoin utilisateur

    Je dirais que si. Le système d'unit de systemd est plus simple a hacker que l'horreur sans nom qu'il y a encore dans debian pour les rc.d.
    Petit example avec mpd en fin de message (parce que c'est LONG rc.d!).
    C'est juste indiscutablement plus simple, le jour ou l'on a besoin de bricoler un daemon pour soi. Et je n'aime pas systemd, hein!
    En gros:

    • systemd: 49 lignes
    • init.d: 108 lignes, et je n'ai pas eu le courage d'aller compter les trucs sourcés
    • runit, pour l'instance de runsvdir qui démarre quand je me log en tant que user et pas quand je boote le système, pour le fun: 35 (c'est moi qui ai plus petite, nanananèèreeeee)

    Il est possible de lancer des daemon sans être root! Sans DE! Et un watchdog, comme ça quand ça plante ou qu'on ferme par erreur, ça redémarre. Typiquement: le client lourd pour les mails que les gens qui bossent continuent de préférer globalement aux interfaces web.

    Dernier: avantage théorique, avec systemd on devrais pouvoir démarrer plus vite parce que tout simplement si le PC est hors réseau, certains services qui requièrent le réseau ne chercherons pas à démarrer. Je sais pas, moi, le logiciel de backup par exemple, ou syncthing, ou le client mail... Reste à voir si c'est mesurable.

    Ensuite la question est: quelle est la limite entre un utilisateur et un mainteneur sur un système GNU/Linux? Vu que je maintiens mes scripts d'init DIY, que suis-je?

    Systemd:

    [Unit]
    Description=Music Player Daemon
    Documentation=man:mpd(1) man:mpd.conf(5)
    Documentation=file:///usr/share/doc/mpd/html/user.html
    After=network.target sound.target
    [Service]
    Type=notify
    EnvironmentFile=/etc/default/mpd
    ExecStart=/usr/bin/mpd --no-daemon $MPDCONF
    # Enable this setting to ask systemd to watch over MPD, see
    # systemd.service(5). This is disabled by default because it causes
    # periodic wakeups which are unnecessary if MPD is not playing.
    #WatchdogSec=120
    # allow MPD to use real-time priority 40
    LimitRTPRIO=40
    LimitRTTIME=infinity
    # for io_uring
    LimitMEMLOCK=64M
    # disallow writing to /usr, /bin, /sbin, ...
    ProtectSystem=yes
    # more paranoid security settings
    NoNewPrivileges=yes
    ProtectKernelTunables=yes
    ProtectControlGroups=yes
    ProtectKernelModules=yes
    # AF_NETLINK is required by libsmbclient, or it will exit() .. *sigh*
    RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
    RestrictNamespaces=yes
    [Install]
    WantedBy=multi-user.target
    Also=mpd.socket
    
    [Socket]
    ListenStream=%t/mpd/socket
    ListenStream=6600
    Backlog=5
    KeepAlive=true
    PassCredentials=true
    [Install]
    WantedBy=sockets.target
    

    sysvinit+rc.d sous debian:

    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: mpd
    # Required-Start: $local_fs $remote_fs
    # Required-Stop: $local_fs $remote_fs
    # Should-Start: autofs $network $named alsa-utils pulseaudio avahi-daemon
    # Should-Stop: autofs $network $named alsa-utils pulseaudio avahi-daemon
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Music Player Daemon
    # Description: Start the Music Player Daemon (MPD) service
    # for network access to the local audio queue.
    ### END INIT INFO
    . /lib/lsb/init-functions
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    NAME=mpd
    DESC="Music Player Daemon"
    DAEMON=/usr/bin/mpd
    MPDCONF=/etc/mpd.conf
    # Exit if the package is not installed
    [ -x "$DAEMON" ] || exit 0
    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME
    if [ -n "$MPD_DEBUG" ]; then
     set -x
     MPD_OPTS=--verbose
    fi
    PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/1円/p' $MPDCONF)
    mpd_start () {
     log_daemon_msg "Starting $DESC" "$NAME"
     if [ -z "$PIDFILE" ]; then
     log_failure_msg \
     "$MPDCONF must have pid_file set; cannot start daemon."
     exit 1
     fi
     PIDDIR=$(dirname "$PIDFILE")
     if [ ! -d "$PIDDIR" ]; then
     mkdir -m 0755 $PIDDIR
     if dpkg-statoverride --list --quiet /run/mpd > /dev/null; then
     # if dpkg-statoverride is used update it with permissions there
     dpkg-statoverride --force --quiet --update --add $( dpkg-statoverride --list --quiet /run/mpd ) 2> /dev/null
     else
     # use defaults
     chown mpd:audio $PIDDIR
     fi
     fi
     start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
     --exec "$DAEMON" -- $MPD_OPTS "$MPDCONF"
     log_end_msg $?
    }
    mpd_stop () {
     if [ -z "$PIDFILE" ]; then
     log_failure_msg \
     "$MPDCONF must have pid_file set; cannot stop daemon."
     exit 1
     fi
     log_daemon_msg "Stopping $DESC" "$NAME"
     start-stop-daemon --stop --quiet --oknodo --retry 5 --pidfile "$PIDFILE" \
     --exec $DAEMON
     log_end_msg $?
    }
    # note to self: don't call the non-standard args for this in
    # {post,pre}{inst,rm} scripts since users are not forced to upgrade
    # /etc/init.d/mpd when mpd is updated
    case "1ドル" in
     start)
     mpd_start
     ;;
     stop)
     mpd_stop
     ;;
     status)
     status_of_proc -p $PIDFILE $DAEMON $NAME
     ;;
     restart|force-reload)
     mpd_stop
     mpd_start
     ;;
     force-start)
     mpd_start
     ;;
     force-restart)
     mpd_stop
     mpd_start
     ;;
     force-reload)
     mpd_stop
     mpd_start
     ;;
     *)
     echo "Usage: 0ドル {start|stop|restart|force-reload}"
     exit 2
     ;;
    esac
    

    Mon runit à moi, pour le fun, qui est contrôlé par une instance utilisateur de runsvdir (je sais, systemd aussi le peut):

    #!/bin/sh
    die()
    {
     printf "%s\n" "$@" | tee ./down
     exit 1
    }
    SVNAME="$(basename $(pwd))"
    HAS_LOG="$(test -d "$(pwd)/log" && printf "yes")"
    exec 0<&-
    exec 2>&1
    set -xe
    test -f conf && . ./conf
    if test "0ドル" = "run"
    then
     if test "$SVNAME" = "log"
     then
     SVLOG="$(basename $(dirname $(pwd)))"
     SVNAME="${SVLOG}/${SVNAME}"
     AUTO_ROTATE="${AUTO_ROTATE:="no"}"
     fi
     test "yes" = "${AUTO_ROTATE}" -a "yes" = "$HAS_LOG" && \
     sv alarm "$(pwd)/log"
    fi
    export DATADIR="/dev/shm/$(id -u)/"
    
    #!/bin/sh
    . ../../common
    echo "Starting $SVNAME"
    exec mpd --no-daemon ~/.config/mpd/mpd.conf --stderr 2>&1