如何在Linux中自动启动需要X的应用程序 [英] How do I automatically start an application that needs X in Linux

查看:92
本文介绍了如何在Linux中自动启动需要X的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在系统进入运行级别5时自动启动X应用程序.

I'm trying to start an X application automatically when the system enters run level 5.

正确的方法是什么?

我已经编写了一个脚本并将其放在/etc/init.d/

I've written a script and put it in /etc/init.d/

我已经运行了适当的chkconfig命令,以在/etc/rcX.d目录中设置符号链接.

I've run the appropriate chkconfig commands to setup up the symbolic links in the /etc/rcX.d directories.

一切正常,但运行时脚本无法启动X应用程序:

Everything works fine except the script can't start the X application when I run:

/sbin/service scriptName start

这行看起来像这样(为了论证,我已经在xclock中切换了):

The line looks like this (I've switched in xclock for the sake of argument):

'start')
xclock

我收到以下错误:

Error: Can't open display:

经过一些研究,似乎/sbin/service从典型的shell中删除了大多数环境变量.通过添加DISPLAY:

After some research it appears that /sbin/service removes most of the environment variables from a typical shell. By adding DISPLAY:

'start')
DISPLAY=:0
export DISPLAY
xclock

我得到:

Error: Can't open display: :0

我修改了脚本,使其包括:

I modified my script to include:

'start')
DISPLAY=:0
export DISPLAY
XAUTHORITY=/root/.xauth2w90ge
export XAUTHORITY
xclock

现在它可以正常工作-但这显然是一个黑客,因为生成了.xauth2w90ge文件,并且实例之间的实例将不再相同.

And now it works - but this is obviously a hack as the .xauth2w90ge file is generated and won't be the same from instance to instance.

那么,有没有适当的方法来执行此操作,或者我是在错误的树上吠叫?我的要求是使该应用程序与计算机一起自动启动,并且我受可以在RPM安装后脚本中运行的任何命令和权限的限制.

So is there a proper way to do this, or am I barking up the wrong tree? My requirement is to have this application autostart with the machine and I am limited by whatever commands and permissions I can run in an RPM postinstall script.

推荐答案

您应该让X(或您的窗口管理器)自动启动该过程,而不是定义一个初始化脚本. X,KDE和Gnome都有自动启动的方式(即〜/.kde4/Autostart).

Rather than defining an init script, you should be having X (or your window manager) start the process automatically. X, KDE, and Gnome all have ways of automatically starting things up (i.e. ~/.kde4/Autostart).

如果这只是X,请修改/etc/X11/xinit/xinitrc文件(或等效文件)以使其运行命令.我的文件的底部看起来像这样:

If this IS just X, go modify your /etc/X11/xinit/xinitrc file (or equivalent) to have it run your command. Mine looks like this at the bottom of the file:

if [ -n "$failsafe" ]; then
    twm &
    xclock -geometry 50x50-1+1 &
    xterm -geometry 80x50+494+51 &
    xterm -geometry 80x20+494-0 &
    exec xterm -geometry 80x66+0+0 -name login
else
    exec $command
fi

因此,您将对其进行更改以运行所需的任何命令.

So you would change that to run whatever command you want.

这篇关于如何在Linux中自动启动需要X的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆