Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,45 @@
default => Class['vnc::service'],
}

define vnc::create_vncserver_config (
$servers
) {
$index = inline_template('<%= servers.index(name) %>')
$vnc_user = $name[user]

file { "/etc/systemd/system/vncserver@:${index}.service":
ensure => present,
owner => root,
group => root,
mode => '0440',
content => template($vnc::vncservers_template_systemctl),
notify => $notify_class,
}
}

case $::osfamily {
'RedHat': {
$vncservers_template = $vnc::vncservers_template
file { '/etc/sysconfig/vncservers':
ensure => present,
owner => root,
group => root,
mode => '0440',
content => template($vncservers_template),
notify => $notify_class,
case $::operatingsystemrelease {
/^[6,5]\./: {
$vncservers_template = $vnc::vncservers_template
file { '/etc/sysconfig/vncservers':
ensure => present,
owner => root,
group => root,
mode => '0440',
content => template($vncservers_template),
notify => $notify_class,
}
}
/^7\./: {
vnc::create_vncserver_config {
$vnc::servers:
servers => $vnc::servers
}
}
default: { fail('Unsupported OS version') }
}


file { '/etc/skel/.vnc':
ensure => directory,
Expand All @@ -52,6 +80,6 @@
}
}

default: { }
default: { fail('Unsupported OS') }
}
}
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
$service_enable = true,
$service_ensure = running,
$xstartup_template = 'vnc/xstartup.erb',
$vncservers_template = 'vnc/vncservers.erb'
$vncservers_template = 'vnc/vncservers.erb',
$vncservers_template_systemctl = 'vnc/vncservers_systemctl.erb'
) {
include vnc::install, vnc::config, vnc::service

Expand Down
3 changes: 2 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
case $::osfamily {
'RedHat': {
case $::operatingsystemrelease {
/^6\./: { $package = 'tigervnc-server' }
/^[7,6]\./: { $package = 'tigervnc-server' }
/^5\./: { $package = 'vnc-server' }
default: { fail('Unsupported OS version') }
}
Expand All @@ -32,5 +32,6 @@
}
}

package { 'xterm': ensure => installed }
package { $package: ensure => installed }
}
54 changes: 47 additions & 7 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,53 @@
#
# Manages the VNC service
#
class vnc::service {
include vnc
class vnc::service (
$enable = true,
$ensure = running,
){
$notify_class = $vnc::refresh ? {
false => undef,
default => Class['vnc::service'],
}

define vnc::create_vncserver_services (
$servers,
$ensure,
$enable,
) {
$index = inline_template('<%= servers.index(name) %>')
service { "vncserver@:${index}.service":
ensure => $ensure,
enable => $enable,
hasstatus => true,
status => "sudo systemctl status vncserver@:${index}.service; /usr/bin/test $? -eq 0",
}
}

service { 'vncserver':
ensure => $vnc::service_ensure_real,
enable => $vnc::service_enable_real,
hasstatus => true,
status => '/sbin/service vncserver status; /usr/bin/test $? -eq 0',
case $::osfamily {
'RedHat': {
case $::operatingsystemrelease {
/^[6,5]\./: {
service { 'vncserver':
ensure => $ensure,
enable => $enable,
hasstatus => true,
status => '/sbin/service vncserver status; /usr/bin/test $? -eq 0',
}
}
/^7\./: {
vnc::create_vncserver_services {
$vnc::servers:
servers => $vnc::servers,
ensure => $ensure,
enable => $enable,
}
}
default: { fail('Unsupported OS version') }
}
}
default: {
fail('Unsupported OS')
}
}
}
45 changes: 45 additions & 0 deletions templates/vncservers_systemctl.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
# ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.


[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l <%= @vnc_user -%> -c "/usr/bin/vncserver %i -geometry 1280x1024""
PIDFile=/home/<%= @vnc_user -%>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target