How to script a process upon wake up on Ubuntu



  • Create a new file in /etc/pm/sleep.d

    vi /etc/pm/sleep.d/bluetooth_restart
    

    Add the following contents to the file. You will want to replace sudo service restart bluetooth section with your own commands or point to your own script

    #!/bin/sh
    case "$1" in
        thaw|resume)
            sudo service bluetooth restart
            ;;
    esac
    

    Now when you system wakes up it will automatically perform this action.



  • You could just modify the bluetooth.service to have this :

    [Unit]
    ...
    `After=suspend.target hibernate.target hybrid-sleep.target`
    
    ...
    
    [Install]
    WantedBy=suspend.target hibernate.target hybrid-sleep.target
    


  • @stacksofplates said in How to script a process upon wake up on Ubuntu:

    You could just modify the bluetooth.service to have this :

    [Unit]
    ...
    `After=suspend.target hibernate.target hybrid-sleep.target`
    
    ...
    
    [Install]
    WantedBy=suspend.target hibernate.target hybrid-sleep.target
    

    What file are you using?

    This is what I found /etc/systemd/system/bluetooth.taget.wants/bluetooth.service

    b6be4a94-06d8-4b71-9052-a6508b604f6d-image.png


Log in to reply