2

I keep finding similar posts online but I can't really use the solutions in my case. in my /etc/bash.bashrc file, I have the following code placed at the very bottom:

if [ -e /tmp/.X0-lock ]; then
    rm /tmp/.X0-lock
fi

startx
cd /home/user1/Documents/ProgramFile
./ myProgram.sh

This is to run my program automatically upon startup.

I'm running Debian 6.0.7 squeeze. I want to run my program as root on startup. I executed the following command to disable the GUI:

 update-rc.d -f gdm3 remove

I modified /etc/inittab to allow the root user to automatically login:

1:2345:respawn:/bin/login -f root tty1 </dev/tty1 > /dev/tty1 2>&1

when I boot up my box, I get the following error:

_XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running

Fatal server error:
Cannot establish any listening sockets - Make sure an X server isn't already running

Please consult the The X.Org Foundation support 
at http://wiki.x.org
for help. 
Please also check the log file at "/var/log/Xorg.0.log" for additional information.

(WW) xf86CloseConsole: KDSETMODE failed: Bad file descriptor   
(WW) xf86CloseConsole: VT_GETMODE failed: Bad file descriptor

Weird thing is this appears in a white box at the top left corner of my screen, it stays there fore a little while (~15 secs) and then I see my code execute and the screen changes to my application.

Q: Can anyone explain to me what is going on here and what I can do to not get the error messages.

fifamaniac04
  • 185
  • 1
  • 5
  • 13

2 Answers2

2

Your script doesn't check if X is already running.
Workaround:

if [ -e /tmp/.X0-lock ]; then
   XPID=$(cat /tmp/.X0-lock)
   if ps -p $XPID >/dev/null; then
      echo "X already running"
   else
      rm /tmp/.X0-lock
      startx
   fi
fi

cd /home/user1/Documents/ProgramFile
./myProgram.sh

However I'd do something like this:

# /etc/inittab
3:2345:respawn:/bin/login -f username tty3 < /dev/tty3 > /dev/tty3 2>&1

and

# /home/username/.bashrc
if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty3 ]; then
  startx -- :0  -quiet -logverbose 11
  cd /mydir
  ./myprog
fi

So you spawn automatically a shell on tty3. Assuming bash is your current shell, bash checks if it runs on tty3, then it executes your stuff.

1

It looks like you haven't changed your default runlevel and X Server is already running. You should have set it to 3, i.e.:

id:3:initdefault:

Although I don't think your script is going to work anyway. This part:

cd /home/user1/Documents/ProgramFile
./ myProgram.sh

is going to be executed only after X Server stopped.

UVV
  • 2,928
  • 3
  • 23
  • 36
  • I changed the default run level in `/etc/inittab` and now my box boots to the GUI for root. If I open a terminal then I get the same error message as above and my program still executes. Do you know how I could go about the part i changed in the bash.bashrc? – fifamaniac04 Jan 16 '14 at 15:52