1

I have an application which makes use of a 3dconnexion space mouse. It works fine when using the spacenavd daemon however I'm having issues getting the daemon to run at boot or as a service.

$ sudo service spacenavd start

in /var/log/spnavd.log

Spacenav daemon 0.5
failed to open config file /etc/spnavrc: No such file or directory. using defaults.
Device detection, parsing /proc/bus/input/devices
using device: /dev/input/event5
device name: 3Dconnexion SpaceNavigator
trying to open X11 display ":0.0"
XAUTHORITY=/root/.Xauthority
No protocol specified
No protocol specified
failed to open X11 display ":0.0"
waiting for X socket file to appear

When I run the system V init script however, I don't have any issues:

$ sudo /etc/init.d/spacenavd start

in /var/log/spnavd.log

Spacenav daemon 0.5
failed to open config file /etc/spnavrc: No such file or directory. using defaults.
Device detection, parsing /proc/bus/input/devices
using device: /dev/input/event5
device name: 3Dconnexion SpaceNavigator
trying to open X11 display ":0"
XAUTHORITY=/home/sam/.Xauthority

The problem is that I need the daemon to start from boot instead of launching it manually which requires sudo access.

Edit (suggestion from muru)

I made the following upstart script

description "Spacenavd upstart script. Starts after lightdm to allow for binding with the Xorg server"
author "Samuel Charreyron"

start on started lightm
stop on shutdown

pre-start script
    echo "Starting spacenavd daemon"
end script

script 
    env DISPLAY=:0.0
    exec /usr/sbin/spacenavd -v -d 2> /var/log/spnavd.log
end script

pre-stop script
    echo "Stopping spacenavd daemon"
    # detect daemon's process id
    pid=`cat /var/run/spnavd.pid 2>/dev/null`
    if [ $? != 0 ]; then
        pid=`ps -e | grep spacenavd | awk '{ print $1 }'`
        if [ -z "$pid" ]; then
             echo 'spacenavd daemon is not running, nothing to do.'
             exit 1
        fi
    fi
    kill $pid
end script

I see that spacenavd cannot connect to the Xorg server. In fact, any upstart script that is run by root seems unable to use Xorg. How can I do so, since spacenavd needs sudo access to the USB devices?

  • Does spacenavd have an Upstart configuration file? – muru Dec 5 '14 at 15:25
  • I don't think so. It relies on System V I believe. – user3293204 Dec 6 '14 at 18:30
  • Then I don't see how it is a problem with Upstart. Upstart starts sysv init scripts without any problem. Something might be causing it to fail. – muru Dec 6 '14 at 18:35
  • I'm not sure, I think the way upstart starts the sysv init script, it cannot connect to the Xorg server. – user3293204 Dec 10 '14 at 17:53
  • It's possible Upstart starts it before it starts X. And without an Upstart configuration file, we cannot order it as well. IMHO the simplest way would be for you to write a startup script that restarts the service once X starts. – muru Dec 10 '14 at 17:56
1

The root does not have access to Xserver by default. In order to enable it, you need to copy your /home/sam/.Xauthority file to /root/.Xauthority

sudo cp /home/sam/.Xauthority /root/

After the reboot simply enable the spacenavd daemon at the boot:

sudo service spacenavd enable

And start the spacenavd service:

sudo service spacenavd start

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.