Initial commit
This commit is contained in:
85
manifests/app.pp
Normal file
85
manifests/app.pp
Normal file
@@ -0,0 +1,85 @@
|
||||
# modules/frankenphp/manifests/app.pp
|
||||
|
||||
define frankenphp::app (
|
||||
Stdlib::Absolutepath $root_dir,
|
||||
String $user,
|
||||
String $listen_port,
|
||||
String $group = $user,
|
||||
Stdlib::Absolutepath $docs_root = '/var/www',
|
||||
String $app_caddyfile_dir = '/etc/frankenphp/sites.d',
|
||||
String $supervisor_conf_dir = '/etc/supervisor/conf.d',
|
||||
Boolean $managed_root_dir = true,
|
||||
Enum['present', 'absent'] $ensure = 'present',
|
||||
) {
|
||||
|
||||
$app_name = $title
|
||||
$app_caddyfile = "${app_caddyfile_dir}/${app_name}.Caddyfile"
|
||||
$supervisor_conf = "${supervisor_conf_dir}/frankenphp-${app_name}.conf"
|
||||
|
||||
exec { "refresh-frankenphp-${app_name}":
|
||||
command => "supervisorctl restart frankenphp-${app_name}",
|
||||
path => ['/usr/bin', '/bin'],
|
||||
refreshonly => true,
|
||||
}
|
||||
|
||||
if $ensure == 'present' {
|
||||
# Users
|
||||
ensure_resource('group', $group, { ensure => 'present' })
|
||||
ensure_resource('user', $user, {
|
||||
ensure => 'present',
|
||||
gid => $group,
|
||||
shell => '/bin/false',
|
||||
home => "${docs_root}/${user}",
|
||||
system => true,
|
||||
require => Group[$group],
|
||||
})
|
||||
|
||||
# Directories
|
||||
ensure_resource('file', $app_caddyfile_dir, { ensure => 'directory' })
|
||||
if ! $managed_root_dir {
|
||||
ensure_resource('file', $root_dir, {
|
||||
ensure => 'directory',
|
||||
owner => $user,
|
||||
group => $group,
|
||||
mode => '0755',
|
||||
require => User[$user],
|
||||
})
|
||||
}
|
||||
|
||||
# Caddyfile
|
||||
$caddy_content = epp('frankenphp/app_caddyfile.epp', {
|
||||
listen_port => $listen_port,
|
||||
root_dir => $root_dir,
|
||||
})
|
||||
|
||||
file { $app_caddyfile:
|
||||
ensure => 'file',
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => $caddy_content,
|
||||
notify => Exec["refresh-frankenphp-${app_name}"],
|
||||
}
|
||||
|
||||
# Supervisor
|
||||
supervisord::program { "frankenphp-${app_name}":
|
||||
command => "/usr/bin/frankenphp run --config ${app_caddyfile}",
|
||||
priority => '100',
|
||||
user => $user,
|
||||
autorestart => true,
|
||||
autostart => true,
|
||||
startretries => 20,
|
||||
program_environment => {
|
||||
'PATH' => '/bin:/sbin:/usr/bin:/usr/sbin',
|
||||
},
|
||||
require => File[$app_caddyfile]
|
||||
}
|
||||
|
||||
} else {
|
||||
file { $app_caddyfile: ensure => 'absent' }
|
||||
file { $supervisor_conf:
|
||||
ensure => 'absent',
|
||||
notify => Service['supervisor'],
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user