Как запустить приложение с графическим интерфейсом с upstart?

638
goGud

Я боролся с этой проблемой в течение трех дней, и я попробовал много способов решить ее, но пока не увенчался успехом. Я надеюсь, что вы, ребята, можете мне помочь ...

У меня есть приложение с графическим интерфейсом. Я хочу запустить это приложение автоматически. И когда он неожиданно закрывается или закрывается, я хочу снова открыть это приложение.

Я попытался использовать скрипт upstart, однако, хотя нет проблем с сервисами upstart, приложение GUI не запускается с скрипт upstart. Он говорит, что не может подключиться к X-серверу ..

Должен ли я добавить или изменить некоторые параметры, чтобы они открывались с помощью upstart, или есть ли способ автоматически открывать приложение с графическим интерфейсом, когда происходит неожиданный выход или завершение работы (не один раз после входа в систему, я имею в виду не при запуске)?

Спасибо за вашу любезную поддержку ...

0

1 ответ на вопрос

0
a CVn

You cannot launch a graphical application through upstart, or any other init system, because at the time that upstart is executing, X (the graphical environment) is not yet started.

In Windows, the graphical environment is an integral part of the operating system; even Windows Server Core is graphical at heart (even though it only presents you with a command prompt window). Linux, on the other hand, takes the opposite approach: the system itself is text-based only, and the graphical environment is provided by a userspace application running on top of that.

So unfortunately, there is no easy way to do what you appear to be after.

That said, you might be able to work around the limitation. Many desktop environments provide the ability to define a list of applications that will be launched when you log in (or more accurately, start the desktop environment). You could write a script that launches the application in a tight loop and exits when the application exits with a zero exit status (which is normal for "successful exit without a problem"). Whether this will work for you or not depends on your definition of "unexpected exit".

A naiive implementation might be something along the lines of:

#!/bin/bash while true do my-app || exit Xdialog --timeout 15 --yesno "Program exited. Restart it?" 2 50 test "$?" = "0" -o "$?" = "255" || exit done 

The || means "execute the following if the exit status from the previous was non-zero" (it is read "or"). See the Xdialog documentation for how that one works; basically, it prompts you whether you want to keep running the program, and if you answer Yes or don't answer anything at all within 15 seconds, it relaunches the program by running the loop once more. Make the script file executable and point your desktop environment at launching it on login, and my-app will run until you explicitly close it and tell the system to not restart it.

Я использую CentOs, я попробовал ваше предложение, после запуска этого скрипта, когда я убиваю процесс приложения (не перезапускаю скрипт!). Это дает ошибку дампа ядра, и нет никакого диалога для запуска его снова .. goGud 9 лет назад 0

Похожие вопросы