97 lines
2.7 KiB
Puppet
97 lines
2.7 KiB
Puppet
# modules/frankenphp/manifests/app.pp
|
|
|
|
define frankenphp::app (
|
|
String $user,
|
|
String $listen_port,
|
|
String $group = $user,
|
|
String $root_dir = 'www',
|
|
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"
|
|
$full_root_dir = "${docs_root}/${user}/${root_dir}"
|
|
|
|
exec { "refresh-frankenphp-${app_name}":
|
|
command => "supervisorctl restart frankenphp-${app_name}",
|
|
path => ['/usr/bin', '/bin'],
|
|
refreshonly => true,
|
|
require => Supervisord::Program["frankenphp-${app_name}"],
|
|
}
|
|
|
|
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' })
|
|
|
|
ensure_resource('file', "${docs_root}/${user}", {
|
|
ensure => 'directory',
|
|
owner => $user,
|
|
group => $group,
|
|
mode => '0755',
|
|
require => User[$user],
|
|
})
|
|
|
|
if $managed_root_dir {
|
|
ensure_resource('file', $full_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 => $full_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'],
|
|
}
|
|
}
|
|
}
|