I'm running owncloud client in Ubuntu and after a suspend/resume there's a bug in owncloud which makes it not be able to connect to the server.

I wrote a little script which should restart owncloud, but it doesn't. I've put it in /lib/systemd/system-sleep and the script runs. Contents:

#! /bin/sh
 case $1 in
        echo "$(date) off" >> /var/log/sulog.txt #debugging
         echo "$(date) on" >> /var/log/sulog.txt #debugging
         killall owncloud
         echo "$(date) started owncloud" >> /var/log/sulog.txt #debugging

The script executes as the log file is updated. However it doesn't kill the active owncloud instance and it doesn't start a new one either when I resume after a suspend.

When I run the script in terminal as the current user it works as I want it to.
When I run it in root it kills the owncloud instance, but it then start a new one without the server settings etc. I've worked around that with sudo -H -u <user> bash <....> to start it as another user, but then it doesn't work because it doesn't have the keychain unlocked.

How can I /usr/bin/owncloud from within the script (which is run as root) as the current user with the current session so that the icon is also added to the statusbar?


Your missing the DISPLAY definition. Also, making it depend on Network connection is better. For me on arch linux works:


 case "$2" in
               # is called as soon as connection is up
               env DISPLAY=:0 sudo -u yourusername owncloud
               # yes, maybe that is better in system-sleep
               killall owncloud

The script has to be owned by root:

sudo chown root:root /etc/NetworkManager/dispatcher.d/20-owncloud

Don't forget to make that script executable:

sudo chmod 755 /etc/NetworkManager/dispatcher.d/20-owncloud

and start/enable the NetworkManager dispatcher:

sudo systemctl start NetworkManager-dispatcher.service
sudo systemctl enable NetworkManager-dispatcher.service

At least on arch it works that way, maybe slightly other names in ubuntu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.