Make a script start after suspend in Ubuntu 15.04 (systemd)

There are two approaches to choose from:

Using the /lib/systemd/system-sleep/ directory:

Create another script called 00start_my_connection:

#!/bin/sh
if [ $1 = post ] && [ $2 = suspend ]
then /usr/local/bin/start_my_connection
fi

$1 is "post" on resume/thaw and "pre" otherwise. In either case, $2 contains either "suspend", "hibernate", or "hybrid-sleep". If you want the script to also run on thaw from hibernation, leave out && [ $2 = suspend ].

Ensure this script is executable by using chmod a+x 00start_my_connection

Move this script into /lib/systemd/system-sleep/ using

sudo mv 00start_my_connection /lib/systemd/system-sleep/

Using service files:

Create the file /etc/systemd/system/start_my_connection.service:

[Unit]
Description=Run start_my_connection
After=suspend.target
#After=hibernate.target
#After=hybrid-sleep.target

[Service]
ExecStart=/usr/local/bin/start_my_connection

[Install]
WantedBy=suspend.target
#WantedBy=hibernate.target
#WantedBy=hybrid-sleep.target

Uncomment all lines if you also want the script to run on thaw from hibernation. Then install the service file with:

sudo systemctl enable start_my_connection.service

Create a file 01myscript in /etc/pm/sleep.d/ directory.

Contents of that file should be:

#!/bin/bash

case $1 in 
    thaw|resume) /usr/local/bin/start_my_connection
    ;;
esac

Make that script executable: sudo chmod +x /etc/pm/sleep.d/01myscript.

Try to suspend