Install N2N as a Service on FreeBSD

Why do I want to? Because I run the incredibly awesome FreeNAS on a small server, and the jails are FreeBSD. One of those jails is supposed to be a in an N2N VPN, so I can access the files from elsewhere.

First, put this into /etc/rc.d/edge:

#!/bin/sh
# PROVIDE: edge
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="edge"
rcvar=$(set_rcvar)
command="/wherever/you/have/n2n/edge"
start_cmd="edge_start"
stop_cmd="edge_stop"
load_rc_config $name

edge_start()
{
 export N2N_KEY;
 "$command" -a "$edge_ip" -u "$edge_uid" -g "$edge_gid" -c "$edge_community" -l "$edge_supernode";
}

edge_stop()
{
 killall edge;
}

run_rc_command "$1"

Then add the following to your /etc/rc.conf:

N2N_KEY="..."
edge_enable="YES"
edge_ip="192.168.312.14"
edge_uid="1000"
edge_gid="1000"
edge_community="cupcakes"
edge_supernode="cupcakes.sweet.stuff:2016"

And your edge client will run as a service.

Leave a Reply

Your email address will not be published. Required fields are marked *