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
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:
Description=virtual frame buffer X server for display %I
ExecStart=/usr/bin/Xvfb %I -screen 0 1280x1024x24
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
- 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 .