Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

[SOLVED] openvpn, dhcp, suspend and hooks

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
hujuice
Guru
Guru
User avatar
Posts: 354
Joined: Tue Oct 16, 2007 12:57 pm
Location: Nicosia, Cyprus

[SOLVED] openvpn, dhcp, suspend and hooks

  • Quote

Post by hujuice » Wed Mar 12, 2025 7:31 am

My openvpn crashes when resuming from the hibernation.
The reason is quite clear: the physical network is inactive because of the DHCP.
Both elogind and dhcpcd have hooks to handle the problem, but the solution I have found is quite "spaghetti".

dhcpcd is not aware of suspend, so the only way is to use a pre-suspend elogind hook.
On the other side, elogind is not aware of the dhcpcd procedure after resume (lost carrier, rebinding, bla bla), so the only way is a post-binding dhcpcd hook.

The two hooks work, but I find a bit strange to manage two complementary operations with different tools.
Better ideas?

Code: Select all

#!/bin/bash
# -- Stop openvpn before suspend
#
# NOTE: openvpn is stopped here, before suspend, but NOT
#       restarted here, because a bounded dhcp address is
#       necessary. A dhcp hook is used for that.
#       See: /etc/dhcpcd.exit-hook

case $1/$2 in
  pre/*)
    /usr/bin/logger -p daemon.info "Stopping openvpn.home before suspend."
    /etc/init.d/openvpn.home stop
    ;;
esac

Code: Select all

# -- Start openvpn after suspend
#
# NOTE: the runlevel is restored here, but openvpn has been
#       stopped with an elogind hook.
#       See: /etc/elogind/system-sleep/stop-openvpn-before-suspend

if [ "${interface}" = "eth0" ]; then
    if [ "${reason}" = "BOUND" ]; then
        /usr/bin/logger -p daemon.info "Restoring runlevel after bound."
        /usr/bin/openrc
    fi
fi
Regards,
HUjuice
Last edited by hujuice on Thu Mar 13, 2025 8:28 am, edited 1 time in total.
Those who lack character must at least have a method.
Chi non ha carattere, deve pur avere un metodo.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Wed Mar 12, 2025 11:45 am

I used to have an acpid hook that would restart my wifi after suspend. It was basically a crash recovery action.
It didn't even matter whether it was triggered by suspend event or resume event, because a suspended machine doesn't do anything useful anyway, so the restart would be relayed until after resume.
Make Pipewire a system service
Top
hujuice
Guru
Guru
User avatar
Posts: 354
Joined: Tue Oct 16, 2007 12:57 pm
Location: Nicosia, Cyprus

  • Quote

Post by hujuice » Thu Mar 13, 2025 8:27 am

The solution is quite simple: manage the appropriate rc dependencies and stop the network before suspend.
openrc will do the job.

Code: Select all

rc_need="net.eth0"

Code: Select all

#!/bin/bash
# Stop the network to avoid openpvn crashes

NET="net.eth0"

case $1 in
    pre)
        if /etc/init.d/"${NET}" status; then
            /usr/bin/logger -p daemon.info "Stopping network before suspend."
            /etc/init.d/"${NET}" stop
        fi
        ;;
    post)
        /usr/bin/logger -p daemon.info "Restoring runlevel."
        /usr/bin/openrc
        ;;
esac
Those who lack character must at least have a method.
Chi non ha carattere, deve pur avere un metodo.
Top
Post Reply

3 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic