Editing
Running runit-supervised services inside a vserver
(section)
From Linix VServer
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== The big picture == Let's see how it all fits together. We'd like to achieve something like this (output of <tt>vps axfu</tt>): <pre> USER PID CONTEXT %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0 MAIN 0.0 0.0 104 16 ? Ss Jan29 0:06 runit root 4188 0 MAIN 0.0 0.0 132 32 ? Ss Jan29 0:10 runsvdir -P /var/service log: ....................................................... root 4250 0 MAIN 0.0 0.0 108 28 ? Ss Jan29 0:00 \_ runsv vserver-logrelay-squid log 4256 0 MAIN 0.0 0.0 128 44 ? S Jan29 0:00 | \_ svlogd -t /var/log/sv/vserver-logrelay-squid logrelay 3106 0 MAIN 0.0 0.1 25428 1944 ? S 00:44 0:00 | \_ socat -d -d -d -D -ls -u UNIX-LISTEN:/etc/vservers/squid/vdir/dev/log,unlink-early,nonblock,mode=666,setuid=logrelay UNIX-CONNECT:/dev/log,type=2,nonblock,forever root 19272 0 MAIN 0.0 0.0 108 28 ? Ss Feb01 0:00 \_ runsv squid log 19273 0 MAIN 0.0 0.0 128 44 ? S Feb01 0:00 | \_ svlogd -t /var/log/sv/squid root 10324 0 MAIN 0.0 0.0 5728 364 ? S Feb01 0:00 | \_ signal-relay vserver squid exec squid -N -D -sYC proxy 10334 2 squid 0.0 0.5 24968 8036 ? Sl Feb01 0:01 | \_ squid -N -D -sYC root 24219 0 MAIN 0.0 0.0 108 32 ? Ss 02:02 0:00 \_ runsv nmbd root 24220 0 MAIN 0.0 0.0 5732 376 ? S 02:02 0:00 | \_ signal-relay vserver samba exec /usr/sbin/nmbd -F root 24230 3 samba 0.0 0.1 30080 2360 ? Ss 02:02 0:00 | \_ /usr/sbin/nmbd -F root 24251 3 samba 0.0 0.0 32172 1496 ? S 02:02 0:00 | \_ /usr/sbin/nmbd -F root 24253 0 MAIN 0.0 0.0 108 28 ? Ss 02:02 0:00 \_ runsv smbd root 24254 0 MAIN 0.0 0.0 5732 376 ? S 02:02 0:00 | \_ signal-relay vserver samba exec /usr/sbin/smbd -F root 24268 3 samba 0.0 0.2 41888 3404 ? Ss 02:02 0:00 | \_ /usr/sbin/smbd -F root 24289 3 samba 0.0 0.0 41888 1232 ? S 02:02 0:00 | \_ /usr/sbin/smbd -F root 29625 0 MAIN 0.0 0.0 104 28 ? Ss 02:22 0:00 \_ runsv cron-squid root 29626 0 MAIN 0.0 0.0 5732 376 ? S 02:22 0:00 \_ signal-relay vserver squid exec cron -f root 29637 2 squid 0.0 0.0 11492 1060 ? S 02:22 0:00 \_ cron -f </pre> For service supervision to work, we must be able to send signals to our services. Specifically, <tt>runsv</tt> must be able to send signals to its children. Alas, it's not prepared to send signals across context boundaries, which is where <tt>signal-relay</tt> comes in. === <tt>signal-relay</tt> === <tt>signal-relay</tt> is a small program not unlike <tt>runit</tt>'s <tt>chpst</tt> that does the following: * it forks a child; ** inside the child, it execs the program specified on its command line; * in the parent, it sets up signal handlers for every signal that relay the signal to the child, even if the child is running in a different context; * if the child exits, <tt>signal-relay</tt> exits. * (It can also put the child into its own process group; use the <tt>-P</tt> switch. Sending signals to process groups in a different context doesn't work yet, though.) === Setting up the vservers === When we start a service for runit, we want the command that starts the service to stay in the foreground until the moment the service dies. <tt>vserver exec</tt> looks just right, but there is a catch: it only works for vservers that have been "started". <tt>vserver start</tt>, however, doesn't fit very well into the <tt>runit</tt> way of doing things. You can set it up as a service (this is discussed in [[util-vserver:InitStyles]]), but it seems superfluous to leave some processes around just to keep a vserver "started" so that we can run services in it. What we need is a way of basically doing "start vserver <guest> if it's not started, then exec program <service> inside it". Normally, a context with no processes running inside it is destroyed by the kernel; thus, just setting <tt>/etc/vservers/guest/apps/init/cmd.start</tt> to <tt>/bin/true</tt> isn't going to work; we would need something that stays around for a while, like a script that calls <tt>sleep 1m &</tt>. This would make <tt>vserver start</tt> happy, so in our service run script, we could do something like <pre> vserver guest status || vserver guest start exec signal-relay vserver guest exec /path/to/service-program </pre> A more elegant solution is to make the guest context ''persistent''. This way it sticks around even if there are no processes left in it. <pre> cd /etc/vservers/guest echo persistent >>flags echo persistent >>nflags echo /bin/true >apps/init/cmd.start </pre> (I ''guess'' <tt>nflags</tt> is for the network context.) Now, <tt>vserver guest start</tt> should be able to "start" our vserver (set up all of its state), and exit without leaving stray processes around.
Summary:
Please note that all contributions to Linix VServer may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Linix VServer:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Page actions
Page
Discussion
Read
Edit
History
Page actions
Page
Discussion
More
Tools
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
About
Overview
Paper
News
Developers
Donations
Search
Getting Started
Downloads
FAQs
Documentation
Support
Participate
How to participate
Report a Bug
Communicate
Teams/Projects
Hall of Fame
Resources
Archives
Recent Wiki Changes
Pastebin
Related Projects
VServer Hosting
Happy VServer Users
Tools
What links here
Related changes
Special pages
Page information