You are not logged in.

#1 2023-11-23 18:09:34

AndreyFrantsevich
Member
Registered: 2023-10-30
Posts: 15

Run a unit after change Wi-Fi network.

Hello!
I have a proxy with sing-box. It works correct. But if I have connection A Wi-Fi, then I connect to B Wi-Fi, I need to restart my sing-box unit.
So I want to write a unit, which restarts sing-box unit after the change Wi-Fi network.
I've tried the way from Wiki, but it doesn't work.

/etc/systemd/system/foo.service
[Unit]
...
Wants=network-online.target
After=network-online.target nss-lookup.target
...

There is my current version:

[Unit]
Description=Xray reconnect after change wifi
Wants=network-online.target
After=network-online.target
Requisite=sing-box.service
After=sing-box.service


[Service]
Type=forking
Environment=SUDO_USER=andrew
ExecStart=/usr/bin/systemctl restart sing-box

[Install]
WantedBy=network-online.target

Offline

#2 2023-11-23 19:04:52

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: Run a unit after change Wi-Fi network.

Explain what specifically "doesn't work" means? The unit doesn't activate? There's errors thrown in your journal?

What are you using for your network configuration? Check if that tool supports hooks, which are typically the go-to places to configure something like this. NetworkManager, for example, has a Dispatcher.

Offline

#3 2023-11-24 13:26:37

AndreyFrantsevich
Member
Registered: 2023-10-30
Posts: 15

Re: Run a unit after change Wi-Fi network.

twelveeighty wrote:

Explain what specifically "doesn't work" means? The unit doesn't activate? There's errors thrown in your journal?

What are you using for your network configuration? Check if that tool supports hooks, which are typically the go-to places to configure something like this. NetworkManager, for example, has a Dispatcher.

I have tried to use Network Manager dispatcher, but it only works if I turn off and turn on Wi-Fi connection.

Is there a way, that dispatcher runs the script after changing Wi-Fi network?

Offline

Board footer

Powered by FluxBB