Skip to content

Instantly share code, notes, and snippets.

@pr0way
Last active January 31, 2024 09:49
Show Gist options
  • Select an option

  • Save pr0way/48e18c9584d4b5ecb96f593dec9a938c to your computer and use it in GitHub Desktop.

Select an option

Save pr0way/48e18c9584d4b5ecb96f593dec9a938c to your computer and use it in GitHub Desktop.
Simple init script to up & down wireguard
  1. Go to /etc/init.d directory
  2. Create file with name "wireguard" and content below.
  3. Make file executable chmod +x wireguard
  4. Add to rc-update: rc-update add wireguard default
  5. That's it
#!/sbin/openrc-run
depend() {
need localmount
need net
}
start() {
ebegin "Starting wireguard"
/usr/bin/wg-quick up wg0
eend $?
}
stop() {
ebegin "Stopping wireguard"
/usr/bin/wg-quick down wg0
eend $?
}
@Tiger-Tom
Copy link

This worked! Thank you :)

@epiecs
Copy link

epiecs commented Jan 29, 2022

Hi,

At step 4 you have written defualt instead of default. This might confuse people not used to working with Linux :)

Thanks for the init script!

Kr, Gregory

@pr0way
Copy link
Author

pr0way commented Feb 2, 2022

@epiecs Yes, you're right 👍 Corrected.

@DavidRLTG
Copy link

Hi there! I'm on Devuan OpenRC.
I use wgcf as my wireguard config,
wgcf-profile.conf
If I try adding this to my init, it gives some sort of errors about localmount and net. Do I need to replace them?
Am I dumb? I really dunno how to get this script working. Help?

@epiecs
Copy link

epiecs commented Jan 26, 2024

I wrote a guide some time ago on how to work with alpine. It is in dutch though but google translate should be able to help you. Here is the section on how to work with services: https://github.com/epiecs/alpine-guide#zelf-service-scripts-schrijven.

@DavidRLTG
Copy link

I wrote a guide some time ago on how to work with alpine. It is in dutch though but google translate should be able to help you. Here is the section on how to work with services: https://github.com/epiecs/alpine-guide#zelf-service-scripts-schrijven.

Thank you! I followed the Wireguard part, but it did nothing sadly, I followed every step I swear.
Any ideas?

@epiecs
Copy link

epiecs commented Jan 31, 2024

not atm, You'll have to look at errors/logs and check what is happening. Maybe try a wg show etc and also test if your wg setup works without the init file. Just plain old wg-quick up <int>

@DavidRLTG
Copy link

Second part is already invalid, it doesn't work without it or with it, but I'll try seeing logs! Thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment