Configure and start service

This commit is contained in:
2022-09-08 20:54:55 -04:00
parent 93a65223fc
commit bccd3e8a4c
9 changed files with 105 additions and 0 deletions

View File

@@ -12,7 +12,9 @@
#### Private Classes
* `klipper::configure`: Handles configuration of klipper
* `klipper::install`: Perform baseline install of Klipper
* `klipper::service`: Manage the klipper service
## Classes
@@ -37,6 +39,7 @@ The following parameters are available in the `klipper` class:
* [`user`](#user)
* [`python_dir`](#python_dir)
* [`config_dir`](#config_dir)
* [`log_path`](#log_path)
##### <a name="src_path"></a>`src_path`
@@ -78,3 +81,11 @@ The path to place klipper config files
Default value: `"/home/${klipper::user}/klipper_config"`
##### <a name="log_path"></a>`log_path`
Data type: `Stdlib::Absolutepath`
Where to store the klipper logs
Default value: `"/home/${klipper::user}/klipper_logs"`

16
manifests/configure.pp Normal file
View File

@@ -0,0 +1,16 @@
# @summary Handles configuration of klipper
#
# @api private
#
class klipper::configure {
file { $klipper::config_dir:
ensure => directory,
owner => $klipper::user,
mode => '0755',
}
file { "${klipper::config_dir}/printer.cfg":
ensure => file,
owner => $klipper::user,
mode => '0644',
}
}

View File

@@ -10,6 +10,7 @@
# @param user The account to run klipper under
# @param python_dir The path to place the klipper python virtualenv
# @param config_dir The path to place klipper config files
# @param log_path Where to store the klipper logs
#
class klipper (
String $version = 'present',
@@ -17,6 +18,13 @@ class klipper (
Stdlib::Absolutepath $src_path = "/home/${klipper::user}/klipper",
Stdlib::Absolutepath $python_dir = "/home/${klipper::user}/klippy-env",
Stdlib::Absolutepath $config_dir = "/home/${klipper::user}/klipper_config",
Stdlib::Absolutepath $log_path = "/home/${klipper::user}/klipper_logs",
) {
contain klipper::install
contain klipper::configure
contain klipper::service
Class['klipper::install']
-> Class['klipper::configure']
-> Class['klipper::service']
}

View File

@@ -47,4 +47,10 @@ class klipper::install {
subscribe => Vcsrepo[$klipper::src_path],
user => $klipper::user,
}
file { $klipper::log_path:
ensure => directory,
owner => $klipper::user,
mode => '0755',
}
}

11
manifests/service.pp Normal file
View File

@@ -0,0 +1,11 @@
# @summary Manage the klipper service
#
# @api private
#
class klipper::service {
systemd::unit_file { 'klipper.service':
content => template('klipper/klipper.service.erb'),
enable => true,
active => true,
}
}

View File

@@ -13,6 +13,10 @@
{
"name": "puppetlabs-vcsrepo",
"version_requirement": ">= 5.0.0 < 6.0.0"
},
{
"name": "puppet-systemd",
"version_requirement": ">= 3.1.0 < 4.0.0"
}
],
"operatingsystem_support": [

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'spec_helper'
describe 'klipper::configure' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
it { is_expected.to compile }
end
end
end

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'spec_helper'
describe 'klipper::service' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
it { is_expected.to compile }
end
end
end

View File

@@ -0,0 +1,23 @@
# MANAGED BY PUPPET
# Systemd Klipper Service
[Unit]
Description=Systemd Klipper Service
Documentation=https://www.klipper3d.org/
After=network.target
Wants=udev.target
[Install]
WantedBy=multi-user.target
[Service]
Environment=KLIPPER_CONFIG=<%= scope['klipper::config_dir'] %>/printer.cfg
Environment=KLIPPER_LOG=<%= scope['klipper::log_path'] %>/klippy.log
Environment=KLIPPER_SOCKET=/tmp/klippy_uds
Environment=KLIPPER_PRINTER=/tmp/printer
Type=simple
User=<%= scope['klipper::user'] %>
RemainAfterExit=yes
ExecStart=<%= scope['klipper::python_dir'] %>/bin/python <%= scope['klipper::src_path'] %>/klippy/klippy.py ${KLIPPER_CONFIG} -I ${KLIPPER_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPER_SOCKET}
Restart=always
RestartSec=10