Thursday, October 13, 2016

Running FAUCET as a systemd controlled service in Ubuntu 16

Ubuntu 16 pushes us towards systemd (https://wiki.ubuntu.com/SystemdForUpstartUsers) to manage services. In a recent installation I used this process to have FAUCET run as a service and have it automatically start on boot. 

There's more than one way to do this (in particular, you can systemd to directly start FAUCET as the correct user, rather than via sudo). We're also working on making this easier.

1. Create a user to run FAUCET as. On my system, I created a user "faucet". 

# useradd faucet

2. Install FAUCET itself. You have a few choices - here are two (pip is the easiest; the git clone will get you the latest development version).
  • pip
# pip install ryu-faucet
  • git
# cd /home/faucet/
# git clone https://github.com/REANNZ/faucet

3. Identify the root of the FAUCET installation faucet.py is in your installation. 

# find / -name faucet.py
/home/faucet/faucet/src/ryu_faucet/org/onfsdn/faucet/faucet.py

In my case, it's /home/faucet/faucet

4. Create a file,/etc/default/faucet,  containing the following. Substitute in the correct values for your FAUCET installation path, and where you want your config files and logs. Don't forget that the log files will need to be writable by the faucet user, so make sure there's a directory faucet can write to.

# path to Ryu manager (likely local)
RYU_MANAGER=/usr/local/bin/ryu-manager
# user to run FAUCET as (must already exist)
FAUCET_USER=faucet
# directory containing FAUCET application code
FAUCET_APP_DIR=/home/faucet/faucet/src/ryu_faucet/org/onfsdn/faucet
# file containing Gauge's custom ryu.conf
FAUCET_RYU_CONF=/home/faucet/faucet/src/cfg/etc/ryu/ryu.conf
# host address FAUCET controller should listen on for OpenFlow switch
FAUCET_LISTEN_HOST=10.0.0.1
# TCP port FAUCET controller should listen on for OpenFlow switch
FAUCET_LISTEN_PORT=6636
# location of FAUCET's configuration file.
FAUCET_CONFIG=/etc/faucet/faucet.yaml
# where FAUCET should log to (directory must exist and be writable by FAUCET_USER)
FAUCET_LOG=/var/log/faucet/faucet.log
# where FAUCET should log exceptions to (directory must exist as above)
FAUCET_EXCEPTION_LOG=/var/log/faucet/faucet_exception.log

5. Create another file, /home/faucet/start-faucet.sh, that will start FAUCET (and don't forget to make it executable):

#!/bin/bash
DEFAULTFILE=/etc/default/faucet
. $DEFAULTFILE
export FAUCET_CONFIG
export FAUCET_LOG
export FAUCET_EXCEPTION_LOG
sudo -E -u $FAUCET_USER $RYU_MANAGER --config-file=$FAUCET_RYU_CONF --ofp-listen-host=$FAUCET_LISTEN_HOST --ofp-tcp-listen-port=$FAUCET_LISTEN_PORT $FAUCET_APP_DIR/faucet.py

6. Create the last file, /etc/systemd/system/faucet.service that defines the FAUCET service:

[Unit]
description="FAUCET OpenFlow switch controller"
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/home/faucet/start-faucet.sh
Restart=always

[Install]
WantedBy=multi-user.target

7. Enable the systemd-networkd-wait-online.service service. This has systemd wait for the network to come up, before trying to start FAUCET:

# systemctl enable systemd-networkd-wait-online.service

8. Enable the FAUCET service you just created:

# systemctl enable faucet

9. Start FAUCET and view its status:

# systemctl start faucet
# systemctl status faucet




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.