Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
systemd + lxc + bridging réseau
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
ceone_
n00b
n00b


Joined: 02 Aug 2013
Posts: 6

PostPosted: Fri Aug 02, 2013 11:40 am    Post subject: systemd + lxc + bridging réseau Reply with quote

Bonjour,

Venant de passer à systemd par la force des choses (...) je me retrouve confronté au problème suivant:
J'utilise des LXC et avant sous openrc le script d'init "instanciait" automatiquement le bridge réseau lorsque je lançais mon conteneur.

Comment arriver à ce résultat avec systemd ?
Back to top
View user's profile Send private message
ceone_
n00b
n00b


Joined: 02 Aug 2013
Posts: 6

PostPosted: Sat Aug 03, 2013 12:04 pm    Post subject: Reply with quote

Peut-être avais-je mal formulé ma demande en tout cas j'ai fini par résoudre mon problème de la façon suivante:
premièrement faire un unit qui s'occupe de créer le bridge

Code:

# cat /usr/lib/systemd/system/net-bridge\@.service
[Unit]
Description=Init a bridge
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c "/usr/local/bin/init-bridge %i /etc/conf.d/net"
RemainAfterExit=yes



cet unit lance un script qui crée le bridge si celui-ci n'existe pas (il y a certainement mieux à faire comme bash mais ça a déjà le mérite de marcher :))
Code:

# cat /usr/local/bin/init-bridge
#/bin/bash

BRIDGE_NAME="$1"
CONFIG="$2"

BRCTL=`which brctl`

IFCONFIG=`which ifconfig`

ROUTE=`which route`

source $2

BR_ROUTE_NAME="routes_"$BRIDGE_NAME
BR_CONFIG_NAME="config_"$BRIDGE_NAME
BRCTL_P_NAME="brctl_"$BRIDGE_NAME

if [ $((`$BRCTL show | grep $BRIDGE_NAME | wc -l`)) -eq 0 ]
then
   #brctl addbr br0
   $BRCTL addbr $BRIDGE_NAME

   #parsing params
   counter=0
   for i in ${!BRCTL_P_NAME}
   do
   if [ $(( $counter % 2 )) -eq 0 ]
   then
   command=$i
   else
   $BRCTL $command $BRIDGE_NAME $i
   command=null
   fi
   counter=$(( $counter + 1))
   done
   $IFCONFIG $BRIDGE_NAME `echo ${!BR_CONFIG_NAME} | sed -e 's/brd/broadcast/g' `
   $IFCONFIG $BRIDGE_NAME up
   $ROUTE add -net `echo ${!BR_ROUTE_NAME} | sed -e 's/via/gw/g'`
fi

exit 0


puis faire un unit de lancement des lxc
Code:

#cat /usr/lib/systemd/system/lxc\@.service
[Unit]
Description=Linux Container %i
After=net-bridge@br0.service
Requires=net-bridge@br0.service

[Service]
Type=forking
ExecStartPre=/bin/mount --make-rprivate /
ExecStart=/usr/sbin/lxc-start -dn %i
ExecStop=/usr/sbin/lxc-stop -n %i

[Install]
WantedBy=multi-user.target



j'ai trouvé ce dernier sur le wiki d'archlinux et l'ai modifié afin qu'il lance l'initialisation du bridge lors de son exécution.


En espèrant que ça puisse aider quelqu'un d'autre.

François
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
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