#!/usr/bin/env ssm
# Two warnings:
# 1) This script uses a script to run cjdroute and feed it
#	 the config. It can be found in the main cjdns repo:
#	 contrib/sh/run-cjdroute.sh
#	 Or here: http://ix.io/fYT
# 2) service_respawn is disabled by default because you need
#    "noBackground":1 in cjdroute.conf for it to actually work.
#    Barely.

unset reload

service_respawn=true
service_command='/usr/bin/run-cjdroute'
cjdroute_admin_port='11234'

cjdroute.check_tun_module() {
	[[ -e '/dev/net/tun' ]] || {
		modprobe tun || {
			printf 'Could not load module tun!\n'
			return 1
		}
	}
}

pre_start() {
	cjdroute.check_tun_module
}