Правильный способ запустить xvfb при запуске на centos?

20699
Stefan Kendall

Я следую этому уроку и хочу узнать эквивалентную centos-версию этого специфичного для Ubuntu шага:

You may receive a few warnings regarding fonts and such, but it’ll still work despite these. If you want the framebuffer to start automatically on system startup you can do: sudo update-rc.d xvfb defaults 10 

Как правильно запустить xvfb при запуске на centos?

10

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

18
JdeBP

And now, the systemd answer.

It has been almost four years since these questions and answers, and the world has changed whilst they have not. Since version 7, CentOS has used systemd. Ubuntu is mentioned in the question and in comments. Since version 15, Ubuntu has used systemd too.

Although one can use System 5 rc scripts under systemd, the scripts in answers here are highly suboptimal, to say the least. One blithely uses killall, whose problems for dæmon management are well known; and the other is a mess of rickety lock file and PID file logic none of which is actually necessary under a service manager, since service managers themselves keep track of dæmon processes.

As I have said elsewhere, if you're starting to learn this stuff and are on CentOS Linux version 7 or later or Ubuntu Linux version 15 or later, don't begin with System 5 rc scripts in the first place. Begin with systemd unit files.

a template for multiple Xvfb services

Simple xvfb.service systemd unit files for xvfb can be found at https://www.centos.org/forums/viewtopic.php?f=48&t=49080#p208363 and at https://askubuntu.com/a/621256/43344 . However, as I mentioned at the latter one can also take a templatized approach:

[Unit] Description=virtual frame buffer X server for display %I After=network.target [Service] ExecStart=/usr/bin/Xvfb %I -screen 0 1280x1024x24 [Install] WantedBy=multi-user.target 

As a locally-written, non-system non-packaged, unit file for system-wide (as opposed to per-user) services this goes into /etc/systemd/system/xvfb@.service of course.

controlling the services

One instantiates the template, into an actual named service, with the display number that is desired. For display :99, therefore, there is an actual service instance named xvfb@:99.service.

  • Set the service to auto-start on bootstrap with systemctl enable xvfb@:99.service .
  • Unset auto-starting the service with systemctl disable xvfb@:99.service .
  • Start the service manually with systemctl start xvfb@:99.service .
  • Stop the service manually with systemctl stop xvfb@:99.service .
  • Inspect the current service status in detail with systemctl status xvfb@:99.service .

Further reading

ссылка для «Добавление xvfb к системным службам» не работает. Manish 8 лет назад 0
Упомянутый выше вопрос SuperUser был автоматически удален. К счастью, тот, кто задает вопрос, опубликовал это. ☺ JdeBP 8 лет назад 0
12
Tacticus

Я использую следующий сценарий инициализации, чтобы добавить и запустить xvfb при загрузке, просто распаковать его в /etc/init.d/ и запустить chkconfig xvfb на

 #!/bin/bash #chkconfig: 345 95 50 #description: Starts xvfb on display 99 if [ -z "$1" ]; then echo "`basename $0` " exit fi  case "$1" in start) /usr/bin/Xvfb :99 -screen 0 1280x1024x24 & ;;  stop) killall Xvfb ;; esac 
dont forget add execute permission to this file: chmod +x xvfb panchicore 11 лет назад 1
Несмотря на то, что его вопрос был задан для CentOS, он стал полезным и для других дистрибутивов. Это хорошо работает на Ubuntu; вам просто нужно запустить `update-rc.d` вместо` chkconfig`. См. [Этот ответ] (http://askubuntu.com/questions/2263/chkconfig-alternative-for-ubuntu-server) для получения дополнительной информации о `update-rc.d`. sigpwned 10 лет назад 2
Вопрос был о том, как это сделать на CentOS. Текущий CentOS использует systemd, и этот ответ не решает вопрос. Ответ от JdeBP более уместен. Yoichi 6 лет назад 1
Учитывая, что вопрос был задан 6 лет назад, когда существующей версии centos не существовало (как и systemd iirc). Решение systemd, тем не менее, намного лучше и должно быть предпочтительным вариантом, когда это возможно. Tacticus 6 лет назад 0
4
Thilo

Here's a nice init script to accomplish this:

http://onemoretech.wordpress.com/2009/05/27/an-xvfb-init-script/

The script is:

#!/bin/bash # # /etc/rc.d/init.d/xvfbd # # chkconfig: 345 95 28 # description: Starts/Stops X Virtual Framebuffer server # processname: Xvfb # . /etc/init.d/functions [ "$" = "no" ] && exit 0 PROG="/usr/X11R6/bin/Xvfb" PROG_OPTIONS=":5 -screen 0 640x480x24" PROG_OUTPUT="/tmp/Xvfb.out" case "$1" in start) echo -n "Starting : X Virtual Frame Buffer " $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 & disown -ar /bin/usleep 500000 status Xvfb & >/dev/null && echo_success || echo_failure RETVAL=$? if [ $RETVAL -eq 0 ]; then /bin/touch /var/lock/subsys/Xvfb /sbin/pidof -o %PPID -x Xvfb > /var/run/Xvfb.pid fi echo ;; stop) echo -n "Shutting down : X Virtual Frame Buffer" killproc $PROG RETVAL=$? [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb /var/run/Xvfb.pid echo ;; restart|reload) $0 stop $0 start RETVAL=$? ;; status) status Xvfb RETVAL=$? ;; *) echo $"Usage: $0 (start|stop|restart|reload|status)" exit 1 esac exit $RETVAL 

Save the script as xvfbd and copy the script to /etc/init.d, then run the following command:

sudo chkconfig --add xvfbd 
1
kenorb

The simplest way is to add the following line into /etc/rc.local file (create one if it's not there):

Xvfb :0 -screen 0 1024x768x16 & 

to start X virtual framebuffer on boot.

-2
tryp

Вы можете использовать более простой способ, если вам просто нужно запустить или запустить что-то при загрузке компьютера.

В Redhat / CentOS добавьте строку скрипта в этот файл: /etc/rc.d/rc.local

Я не отрицал вас, но я думаю, что это работает только для системы V. Donato 8 лет назад 0
Я попробовал это сегодня на ванильной системе CentOS 7 (потому что я ленивый), и это сработало, запустив Xvfb. clusterdude 6 лет назад 0

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