[ubuntu] Add Apache and Nginx (#2516)

* [ubuntu] Add apache and nginx (#2501)

* Use dpkg-query to get nginx version

* Fix flaky apache cli test
This commit is contained in:
Shivam Mathur
2021-01-29 07:52:46 -08:00
committed by GitHub
parent b386372a86
commit 212431cc79
8 changed files with 101 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" -DisableNameCheckin
Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Java.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Rust.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Tools.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "SoftwareReport.WebServers.psm1") -DisableNameChecking
# Restore file owner in user profile
Restore-UserOwner
@@ -244,6 +245,8 @@ $markdown += New-MDHeader "PowerShell Modules" -Level 4
$markdown += Get-PowerShellModules | New-MDTable
$markdown += New-MDNewLine
$markdown += Build-WebServersSection
$markdown += New-MDHeader "Android" -Level 3
$markdown += Build-AndroidTable | New-MDTable
$markdown += New-MDNewLine

View File

@@ -0,0 +1,41 @@
function Get-ApacheVersion {
$name = "apache2"
$port = 80
$version = bash -c "apache2 -v | grep -Po 'Apache/(\d+.){2}\d+'" | Take-OutputPart -Part 1 -Delimiter "/"
$serviceStatus = systemctl status apache2 | grep "Active:" | Take-OutputPart -Part 1
$configFile = "/etc/apache2/apache2.conf"
return [PsCustomObject]@{
"Name" = $name
"Version" = $version
"ConfigFile" = $configFile
"ServiceStatus" = $serviceStatus
"ListenPort" = $port
}
}
function Get-NginxVersion {
$name = "nginx"
$port = 80
$version = (dpkg-query --showformat='${Version}' --show nginx).Split('-')[0]
$serviceStatus = systemctl status nginx | grep "Active:" | Take-OutputPart -Part 1
$configFile = "/etc/nginx/nginx.conf"
return [PsCustomObject]@{
"Name" = $name
"Version" = $version
"ConfigFile" = $configFile
"ServiceStatus" = $serviceStatus
"ListenPort" = $port
}
}
function Build-WebServersSection {
$output = ""
$output += New-MDHeader "Web Servers" -Level 3
$output += @(
(Get-ApacheVersion),
(Get-NginxVersion)
) | Sort-Object Name | New-MDTable
$output += New-MDNewLine
return $output
}

View File

@@ -0,0 +1,14 @@
#!/bin/bash -e
################################################################################
## File: apache.sh
## Desc: Installs Apache HTTP Server
################################################################################
# Install Apache
apt-get install apache2 -y
# Disable apache2.service
systemctl is-active --quiet apache2.service && systemctl stop apache2.service
systemctl disable apache2.service
invoke_tests "WebServers" "Apache"

View File

@@ -0,0 +1,14 @@
#!/bin/bash -e
################################################################################
## File: nginx.sh
## Desc: Installs Nginx
################################################################################
# Install Nginx
apt-get install nginx -y
# Disable nginx.service
systemctl is-active --quiet nginx.service && systemctl stop nginx.service
systemctl disable nginx.service
invoke_tests "WebServers" "Nginx"

View File

@@ -0,0 +1,23 @@
Describe "Apache" {
It "Apache CLI" {
"apache2 -v" | Should -ReturnZeroExitCode
}
It "Apache Service" {
"sudo systemctl start apache2" | Should -ReturnZeroExitCode
"apachectl configtest" | Should -ReturnZeroExitCode
"sudo systemctl stop apache2" | Should -ReturnZeroExitCode
}
}
Describe "Nginx" {
It "Nginx CLI" {
"nginx -v" | Should -ReturnZeroExitCode
}
It "Nginx Service" {
"sudo systemctl start nginx" | Should -ReturnZeroExitCode
"sudo nginx -t" | Should -ReturnZeroExitCode
"sudo systemctl stop nginx" | Should -ReturnZeroExitCode
}
}

View File

@@ -191,6 +191,7 @@
"{{template_dir}}/scripts/installers/azure-devops-cli.sh",
"{{template_dir}}/scripts/installers/basic.sh",
"{{template_dir}}/scripts/installers/aliyun-cli.sh",
"{{template_dir}}/scripts/installers/apache.sh",
"{{template_dir}}/scripts/installers/aws.sh",
"{{template_dir}}/scripts/installers/nvm.sh",
"{{template_dir}}/scripts/installers/clang.sh",
@@ -238,6 +239,7 @@
"{{template_dir}}/scripts/installers/dpkg-config.sh",
"{{template_dir}}/scripts/installers/mongodb.sh",
"{{template_dir}}/scripts/installers/netlify.sh",
"{{template_dir}}/scripts/installers/nginx.sh",
"{{template_dir}}/scripts/installers/android.sh",
"{{template_dir}}/scripts/installers/pypy.sh",
"{{template_dir}}/scripts/installers/python.sh"

View File

@@ -194,6 +194,7 @@
"{{template_dir}}/scripts/installers/azure-devops-cli.sh",
"{{template_dir}}/scripts/installers/basic.sh",
"{{template_dir}}/scripts/installers/aliyun-cli.sh",
"{{template_dir}}/scripts/installers/apache.sh",
"{{template_dir}}/scripts/installers/aws.sh",
"{{template_dir}}/scripts/installers/clang.sh",
"{{template_dir}}/scripts/installers/swift.sh",
@@ -221,6 +222,7 @@
"{{template_dir}}/scripts/installers/mono.sh",
"{{template_dir}}/scripts/installers/mysql.sh",
"{{template_dir}}/scripts/installers/mssql-cmd-tools.sh",
"{{template_dir}}/scripts/installers/nginx.sh",
"{{template_dir}}/scripts/installers/nvm.sh",
"{{template_dir}}/scripts/installers/nodejs.sh",
"{{template_dir}}/scripts/installers/bazel.sh",

View File

@@ -194,6 +194,7 @@
"{{template_dir}}/scripts/installers/azure-devops-cli.sh",
"{{template_dir}}/scripts/installers/basic.sh",
"{{template_dir}}/scripts/installers/aliyun-cli.sh",
"{{template_dir}}/scripts/installers/apache.sh",
"{{template_dir}}/scripts/installers/aws.sh",
"{{template_dir}}/scripts/installers/clang.sh",
"{{template_dir}}/scripts/installers/swift.sh",
@@ -221,6 +222,7 @@
"{{template_dir}}/scripts/installers/mono.sh",
"{{template_dir}}/scripts/installers/mysql.sh",
"{{template_dir}}/scripts/installers/mssql-cmd-tools.sh",
"{{template_dir}}/scripts/installers/nginx.sh",
"{{template_dir}}/scripts/installers/nvm.sh",
"{{template_dir}}/scripts/installers/nodejs.sh",
"{{template_dir}}/scripts/installers/bazel.sh",