If you want to, you can instead make a systemd
.service file that does the same thing. A basic systemd
.service file for the above command might look like the following:
Description=Start VNC server
ExecStart=/usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -display :0 -rfbauth /etc/x11vnc.pass -rfbport 5900 -noxrecord -noxfixes -noxdamage -forever
Things to note:
- Because this service relies on lightdm starting up, I've added a
Requires=lightdm.service. This means that if this service is requested to start, then
lightdm.service will also be asked to start, but if
lightdm.service fails to start, then this service won't be asked to start. Additionally,
After=lightdm.service is needed so that this service will start after `lightdm.service has finished starting.
- The command being run doesn't have
-bg specified. In systemd, it's preferred that services stay in the foreground, so that systemd knows that they are running. Note that it is possible to specify a PID file for a service that goes into the background.
WantedBy=graphical.target specifies that, as part of starting up your GUI, this should also get started up.
To install this file so that the service is run as root, add this file into
/etc/systemd/system. Then, run
sudo systemctl enable <filename> (where
<filename> is the name of the service file in
/etc/systemd/system). A symlink should be created in
/etc/systemd/system/graphical.target.wants/. After rebooting, when you run
systemctl status <filename>, you should see that the service is recognized and not yet started.
/etc/systemd/system/ is meant for system-wide services that the system administrator (you) add.
/lib/systemd/system/ is meant for system-wide services installed by packages. You do not need to make a symlink to
/lib/systemd/system/ for the service to load. The below table (taken from the
systemd.unit manpage) describes what each location is for with regards to system services (there are separate paths for user services):
│Path │ Description │
│/etc/systemd/system │ Local configuration │
│/run/systemd/system │ Runtime units │
│/lib/systemd/system │ Units of installed packages │