LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-26-2011, 01:35 PM   #1
bayoulinux
Member
 
Registered: Oct 2011
Posts: 34

Rep: Reputation: Disabled
Spawning xterm from Linux service: xterm: DISPLAY is not set


Hello:

Newbie question here...

I'm trying to create a simple Linux service that:

1. Spawns xterm
2. Within this newly spawned xterm, echoes a message.

I seem to get DISPLAY type errors when the service is run(xterm: DISPLAY is not set)... I tried to set the $DISPLAY to localhost:0, localhost:0.0, etc.. and well as "xterm -display localhost:0 ...." and still have difficulties.

Regardless, here's the code from "/etc/init.d/testscript.sh":

#! /bin/sh -e
# upstart-job
#

set -e

# Some things that run always

echo "Now going to echo display"

echo $DISPLAY

xterm -e /testing/showit.sh

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting script testscript.sh "
;;
stop)
echo "Stopping script testscript.sh"
;;
*)
echo "Usage: /etc/init.d/testscript.sh {start|stop}"
exit 1
;;
esac

exit 0


and the script "/testing/showit.sh":


#! /bin/sh -e
echo "************** THIS IS A TEST *************"
$SHELL


root@bill-ThinkPad-T500:/etc/init.d# update-rc.d testscript.sh defaults
update-rc.d: warning: /etc/init.d/testscript.sh missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/testscript.sh ...
/etc/rc0.d/K20testscript.sh -> ../init.d/testscript.sh
/etc/rc1.d/K20testscript.sh -> ../init.d/testscript.sh
/etc/rc6.d/K20testscript.sh -> ../init.d/testscript.sh
/etc/rc2.d/S20testscript.sh -> ../init.d/testscript.sh
/etc/rc3.d/S20testscript.sh -> ../init.d/testscript.sh
/etc/rc4.d/S20testscript.sh -> ../init.d/testscript.sh
/etc/rc5.d/S20testscript.sh -> ../init.d/testscript.sh



and then to to start the service I get the display message. Note you can see echo $DISPLAY shows nothing which is a big clue, but when I try to manually set it to localhost:0.0 before calling xterm is doesn't help. What should I do?

root@bill-ThinkPad-T500:/etc/init.d# service testscript.sh start
Now going to echo display

Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm Xt error: Can't open display: %s
xterm: DISPLAY is not set


or trying not as root:

bill@bill-ThinkPad-T500:/etc/rcS.d$ service testscript.sh start
Now going to echo display

xterm Xt error: Can't open display:
xterm: DISPLAY is not set


Thanks for any help...

- Bill
 
Old 11-26-2011, 05:29 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The problem is because at boot-time, there is no X server available. You can't run an xterm without one. Why do you want to run your service in an xterm? The only time I've ever needed to do this was when I wanted to start a perpetually running program that has an interactive console. I accomplished that using screen. You can start a screen session in a detached mode, and then, from your script, use screen's stuff command to stuff commandlines into the session. The commandlines that you stuff there would be contrived to start your program. You can later (after booting completes) attach to the screen session to witness your program's progress and potentially interact with it, if that's what it does. There are a lot more details to this method, but that is the general approach.
If you really need it to run in an xterm for some reason (and I can't think of any good reason), then you could have your script launch a virtual X server, Xvfb, and your xterm could use that as its server. Since it is virtual, you can't see it or interact with it. You can grab image snapshots from it, using xwd, since Xvfb creates a virtual screen in a compatible format.

--- rod.

Last edited by theNbomr; 11-26-2011 at 05:30 PM.
 
Old 11-26-2011, 08:05 PM   #3
bayoulinux
Member
 
Registered: Oct 2011
Posts: 34

Original Poster
Rep: Reputation: Disabled
Hi:

Thanks for the reply. This was purely an educational exercise to learn about Linux services and invoking init scripts and Sys V. At first I wanted to see if I could get a service to invoke at boot time... I then was settling for just invoking the service manually with "service testscript.sh start" and couldn't get past this DISPLAY problem.

if I treat testscript.sh and showit.sh as a script, not a service (omitting the part of testscript.sh that is service related), when invoking testscript.sh is opens xterm just fine. This DISPLAY problem is something that is service specific, or I should say related to properies related to invoking a service (fork?)...

I just want to be able to start a service and have it invoke an xterm and print "Hello, world". I can do it with just bash scripts, but want to tie it to a service, and then eventually tie ir to a service that gets invoked at boot time. If someone could help me do that it would be great, just so I can learn something... ;-)

Thanks!

- Bill
 
Old 11-26-2011, 08:35 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Well, you don't need an xterm in order for your service to print something. Your script's standard output stream is the linux console. Whatever you print will go there. If your program needs to stay running, you can background it, or make it a daemon (there is usually a helper function in your startup scripting somewhere to help you do that).
Usually you have to launch services as root, but any running X server will be owned by a non-root user. Some X configurations cause this to prevent the root user from accessing the X server; this is probably what is going on when you have problems launching services post-boot. There are ways around that, using X authentication tools, but I can't explain how.
My suggestion is to simply not try to launch an xterm, and use existing console facilities.

--- rod.
 
  


Reply

Tags
display, service, xterm



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xterm - howto lauch an xterm into a specific directory jobano Linux - Software 11 01-30-2023 04:45 AM
xterm error display not set fordwrench Slackware 13 12-04-2012 07:28 AM
XTerm(241) support for truetype fonts and method of changing XTerm font. ajassat Linux - Software 2 08-19-2009 12:01 PM
xterm -display remote:0.0 Can't open display - xterm from tru64 to debian 3.1 loopy69 Linux - Software 2 04-01-2008 06:54 PM
how is black xterm background in IceWM when issue a xterm command? BRAHmS Linux - Software 1 02-14-2005 03:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration