Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: A modern init system in 3 minutes
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Sat Dec 13, 2014 12:44 pm    Post subject: Thanks for sharing! Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:28 am; edited 1 time in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Tue Dec 23, 2014 7:56 pm    Post subject: Proceesses SUPERVISION Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:28 am; edited 1 time in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Tue Dec 23, 2014 10:32 pm    Post subject: rc default & chpst path fix Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:29 am; edited 1 time in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Wed Dec 24, 2014 9:57 am    Post subject: RE: Process SUPERVISION Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:29 am; edited 7 times in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Wed Dec 24, 2014 10:35 am    Post subject: Supervise `rc default'?! Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:29 am; edited 1 time in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Thu Dec 25, 2014 2:50 pm    Post subject: Move `rc boot' to stage 2 Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:30 am; edited 1 time in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Fri Mar 13, 2015 10:15 pm    Post subject: [ANNOUCE] Supervision Scripts Framework Reply with quote

[NULL]
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/


Last edited by tclover on Sun Aug 02, 2015 10:30 am; edited 1 time in total
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 512

PostPosted: Thu Mar 26, 2015 11:05 pm    Post subject: Reply with quote

Ant P. wrote:
I wrote this to make sysv's poweroff/reboot programs work. You can just run it directly.
/etc/runit/runsvdir/all/initctl/run:
#!/usr/bin/perl -T
use v5.18;
use warnings;
use autodie;

$ENV{PATH} = '/sbin:/bin';

my $INIT_FIFO    = '/dev/initctl';
my $REQ_SIZE     = 384;
my $MAGIC_HEADER = 0x03091969;
my $CMD_RUNLEVEL = 0x1;

-e $INIT_FIFO or system("/usr/bin/mkfifo --mode=0600 $INIT_FIFO");

open(my $pipefh, q{<}, $INIT_FIFO);

while () {
    read($pipefh, my $request, $REQ_SIZE) == $REQ_SIZE
        or die "Failed to read $REQ_SIZE bytes";

    my ($magic, $command, $runlevel, $sleeptime, $stuff) = unpack('l l A4 l A*', $request);

    $magic    == $MAGIC_HEADER  or die "Got invalid magic bytes";
    $command  == $CMD_RUNLEVEL  or next;
    $runlevel =~ /^(0|6)$/      and system("/sbin/runit-init $1");
}

(Side note: sysv's source code is... "interesting". No wonder everyone just starts from scratch instead of fixing it...)


Just quoting this script for the absence of any COPYRIGHT NOTICE NOR AUTHORSHIP before angry John add *any* later as proof of his nonsense.
_________________
home/:mkinitramfs-ll/:supervision(-scripts)/:e-gtk-theme/:(bar-)overlay/
Back to top
View user's profile Send private message
EmaRsk
Apprentice
Apprentice


Joined: 07 Sep 2004
Posts: 158
Location: Italy

PostPosted: Fri Mar 27, 2015 1:21 pm    Post subject: Reply with quote

From wikipedia:

"In all countries where the Berne Convention standards apply, copyright is automatic […]."
"Once an idea has been reduced to tangible form, for example by securing it in a fixed medium (such as a drawing, sheet music, photograph, a videotape, or a computer file), the copyright holder is entitled to enforce his or her exclusive rights."
"In 1989 the United States enacted the Berne Convention Implementation Act, amending the 1976 Copyright Act to conform to most of the provisions of the Berne Convention. As a result, the use of copyright notices has become optional to claim copyright, because the Berne Convention makes copyright automatic."

In free software, licensing is used to ALLOW the distribution of the software, not to prevent it. The fact that we usually don't care to enforce the copyright for our shared scripts doesn't mean that we don't have the right to do that.
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1493

PostPosted: Sat Mar 28, 2015 1:48 pm    Post subject: Reply with quote

This code clearly was ment to be published and used, so where's the problem?
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 4526

PostPosted: Sat Mar 28, 2015 11:46 pm    Post subject: Reply with quote

szatox wrote:
This code clearly was ment to be published and used, so where's the problem?

The problem is when someone comes along and slaps their own license restrictions on it, passing it off as their own work with a tiny ex post facto footnote buried somewhere giving the original author vague credit for something unspecified.

This childish reaction to being caught doing precisely that further confirms that there was no good intention behind it.
_________________
*.ebuild // /etc/service/*
Back to top
View user's profile Send private message
schorsch_76
Guru
Guru


Joined: 19 Jun 2012
Posts: 450

PostPosted: Sat Aug 01, 2015 1:20 pm    Post subject: Reply with quote

My experiments with runit:

I completly replaced openrc with runit. It boots insanely fast. The longest thing is decompressing the initrd, followed by the udev trigger. In nearly no time i am on X and i can work.

Got the getties fixed. Mount and my network setup are via services. Slim is scheduled to start when home is mounted and the udev-trigger is done.

There is one issue i am not yet understand ....

One time initializations like net.eth0 which run ifconfig/route dont need a process to supervise.

Code:
cat net.eth0/run
#!/bin/sh
ifconfig eth0 192.168.178.19/24 || exit 1
route add default gw 192.168.178.1 || exit 1
exec pause


The "pause" at the exec is a script which runs an endles loop sleep 1.
Code:
cat /usr/local/bin/pause
#!/bin/sh
while true ; do
   sleep 1
done


When i dont have this process, it tells me the service is not up. I know of the check script at the service directory. If it exits 0 it tells runit that the service is ok but sv /service/* tells me it is not up without that "pause". Any hints welcome ...
_________________
// valid again: I forgot about the git access. Now 1.2GB big. Start: 2015-06-25
git daily portage tree
Web: https://portage.schorsch-tech.de
git clone https://portage.schorsch-tech.de/portage.git
Back to top
View user's profile Send private message
schorsch_76
Guru
Guru


Joined: 19 Jun 2012
Posts: 450

PostPosted: Sun Aug 02, 2015 12:16 am    Post subject: Reply with quote

To answer my own question: Yes it is needed. See voidlinux
https://github.com/voidlinux/void-runit

See the core-services and pause.c
_________________
// valid again: I forgot about the git access. Now 1.2GB big. Start: 2015-06-25
git daily portage tree
Web: https://portage.schorsch-tech.de
git clone https://portage.schorsch-tech.de/portage.git
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 4526

PostPosted: Sun Aug 02, 2015 1:24 pm    Post subject: Reply with quote

Here's a trick you can use to avoid burning exec() calls on `sleep` processes:
Code:
chpst -L service.lock chpst -l service.lock true

_________________
*.ebuild // /etc/service/*
Back to top
View user's profile Send private message
mi_unixbird
Tux's lil' helper
Tux's lil' helper


Joined: 24 Jul 2015
Posts: 102

PostPosted: Thu Oct 08, 2015 4:55 pm    Post subject: Reply with quote

Just posting here to make it known that I've at least currently transitioned from sysvinit/OpenRC to runit/OpenRC. Boot times seems to have improved by a fraction, at least the stage where runit calls openrc seems to be have been noticeably shorter.

My setup involves "/etc/runit/1" calling rc sysinit and rc boot. the former "default" runlevel has been completely ported to runit as for now for me.

Some caveats I encountered (the package is horribly, horribly broken):

- a tty would not show up initially. The ./run scripts in /etc/service/getty{1..6}/run contained /usr/sbin/chpst. Turns out the executable is simply in /bin/chpst. Changing it to either "chpst" or "/bin/chpst" does it for me.
- Same issue as noted above with the tty's than be fixed by using the -P flag on runsvdir within /etc/runit/2
- the ebuild puts SVDIR=/etc/service in /etc/env.d, this is good because putting services in /service is inane. But bad and solves very little because sv expects a /service directory to exists. I symlinked it to /etc/service for now to fix a couple of annoying bugs with sv.

If anyone knows how to port rc sysinit and rc default to runit and do away with openrc completely. I'd love to now.
_________________
execctl --path exec filectl --current-directory list
Back to top
View user's profile Send private message
mi_unixbird
Tux's lil' helper
Tux's lil' helper


Joined: 24 Jul 2015
Posts: 102

PostPosted: Wed Jan 06, 2016 12:40 pm    Post subject: Reply with quote

So an update on a while later of using runit and runsvdir.

I don't want to do away with OpenRC any more for system boot. OpenRC is better at bringing the system online than a simple random shell script which is what you're going to get with Runit, dependencies and parallel boot do matter. So I'm keeping sysinit and boot from OpenRC.

Couple of things which are in my opinion insane defaults on runit but which can be fixed.


    /service, /etc/service, /var/service, they're all horrible choices for that directory that contains the "current" runlevel. On my system it's /run/svon, it needs to be in /run in my opinion. That's what /run is for. /etc is insane because a process really should not write to /etc under normal operation to store its state and hat's what it does. /var is okay I guess but still not as appropriate as /run

    in general, runit loves to write to /etc. I I am philosophically opposed to this so I fixed this by creating symlinks, /etc/runit/{stopit,runit} are linked to /run/runit/{stopit,runit}, it can write in /run all day long. Also, the ./supervise directories in /etc/sv/$service are linked to /run/sv/supervise/$service here because again, stop writing in /etc you bastard

    I created the sv group and made the permissions of the supervise files as such that members of the sv group can ask for the status of services without having to use root. I think it's silly you need to be root to ask for a status.

    since this is reset at boot because /run is on a tmpfs. I actually created a service that actually monitors these permissions and if they are off it resets it back to the right ones, yeh...

    I think storing runlevels in /etc/runit/runsvdir is dumb, runlevels are not part of runit, as far as I'm concerned the runit init system and the "sv" set of process supervision tools are unrelated but some-how packaged together, they do not need each other. So runlevels are stored in /etc/svlevels now with /run/svon always being a symlink to the current level.

    "sv" was too limited, so I made a wrapper around it which can for instance do "svctl status \*" to get the status of all services in /run/svon, it basically performs globbing and does a bunch of other nice things like automatically managing symlinks, changing runlevels, listing available services etc.


Maybe this code will give you people some ideas:

/etc/runit/1:
#!/bin/bash
# system one time tasks

set -u

. /etc/runit/functions

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/lib/rc/bin

einfo 'Initializing system with OpenRC'
eindent
   einfo 'sysinit level'
   openrc sysinit || {
      eerror 'OpenRC failed the sysinit level' ;
      sulogin ;
      exit 100 ;
      }
      
   slowdown
   
   einfo 'boot level'
   openrc boot || {
      eerror 'OpenRC failed the boot level' ;
      sulogin ;
      exit 100 ;
      }
eoutdent
eend 0

slowdown

ebegin 'Creating stopit and reboot files'
mkdir -p /run/runit &&
touch /run/runit/stopit &&
chmod 0 /run/runit/stopit &&
touch /run/runit/reboot &&
chmod 0 /run/runit/reboot
eend $? || { sulogin ; exit 100 ; }

slowdown


/etc/runit/2:
#!/bin/bash

set -u
. /etc/runit/functions

export PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/lib/rc/bin

export SVDIR=/run/svon
svlevels=/etc/svlevels
runlevel=$svlevels/default
supervisedir=/run/sv/supervise

if get_cmdline single; then
   einfo "Dropping to single user mode"
   sulogin
   exit 0
fi

# check for any other runlevel
if get_cmdline softlevel; then
   level=$cmdline_value
   ebegin "Using runlevel: $level"
   levelpath=$svlevels/$level
   if [[ -d "$levelpath" ]] ; then
      runlevel=$levelpath
      ewend 0
   else
      ewend "$levelpath does not exist"
      einfo "Using $runlevel"
   fi
fi

slowdown

ebegin "Linking $runlevel to $SVDIR"
if [[ -L "$SVDIR" ]] ; then
   eindent
      ewarn "$SVDIR already exists and is a symlink"
      ebegin "Unlinking $SVDIR"
      unlink "$SVDIR"
      eend $?
   outdent
fi

ln -s "$runlevel" "$SVDIR"
eend $? || { sulogin ; exit 0 ; }

slowdown 2

ebegin "Creating $supervisedir"
mkdir -p "$supervisedir"
eend $? || { sulogin ; exit 0 ; }

slowdown 2

openrc runsvdir

einfo "Starting runsvdir with: $SVDIR"
exec runsvdir -P "$SVDIR" &> /dev/null
eerror "Exec some-how failed horribly"
sulogin
exit 0


/etc/runit/3:
#!/bin/bash

set -u
. /etc/runit/functions

exec >/dev/console 2>&1
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/lib/rc/bin
export SVDIR=${SVDIR-/run/svon}

if [[ -d "$SVDIR" && "$(ls "$SVDIR")" ]]; then
   ebegin "Waiting for services to stop"
   sv force-stop "$SVDIR"/*
   sv exit "$SVDIR"/*
   eend $?
else
   einfo "No services to stop"
fi

slowdown 2

ebegin "Obtain all users in users group"
IFS=, users=( $(awk -F: '/^users/ {print $4;}' /etc/group ) )
eend $?

einfo "Sending a TERM signal to all processes by users in users group"
for user in "${users[@]}"; do
   pkill -TERM -u "$user"
done

slowdown 2

patience=5

eindent
   ebegin "Waiting $patience seconds for processes to die"
   now=$(date +%s)
   timeout=$((now+$patience))
   while true ; do
      remaining_count=0
      for user in "${users[@]}" ; do
         usercount=$(ps -u "$user" -o pid= | wc -w)
         ((remaining_count+=usercount))
      done
      if [[ $remaining_count = 0 || $(date +%s) -gt timeout ]]; then
         break
      fi
   done
   if [[ $remaining_count -gt 0 ]]; then
      ewend 1 "$remaining_count processes remaining"
      einfo "Sending KILL signal to remaining processes"
      for user in "${users[@]}"; do
         pkill -KILL -u "$user"
      done
   else
      eend 0
   fi
eoutdent

slowdown 2

if [[ -x /etc/runit/reboot ]] ; then
   ebegin "Rebooting system with OpenRC"
   eindent
      openrc reboot
      exit=$?
   eoutdent
   eend $exit
else
   ebegin "Shutting down system with OpenRC"
   eindent
      openrc shutdown
      exit=$?
   eoutdent
   eend $exit
fi

slowdown


/etc/runit/functions:
#!/bin/bash

get_cmdline () {
   cmdline_value=''
   [[ -r /proc/cmdline ]] || return 1
   local name=$1
   local arg
   local preflen=$((1+${#name}))
   local retval=1 #this is done this way to ensure that later cmdline flags overwrite earlier ones
   for arg in $(cat /proc/cmdline); do
      case "$arg" in
         "$name="?*)
            cmdline_value="${arg:$preflen}"
            retval=0
            ;;
         "$name")
            retval=0
            ;;
      esac
   done
   return $retval
}

slowdown () {
   local default=${1-2}
   if get_cmdline slow ; then
      sleep "${cmdline_value-$default}"
   fi
}


/usr/local/bin/svctl:
#!/bin/bash

set -u

opts=()
cmds=()
servs=()

svdir=${SVDIR-/run/svon}
rldir=${SVRLDIR-/etc/svlevels}
dedir=/etc/sv
if [[ ! -e $svdir ]]; then
   echo "SVDIR $svdir does not exist" 1>&2
   exit 2
fi
   
svdir=$(realpath -s -- "$svdir")

argv=( "$0" "$@" )
i=1
while [[ $i -lt ${#argv[@]} ]]; do
   arg=${argv[i]}
   case "$arg" in
      -w)  opts=( -w "${argv[$((i+1))]}" ); ((i++));;
      -?*) opts+=("$arg");;
      *)  cmds=("$arg"); args=( "${argv[@]:$((i+1))}" ); break;;
   esac
   ((i++))
done

enabledservs=()
definedservs=()
runlevels=()

for arg in "${args[@]:+${args[@]}}"; do
   if [[ $arg != */* ]]; then
      IFS=$'\n'
      globs=( $(find "$svdir/" -maxdepth 1 ! -path "$svdir/" -name "$arg" -printf '%f\n') )
      if [[ "${#globs[@]}" -gt 0 ]]; then
         for glob in "${globs[@]}"; do
            enabledservs+=( "$svdir/$glob" )
         done
      else
         enabledservs+=( "$svdir/$arg" )
      fi
      
      globs=( $(find "$dedir/" -maxdepth 1 ! -path "$dedir/" -name "$arg" -printf '%f\n') )
      if [[ "${#globs[@]}" -gt 0 ]]; then
         for glob in "${globs[@]}"; do
            definedservs+=( "$dedir/$glob" )
         done
      else
         definedservs+=( "$dedir/$arg" )
      fi
      
      globs=( $(find "$rldir/" -maxdepth 1 ! -path "$rldir/" -name "$arg" -printf '%f\n') )
      if [[ "${#globs[@]}" -gt 0 ]]; then
         for glob in "${globs[@]}"; do
            runlevels+=( "$rldir/$glob" )
         done
      else
         runlevels+=( "$rldir/$arg" )
      fi
      
   else
      enabledservs+=( "$arg" )
      definedservs+=( "$arg" )
      runlevels+=( "$arg" )
   fi
done

case "${cmds[@]-}" in
   enable)
      for i in "${!definedservs[@]}"; do
         ln -s -- "${definedservs[i]}" "$SVDIR"
      done
      ;;
   disable)
      for i in "${!enabledservs[@]}"; do
         unlink "${enabledservs[i]}"
      done
      ;;
   list)
      ls "${args[@]:+${args[@]}}" -- "$dedir/"
      ;;
   list-enabled)
      ls "${args[@]:+${args[@]}}" -- "$svdir/"
      ;;
   switch)
      ln -sfT -- "${runlevels[0]}"  "$SVDIR"
      ;;
   *)
      sv "${opts[@]:+${opts[@]}}" "${cmds[@]:+${cmds[@]}}" "${enabledservs[@]:+${enabledservs[@]}}"
      ;;
esac

_________________
execctl --path exec filectl --current-directory list
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 4526

PostPosted: Wed Jan 06, 2016 6:23 pm    Post subject: Reply with quote

Didn't expect this topic to pick up again...

mi_unixbird wrote:
Some caveats I encountered (the package is horribly, horribly broken):

No surprise there, WilliamH is the maintainer. Seems to be real popular among users of other init packages for the same reason.

Quote:
- a tty would not show up initially. The ./run scripts in /etc/service/getty{1..6}/run contained /usr/sbin/chpst. Turns out the executable is simply in /bin/chpst. Changing it to either "chpst" or "/bin/chpst" does it for me.

That one might actually be *my* fault. As in, I submitted a bunch of bugs against the in-tree ebuild to make it less insane a long time ago and the changes therein were only partially applied (and nobody responsible actually bothered to read them, see above).
/bin/chpst is the correct location for that binary because it doesn't need root privileges to work sensibly, nor does it need /usr mounted to function.

Quote:
- Same issue as noted above with the tty's than be fixed by using the -P flag on runsvdir within /etc/runit/2

FWIW, vanilla runit provides a correct /etc/runit/2 and I filed a bug for that too. Gentoo insists on shipping a broken one.

Quote:
- the ebuild puts SVDIR=/etc/service in /etc/env.d, this is good because putting services in /service is inane. But bad and solves very little because sv expects a /service directory to exists. I symlinked it to /etc/service for now to fix a couple of annoying bugs with sv.

Upstream said something a while ago (in geological timescales) about fixing the hardcoded /service thing, there hasn't been a release since then though.

Quote:
If anyone knows how to port rc sysinit and rc default to runit and do away with openrc completely. I'd love to now.

rc default is really easy to replace (see link in sig, it's almost all one-liners), I don't feel confident enough to do away with rc sysinit though. Too much obfuscated magic going on there.

Quote:
/service, /etc/service, /var/service, they're all horrible choices for that directory that contains the "current" runlevel. [...] a process really should not write to /etc under normal operation

I agree wholeheartedly with this point, but I've been too indifferent to do anything about it. Might give it another try.
To be fair runit itself isn't braindead; its own FAQ says you can symlink all the */supervise/ directories to a tmpfs if you really want and it supports running like this.

Quote:
I created the sv group and made the permissions of the supervise files as such that members of the sv group can ask for the status of services without having to use root. I think it's silly you need to be root to ask for a status.

since this is reset at boot because /run is on a tmpfs. I actually created a service that actually monitors these permissions and if they are off it resets it back to the right ones, yeh...

That's weird and it sounds like Gentoo-specific screwery. There's no reason for those directories to not be world-readable.
_________________
*.ebuild // /etc/service/*
Back to top
View user's profile Send private message
mi_unixbird
Tux's lil' helper
Tux's lil' helper


Joined: 24 Jul 2015
Posts: 102

PostPosted: Thu Jan 07, 2016 11:11 am    Post subject: Reply with quote

It is weird and not necessary, but I find it paranoid to need root to _read_ the status of services. OpenRC and sysvrc allow status to be seen without even being in a specific group as far as I know. Needing to be in the sv group is more than enough.

That said, I've been hacking a bit more. I've modified the sysvinit package to install the init binary in /sbin/sysvinit instead of /sbin/init and made init a symlink which can be changed with eselect from runit-init to sysvinit.

I've partially implemented a system now as well where the eselect link also changes shutdown reboot poweroff and halt links to sysv{shutdown,reboot,poweroff,halt} and runit-{shutdown,reboot,poweroff,halt}. I've implemented a simple script that copies some of the functions that we know and love from those binaries and relays them to runit to get the behaviour back.

An "eselect init" system should probably exist, so here's my take:

Code:
DESCRIPTION="Manage /sbin/init implementations"
VERSION="0.1"

SYMLINK_PATH=/sbin/init
SYMLINK_TARGETS=( sysvinit runit-init )
SYMLINK_DESCRIPTION='init process'
SYMLINK_CRUCIAL=1

inherit bin-symlink

do_set () {
   local base=${1%init}
   local files="init halt reboot poweroff shutdown"
   local link
   local target
   # we first check the sanity of everything before we actually make any modiications
   for link in $files; do
      target=$EROOT/sbin/$base$link
      link=$EROOT/sbin/$link
      [[ -e $link && ! -L $link ]] && die -q "$link exists but is not a symlink"
   done
   
   for link in $files; do
      target=$EROOT/sbin/$base$link
      link=$EROOT/sbin/$link
      ln -sf "$target" "$link" || die -q "Could not not link $link to $target"
   done
}

_________________
execctl --path exec filectl --current-directory list
Back to top
View user's profile Send private message
mi_unixbird
Tux's lil' helper
Tux's lil' helper


Joined: 24 Jul 2015
Posts: 102

PostPosted: Tue Jun 14, 2016 9:15 am    Post subject: Reply with quote

Right, so this is my implementation right now for anyone who's interested:

/etc/runit/1:

Code:
#!/bin/sh
# system one time tasks

set -u

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/lib/rc/bin

openrc sysinit || {
   sulogin
   exit 100
   }

openrc boot || {
   sulogin
   exit 100
   }

for arg in $(cat /proc/cmdline); do
   case "$arg" in single)
      sulogin
      exit 100
      ;;
   esac
done

openrc runsvdir || {
   sulogin
   exit 100
   }


The obviously relevant part is the "runsvdir" runlevel. This contains three scripts:

/etc/runlevels/runsvdir/runit-files:
Code:
#!/sbin/openrc-run

description="make the files runit needs to shutdown and reboot the system"

start () {
   ebegin 'Creating stopit and reboot files'
   mkdir -p /run/runit &&
   touch /run/runit/stopit &&
   chmod 0 /run/runit/stopit &&
   touch /run/runit/reboot &&
   chmod 0 /run/runit/reboot
   eend $?
}


This one is used to create the stopit and reboot files, note that they live in "/run/runit" instead of "/etc/runit" and symlinked from there. This is to allow "/etc" to be on a read-only filesystem.

/etc/runlevels/runsvdir/runsvdir-runsupervise
Code:
#!/sbin/openrc-run

svcontainer=${svcontainer-/etc/sv}
runsupervise=${runsupervise-/run/sv/supervise}

depend () {
   keyword -shutdown
}

start() {
   ebegin "Making supervision directory $runsupervise"
   mkdir -p "$runsupervise"
   eend $?
}

stop() {
   ebegin "Removing supervision directory $runsupervise"
   rm -r "$runsupervise"
   eend $?
}


This simply creates a directory "/run/sv/supervise", this is because all the "/etc/sv/*/supervise" directories are symlinked to that directory, again, to keep /etc read-only if possible so /etc/sv/sshd/supervise is a symlink to /run/sv/supervise/sshd

And finally

/etc/runlevels/runsvdir/runsvdir-runlevel:
Code:
#!/sbin/openrc-run

description="set the runlevel runsvdir needs from the kernel command line"
SVDIR="${svdir-/run/svon}"
SVLEVELDIR=/etc/svlevels

start () {
   local level_ level=default arg
   einfo "Setting runsvdir runlevel based on kernel command line"
   for arg in $(cat /proc/cmdline); do
      case "$arg" in softlevel=?*)
         level="${arg#softlevel=}"
         if [ -d "$SVLEVELDIR/$level_" ]; then
            einfo "Setting runsvdir runlevel to $level_"
            level="$level_"
         else
            ewarn "runlevel $level_ does not exist"
         fi
         ;;
      esac
   done
   ln -s "$SVLEVELDIR/$level" "$SVDIR"
   return $?
}


Sets the runlevel which on my system lives in /etc/svlevels based on the kernel command line and defaults to /etc/svlevels/default if non provided. As you can see I do not use the common /var/service but /run/svon for a symlink to the currently active runlevel because I feel it should be in /run

/etc/runit/2 is simply a simple "exec runsvdir -P /run/svon"

I've currently completely embraced OpenRC for system one time tasks opposed to trying to run runit without it. runit-init is used as pid1. runsvdir for process supervision and OpenRC for booting the system.
_________________
execctl --path exec filectl --current-directory list
Back to top
View user's profile Send private message
kurac51
n00b
n00b


Joined: 02 Mar 2017
Posts: 1
Location: Croatia

PostPosted: Thu Mar 02, 2017 3:16 pm    Post subject: Reply with quote

I see some people used runit on gentoo as there only init how was it i was thinking about it but i don't know how well does it work is it perfect like SystemD or OpenRC?
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 4526

PostPosted: Fri Mar 03, 2017 7:48 pm    Post subject: Reply with quote

Runit will not handhold you unlike those other systems. You're required to know how to think and do things for yourself if you go down this path; there are no prewritten init scripts. In a sense it's like Gentoo itself, a meta-init.

If you're asking if it's maintained to the same standards as the other two: williamh "owns" the ebuilds for all three in the main tree, so yes. Don't use that one unless you like reporting bugs and not getting replies for months.
_________________
*.ebuild // /etc/service/*
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum