5

I would like to connect my VPN after wake-up.

1) I have created a script in my home (wakeup.sh)

#! /bin/bash
(echo "Sortie de veille: lancement de wakeup le $(date '+%d/%m/%Y a %H:%M')"
sleep 30
nmcli con up id "My_id_xxxxxx"
echo "-------------------END LOG-------------------") 2>&1 | tee -a /home/guillaume/sortie_veille_auto.log

2) I have created a service in /etc/systemd/system/ named wakeup.service:

[Unit]
Description=Run user script after suspend
After=basic.target
After=suspend.target
After=hibernate.target

[Service]
User=guillaume
Environment=DISPLAY=:0
ExecStart=/home/guillaume/wakeup

[Install]
WantedBy=basic.target
WantedBy=suspend.target
WantedBy=hibernate.target

3) Then, I have activated it with

systemctl enable wakeup.service

and

systemctl status wakeup.service

to verify.

4) After a try, the script is launched, but I have this error in the log:

Erreur : l'activation de la connexion a échoué : Not authorized to control networking.

What's wrong ? nmcli can work with a normal user.

Guillaume
  • 2,101

1 Answers1

1

Instead of having separate After and WantedBy, put them in a series like:

After=basic.target suspend.target hibernate.target
WantedBy=basic.target suspend.target hibernate.target

At least that worked for me. I'm not sure what the basic.target is, but I use the other two successfully like I've shown.

Byte Commander
  • 107,489