Running VNC as a System Service
By setting up the VNC server to run as a systemd service, you can start, stop, and restart it as needed, like any other service. You can also use systemd’s management commands to ensure that VNC starts when your server boots up.
First, create a new unit file called /etc/systemd/system/vncserver@.service
:
The @
symbol at the end of the name will let us pass in an argument you can use in the service configuration. You’ll use this to specify the VNC display port you want to use when you manage the service.
Add the following lines to the file. Be sure to change the value of User
, Group
, WorkingDirectory
, and the username in the value of PIDFILE
to match your username:
The ExecStartPre
command stops VNC if it’s already running. The ExecStart
command starts VNC and sets the color depth to 24-bit color with a resolution of 1280x800. You can modify these start-up options as well to meet your needs. Also, note that the ExecStart
command again includes the -localhost
option.
Save and close the file. Then, make the system aware of the new unit file:
The 1
following the @
sign signifies which display number the service should appear over, in this case the default :1
as was discussed in the Installation and Configuration phase
Stop the current instance of the VNC server if it’s still running, then start it as you would start any other systemd service:
You can verify that it started with this command:
If it started correctly, the output should look like this:
Your VNC server is now ready to use whenever your server boots up, and you can manage it with systemctl
commands like any other systemd service.
Last updated