Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My working FreeBSD startup scripts #264

Closed
krolingo opened this issue Dec 7, 2022 · 6 comments
Closed

My working FreeBSD startup scripts #264

krolingo opened this issue Dec 7, 2022 · 6 comments
Labels

Comments

@krolingo
Copy link

krolingo commented Dec 7, 2022

For anyone interested, here are my scripts to get this working properly on FreeBSD:

1. wireguard-ui daemon: /usr/local/etc/rc.d/wireguard-ui

#!/bin/sh
#
# PROVIDE: wireguard_ui
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable wireguard_ui:
#
# wireguard_ui_enable="YES"
#

. /etc/rc.subr
name="wireguard_ui"
rcvar=wireguard_ui_enable
procname="/usr/local/opt/wireguard-ui/wireguard-ui"
pidfile="/var/run/wireguard_ui.pid"
wireguard_ui_chdir="/usr/local/opt/wireguard-ui"
wireguard_ui_env_file="/usr/local/opt/wireguard-ui/env"

command="/usr/sbin/daemon"
command_args=" -s notice -p ${pidfile} -f ${procname} ${wireguard_ui_env_file}"

stop_postcmd="wireguard_ui_poststop"

wireguard_ui_poststop()
{
    rm -f $pidfile
}

load_rc_config ${name}

: ${wireguard_ui_enable="NO"}
: ${wireguard_ui_pidfile="/var/run/${name}.pid"}

run_rc_command "$1"

2. daemon to watch for changes made by wireguard-ui then restart wireguard to commit the changes

#!/bin/sh
#
# PROVIDE: wgui
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable wgui:
#
# wgui_enable="YES"
#

. /etc/rc.subr

name="wgui"
rcvar=wgui_enable
procname="/usr/local/opt/wgui/wgui"
pidfile="/var/run/wgui.pid"
#wgui_chdir="/usr/local/opt/wgui/"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} ${procname}"

stop_cmd="${name}_stop"
stop_postcmd="${name}_poststop"


wgui_stop()
{
        if [ -f $pidfile ]; then
                echo "Stopping wgui."
                kill $(cat $pidfile)
                echo "Stopped wgui."
        else
                echo "wgui is not running."
                exit 0
        fi
}


wgui_poststop()
{
        rm -f  $pidfile
}

load_rc_config ${name}

: ${wgui_enable="NO"}
: ${wgui_pidfile="/var/run/${name}.pid"}

run_rc_command "$1"

3. script for the daemon:

#!/bin/sh
PATH="$PATH:/usr/local/bin"
while inotifywait -e modify -e create  /usr/local/etc/wireguard/; do
  wg-quick down wg0
  wg-quick up wg0
done

Caveat: For the wgui script to work you will need to install inotify-tools first.
# pkg install inotify-tools

@joeldahl
Copy link

Maybe submit this to the FreeBSD ports collection?

@stale
Copy link

stale bot commented Feb 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 18, 2023
@esmoyer
Copy link

esmoyer commented Mar 8, 2023

Got got this all setup, and try to start the service, but even though it says it's starting when I try service wireguard-ui status, it says it's not running. Can't seem to figure out what I missed, would you happen to have any insight?

EDIT: Got it running, but the only thing I can't seem to figure out is how to get the peers/clients to be seen by OPNsense, but maybe that isn't possible?

@stale stale bot removed the stale label Mar 8, 2023
@stale
Copy link

stale bot commented May 8, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 8, 2023
@stale stale bot closed this as completed May 21, 2023
@krolingo
Copy link
Author

Got got this all setup, and try to start the service, but even though it says it's starting when I try service wireguard-ui status, it says it's not running. Can't seem to figure out what I missed, would you happen to have any insight?

EDIT: Got it running, but the only thing I can't seem to figure out is how to get the peers/clients to be seen by OPNsense, but maybe that isn't possible?

did you get the "connected peers" feature working?

@esmoyer
Copy link

esmoyer commented Jul 10, 2023

Unfortunately not, I gave up and when back to using Wireguard in OPNsense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants