diff --git a/infra/modules/azure_app_service/README.md b/infra/modules/azure_app_service/README.md
index fe855858..14a76a94 100644
--- a/infra/modules/azure_app_service/README.md
+++ b/infra/modules/azure_app_service/README.md
@@ -39,6 +39,7 @@
| [health\_check\_path](#input\_health\_check\_path) | Endpoint where health probe is exposed | `string` | n/a | yes |
| [java\_version](#input\_java\_version) | Java version to use | `string` | `17` | no |
| [node\_version](#input\_node\_version) | Node version to use | `number` | `20` | no |
+| [pm2\_startup\_file\_name](#input\_pm2\_startup\_file\_name) | (Optional) Use this variable to enable PM2. The specified file is used as PM2 process entry point | `string` | `null` | no |
| [private\_dns\_zone\_resource\_group\_name](#input\_private\_dns\_zone\_resource\_group\_name) | (Optional) The name of the resource group holding private DNS zone to use for private endpoints. Default is Virtual Network resource group | `string` | `null` | no |
| [resource\_group\_name](#input\_resource\_group\_name) | Resource group to deploy resources to | `string` | n/a | yes |
| [slot\_app\_settings](#input\_slot\_app\_settings) | Staging slot application settings | `map(string)` | `{}` | no |
diff --git a/infra/modules/azure_app_service/app_service.tf b/infra/modules/azure_app_service/app_service.tf
index 138c23c7..a4c53334 100644
--- a/infra/modules/azure_app_service/app_service.tf
+++ b/infra/modules/azure_app_service/app_service.tf
@@ -21,6 +21,8 @@ resource "azurerm_linux_web_app" "this" {
health_check_eviction_time_in_min = 2
ip_restriction_default_action = "Deny"
+ app_command_line = local.app_service.command_line
+
application_stack {
node_version = var.stack == "node" ? "${var.node_version}-lts" : null
java_version = var.stack == "java" ? var.java_version : null
diff --git a/infra/modules/azure_app_service/app_service_slot.tf b/infra/modules/azure_app_service/app_service_slot.tf
index 63ba4647..78d7365a 100644
--- a/infra/modules/azure_app_service/app_service_slot.tf
+++ b/infra/modules/azure_app_service/app_service_slot.tf
@@ -21,6 +21,8 @@ resource "azurerm_linux_web_app_slot" "this" {
health_check_eviction_time_in_min = 2
ip_restriction_default_action = "Deny"
+ app_command_line = local.app_service.command_line
+
application_stack {
node_version = var.stack == "node" ? "${var.node_version}-lts" : null
java_version = var.stack == "java" ? var.java_version : null
diff --git a/infra/modules/azure_app_service/locals.tf b/infra/modules/azure_app_service/locals.tf
index a2f60e98..886f310b 100644
--- a/infra/modules/azure_app_service/locals.tf
+++ b/infra/modules/azure_app_service/locals.tf
@@ -16,6 +16,7 @@ locals {
sku_name = local.sku_name_mapping[local.tier]
zone_balancing_enabled = local.tier != "s"
is_slot_enabled = local.tier == "s" ? 0 : 1
+ command_line = var.pm2_startup_file_name == null ? null : "pm2 start ${var.pm2_startup_file_name} -i max --no-daemon"
}
app_service_slot = {
diff --git a/infra/modules/azure_app_service/variables.tf b/infra/modules/azure_app_service/variables.tf
index 55cf8a89..a53282f2 100644
--- a/infra/modules/azure_app_service/variables.tf
+++ b/infra/modules/azure_app_service/variables.tf
@@ -129,3 +129,9 @@ variable "subnet_service_endpoints" {
description = "(Optional) Enable service endpoints for the underlying subnet. This variable should be set only if function dependencies do not use private endpoints"
default = null
}
+
+variable "pm2_startup_file_name" {
+ type = string
+ default = null
+ description = "(Optional) Use this variable to enable PM2. The specified file is used as PM2 process entry point"
+}
diff --git a/infra/modules/azure_app_service_exposed/README.md b/infra/modules/azure_app_service_exposed/README.md
index d348088c..0036894f 100644
--- a/infra/modules/azure_app_service_exposed/README.md
+++ b/infra/modules/azure_app_service_exposed/README.md
@@ -36,6 +36,7 @@ This module is used to create an Azure App Service, allowing it to be configured
| [health\_check\_path](#input\_health\_check\_path) | Endpoint where health probe is exposed | `string` | n/a | yes |
| [java\_version](#input\_java\_version) | Java version to use | `string` | `17` | no |
| [node\_version](#input\_node\_version) | Node version to use | `number` | `20` | no |
+| [pm2\_startup\_file\_name](#input\_pm2\_startup\_file\_name) | (Optional) Use this variable to enable PM2. The specified file is used as PM2 process entry point | `string` | `null` | no |
| [resource\_group\_name](#input\_resource\_group\_name) | Resource group to deploy resources to | `string` | n/a | yes |
| [slot\_app\_settings](#input\_slot\_app\_settings) | Staging slot application settings | `map(string)` | `{}` | no |
| [stack](#input\_stack) | n/a | `string` | `"node"` | no |
diff --git a/infra/modules/azure_app_service_exposed/app_service.tf b/infra/modules/azure_app_service_exposed/app_service.tf
index 00c85706..91d76e05 100644
--- a/infra/modules/azure_app_service_exposed/app_service.tf
+++ b/infra/modules/azure_app_service_exposed/app_service.tf
@@ -19,6 +19,8 @@ resource "azurerm_linux_web_app" "this" {
health_check_path = var.health_check_path
health_check_eviction_time_in_min = 2
+ app_command_line = local.app_service.command_line
+
application_stack {
node_version = var.stack == "node" ? "${var.node_version}-lts" : null
java_version = var.stack == "java" ? var.java_version : null
diff --git a/infra/modules/azure_app_service_exposed/app_service_slot.tf b/infra/modules/azure_app_service_exposed/app_service_slot.tf
index 30707f95..6bb3fa3c 100644
--- a/infra/modules/azure_app_service_exposed/app_service_slot.tf
+++ b/infra/modules/azure_app_service_exposed/app_service_slot.tf
@@ -19,6 +19,8 @@ resource "azurerm_linux_web_app_slot" "this" {
health_check_path = var.health_check_path
health_check_eviction_time_in_min = 2
+ app_command_line = local.app_service.command_line
+
application_stack {
node_version = var.stack == "node" ? "${var.node_version}-lts" : null
java_version = var.stack == "java" ? var.java_version : null
diff --git a/infra/modules/azure_app_service_exposed/locals.tf b/infra/modules/azure_app_service_exposed/locals.tf
index 31027019..013bf37e 100644
--- a/infra/modules/azure_app_service_exposed/locals.tf
+++ b/infra/modules/azure_app_service_exposed/locals.tf
@@ -9,6 +9,7 @@ locals {
zone_balancing_enabled = local.tier != "s" && local.tier != "xs"
is_slot_enabled = local.tier == "s" || local.tier == "xs" ? 0 : 1
always_on = local.tier == "xs" ? false : true
+ command_line = var.pm2_startup_file_name == null ? null : "pm2 start ${var.pm2_startup_file_name} -i max --no-daemon"
}
application_insights = {
diff --git a/infra/modules/azure_app_service_exposed/variables.tf b/infra/modules/azure_app_service_exposed/variables.tf
index 71be210d..a798df33 100644
--- a/infra/modules/azure_app_service_exposed/variables.tf
+++ b/infra/modules/azure_app_service_exposed/variables.tf
@@ -98,3 +98,9 @@ variable "sticky_app_setting_names" {
description = "(Optional) A list of application setting names that are not swapped between slots"
default = []
}
+
+variable "pm2_startup_file_name" {
+ type = string
+ default = null
+ description = "(Optional) Use this variable to enable PM2. The specified file is used as PM2 process entry point"
+}