Skip to content

Commit

Permalink
version without cgm and automatic child process removal
Browse files Browse the repository at this point in the history
  • Loading branch information
AFriemann committed Jan 8, 2017
1 parent 693c912 commit b044c9a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 128 deletions.
19 changes: 7 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This service will start a runsvdir process for a given user that will manage run

$HOME/.local/service

requirements
------------

* libcgroup-utils - The session uses cgroups to limit available pids.

user-sessions
-------------

Expand All @@ -17,7 +22,7 @@ and services in *~/.local/service*. Runit should now automatically run all servi
To control the services, use the provided usv script or add a function to your shell rc::

usv () {
SVDIR=~/.local/service sv
SVDIR=~/.local/service sv $@
}

now run (assuming you have the user-session running)::
Expand All @@ -29,8 +34,7 @@ now run (assuming you have the user-session running)::
$ usv stop aria2c
ok: down: aria2c: 1s, normally up

the user-session is run in a cgroup, currently with max PIDs of 50. The cgroup is also used to kill child processes in
case the user-session is killed::
Stopping the user-session should also stop all child services::

$ usv status aria2c
ok: run: aria2c: (pid 12237) 1061s
Expand All @@ -42,12 +46,3 @@ case the user-session is killed::
$ ps aux | grep aria2c
admin 14458 0.0 0.0 10756 2192 pts/6 S+ 00:12 0:00 grep aria2c

user-session-manager
--------------------

The user-session-manager service will automatically create/remove user-sessions for logged in users::

$ cp -r user-session /etc/sv/user-session
$ cp -r user-session-manager /etc/sv/user-session-manager
$ ln -s /etc/sv/user-session-manager /var/service/user-session-manager

3 changes: 0 additions & 3 deletions user-session-manager/finish

This file was deleted.

5 changes: 0 additions & 5 deletions user-session-manager/run

This file was deleted.

99 changes: 0 additions & 99 deletions user-session-manager/usm

This file was deleted.

2 changes: 2 additions & 0 deletions user-session/control/t
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec sv -v h .
4 changes: 2 additions & 2 deletions user-session/finish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

SVNAME="$(basename $0)"
SVNAME="$(realpath $0 | cut -d/ -f4)"
SVUSER="${SVNAME##*.}"

cgm gettasksrecursive pids "$SVUSER" | xargs kill
cgdelete -g "pids:users/${SVUSER}/runit"
16 changes: 9 additions & 7 deletions user-session/run
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/sh

SVNAME="$(realpath $0 | cut -d/ -f4)"
SVUSER=${SVNAME##*.}
SVUSER="${SVNAME##*.}"
SVHOME="$(eval "echo ~$SVUSER")/.local/service"

who -u | grep -q "^$SVUSER" || exit 1
who | grep -q "^${SVUSER}" || exit 1
[ -d "$SVHOME" ] || exit 1

cgm create all "$SVUSER"
cgm removeonempty all "$SVUSER"
cgm setvalue pids "$SVUSER" pids.max 50
CGROUP="users/${SVUSER}/runit"

exec 2>&1
exec cgexec -g "*:${SVUSER}" --sticky chpst -u "$SVUSER" -P runsvdir -P /home/"$SVUSER"/.local/service
cgcreate -g "pids:$CGROUP"
cgset -r pids.max=100 "$CGROUP"

exec cgexec -g "pids:$CGROUP" --sticky -- chpst -u "$SVUSER" runsvdir "$SVHOME"

0 comments on commit b044c9a

Please sign in to comment.