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!
== Running services == Say you have a vserver called <tt>squid</tt>, and you want to run your <tt>squid</tt> proxy inside it to keep it insulated from the other processes on the system, and vice versa. In our current setup, the following run script will do the trick (it borrows a bit from Debian's initscript and uses the Debian defaults file): <pre> #!/bin/sh exec 2>&1 # Set a default for max. filedescriptors SQUID_MAXFD=4096 # Figure out the name of the service we're running as SVNAME=$(basename $(pwd)) # Read the configfile of this service; if it sets VSERVERNAME, we'll assume we have to run inside the specified vserver CONFIG=/etc/default/"$SVNAME" [ -r "$CONFIG" ] && . "$CONFIG" # Source Debian defaults [ -n "$VSERVERNAME" ] && VROOT="/etc/vservers/$VSERVERNAME/vdir" || VROOT=/ [ -r "$VROOT/etc/default/squid" ] && . "$VROOT/etc/default/squid" [ "$SQUID_MAXFD" -gt 4096 ] && SQUID_MAXFD=4096 if test -f /proc/sys/fs/file-max; then global_file_max=$(cat /proc/sys/fs/file-max) minimal_file_max=$(($SQUID_MAXFD + 4096)) [ "$global_file_max" -lt "$minimal_file_max" ] && echo "$minimal_file_max" >/proc/sys/fs/file-max fi if [ ! "$VSERVERNAME" = "" ]; then VSERVERARGS="signal-relay vserver $VSERVERNAME exec" vserver "$VSERVERNAME" status || vserver "$VSERVERNAME" start # start the vserver if necessary fi exec chpst -o"$SQUID_MAXFD" $VSERVERARGS squid -N -D -sYC </pre> This script is generic in the sense that it works with or without a vserver setup. You can run an <tt>svlogd</tt> for this service like you normally would; or you could have all your <tt>svlogd</tt>s run in a different vserver. A run script for <tt>cron</tt> that automatically figures out if it should run in a vserver: <pre> #!/bin/sh exec 2>&1 DEPENDENCIES="" RLIMIT="chpst -t 172800" SVNAME=$(basename $(pwd)) CONFIG=/etc/default/"$SVNAME" # Assume part after dash is name of vserver if [ ! "${SVNAME/*-/}" = "$SVNAME" ]; then VSERVERNAME="${SVNAME/*-/}" fi # By default, we depend on the socklog service if it exists [ -e /service/socklog ] && DEPENDENCIES=socklog # And also on the logrelay service of the pertinent vserver [ -e /service/vserver-logrelay-"$VSERVERNAME" ] && DEPENDENCIES="$DEPENDENCIES vserver-logrelay-$VSERVERNAME" # Can override VSERVERNAME, RLIMIT and DEPENDENCIES here if necessary [ -r "$CONFIG" ] && . "$CONFIG" if [ ! "$VSERVERNAME" = "" ]; then VSERVERARGS="signal-relay vserver $VSERVERNAME exec" vserver "$VSERVERNAME" status || vserver "$VSERVERNAME" start fi if [ -n "$DEPENDENCIES" ]; then sv start $DEPENDENCIES || exit 1 fi exec $RLIMIT $VSERVERARGS cron -f </pre> Now, if you place this run script in a service directory called <tt>cron-squid</tt>, it will run a cron daemon in the <tt>squid</tt> guest. This takes care of rotating the squid logs under <tt>/var/log/squid</tt>, for example; although this could also be done on the host with a few kludges. The vserver-logrelay-template/run script looks like this: <pre> #!/bin/sh exec 2>&1 SVNAME=$(basename $(pwd)) RUNASUSER=logrelay MODE=666 VSERVERNAME=$(echo $SVNAME | sed 's/vserver-logrelay-//') [ -r "/etc/default/$SVNAME" ] && . "/etc/default/$SVNAME" exec socat -d -d -d -D -ls -u \ UNIX-LISTEN:/etc/vservers/$VSERVERNAME/vdir/dev/log,unlink-early,nonblock,mode=$MODE,setuid=$RUNASUSER \ UNIX-CONNECT:/dev/log,type=2,nonblock,forever </pre> This will pass syslog messages from a vserver to the syslog of the host by acting as a syslog server for the <tt>/dev/log</tt> socket of the guest. Thus, you don't need to run a <tt>syslogd</tt> inside the vserver and you don't need to migrate to <tt>syslog-ng</tt> from <tt>socklog</tt> on the host. Symlink this run script into a service directory called <tt>vserver-logrelay-squid</tt>. Unfortunately, <tt>socat</tt> has a largish memory footprint; something more lightweight could, perhaps, be used. Comments and additions welcome.
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