#=============================================================================
# Doloforge::Service::Iis : configure the IIS reverse-proxy back-end for any client/project
#
# Generate config files from templates, add a config file to the whole...
#
# Full help :
#   perldoc Doloforge::Service::Iis
#=============================================================================


package Doloforge::Service::Iis;

use strict;

# This base class implements the constructor and help methods in a generic way.
# This class is specifically a derivative of another service class, since they
# are both based on Apache and need the same kind of configuration.
use base qw(Doloforge::Service::Apache);


#=============================================================================
=encoding utf8

=head1 NAME

Doloforge::Service::Iis : configure the IIS reverse-proxy back-end for any client/project

=head1 SYNOPSIS

    # Update the full configuration, running each client/project/service update
    doloforge config --update

=head1 DESCRIPTION

Todo

=cut


#=============================================================================
# Nearly everything is inherited from Doloforge::Service::Apache !!!
#
# Service-related directories are created by the PerlRequire'd script, run
# by Apache at startup. This script is located in /etc/doloforge/ directory.


#=============================================================================
# Method update
#
# Update the service configuration on the host, depending on
# client/project/service config files...
# This method receives :
#   option: context options passed on the command-line (quite useless there)
#   client_conf: client configuration file contents (client.$name.yaml)
#   project_conf: project configuration file contents (project.$name.client.$name.yaml)

sub update {
    my $self = shift;

    my ($option, $client_conf, $project_conf) = @_;

    # Call the same method from the super-class first, which will do generic Apache things.
    $self->SUPER::update($option, $client_conf, $project_conf);

    if ($self->has_role('nfs_role')) {
        # Merge the config hashes with the proper template files, and save the result...
        # Similar to Apache httpd.conf VirtualHost, but with a different name, to make Windows happy.
        $self->merge_template($option, $client_conf, $project_conf, # Configuration hashes
            # Service-specific template, from [skel]/template/[stage]/apache_*
            "$self->{global}->{dir}->{skel}/template/$self->{name}_mkw3site.bat.tmpl",
            # Alternate project-service-specific template, to be used if it exists
            "$self->{global}->{dir}->{shared}/$client_conf->{name}/$project_conf->{name}/conf/$self->{name}_mkw3site.bat.tmpl",
            # Filled-in file, in [client]/[project]/_conf/ (it's name must be unique among all services)
            "$self->{global}->{dir}->{shared}/$client_conf->{name}/$project_conf->{name}/_conf/$self->{name}_mkw3site.bat",
            # Link to the filled-in file, which must be maintained once the project is active
            "$self->{global}->{dir}->{shared}/.doloforge/$self->{name}/conf.d/$client_conf->{name}_$project_conf->{name}_mkw3site.bat",
        );

        # Link the project's DocumentRoot in IIS's central shared storage, just like:
        #   ln -s /srv/doloforge/shared/devl/internal/sandbox/iis/htdocs /srv/doloforge/shared/devl/.doloforge/iis/wwwroots/internal_sandbox
        # Create link on NFS servers only, since everything is in shared storage...
        # FIXME : add a link to the shared storage for IIS logs, or let the log analyzer procedure get the logs from various web hosts ?
        $self->link_file(
            "$self->{global}->{dir}->{shared}/$client_conf->{name}/$project_conf->{name}/$self->{name}/htdocs",
            "$self->{global}->{dir}->{shared}/.doloforge/$self->{name}/wwwroots/$client_conf->{name}_$project_conf->{name}",
        );
    }
}



1;
__END__

=head1 AUTHOR

Nicolas Huillard <F<nicolas@huillard.net>>, Dolomède

=head1 SEE ALSO

doloforge(1)

=cut
