Applicable when
- There is a need to run a component implemented as a Windows Service using .NET in the cloud environment with minimal modifications
Non-applicable when
- Service requires substantial modification for other reasons and can be rewritten using a cloud-native technology stack
Implementation
Compatibility Updates
Directory Structure Handling
Linux uses "/" as the folder separator whereas Windows uses "\". All parts of the code that handle folder and file paths should be updated to account for this difference:
E.g.
If Not S.EndsWith("\") Then F = S & "\"
should be updated with
If Not S.EndsWith("/") Then F = S & "/"
See also Path Separators.
Registry Settings
If the service reads settings from the Windows registry these settings should be passed to the container as environment variables and further passed to the service via values.xml file in /etc/mono/registry/<path to settings in the registry>/values.xml
<values>
<value name="LogFolder" type="string">${LOG_FOLDER}</value>
<value name="Interval" type="string">${INTERVAL}</value>
<value name="LCRRefreshInterval" type="string">${LCR_REFRESH_INTERVAL}</value>
<value name="DaysToKeepLog" type="string">${DAYS_TO_KEEP_LOG}</value>
<value name="UserID" type="string">${USER_ID}</value>
<value name="Password" type="string">${PASSWORD}</value>
<value name="DBHost" type="string">${DB_HOST}</value>
<value name="DBPort" type="string">${DB_PORT}</value>
<value name="DBName" type="string">${DB_NAME}</value>
<value name="MaxItemsInWip" type="string">${MAX_ITEMS_IN_WIP}</value>
<value name="CostPriceRatioVerified" type="string">${COST_PRICE_RATIO_VERIFIED}</value>
<value name="CostPriceRatioDemo_Eval" type="string">${COST_PRICE_RATIO_DEMO_EVAL}</value>
<value name="CostPriceRatioPaying" type="string">${COST_PRICE_RATIO_PAYING}</value>
<value name="MessagesDatabase" type="string">${MESSAGES_DATABASE}</value>
<value name="SwitchNodeName" type="string">${SWITCH_NODE_NAME}</value>
</values>
If the settings used to be encrypted the code needs to be updated to be used unencrypted:
Public UserID As New ConfigClass.AppParam("root", "The name of the Database user", True)
Public Password As New ConfigClass.AppParam("123456", "The Password of the Database user", True)
' Mono Framework doesn't support DPAPI.
Public UserID As New ConfigClass.AppParam("root", "The name of the Database user", False)
Public Password As New ConfigClass.AppParam("123456", "The Password of the Database user", False)
Building Procedure
entrypoint.sh Example
#!/bin/bash
if [[ -z "$LOG_FOLDER" ]]; then
export LOG_FOLDER="/usr/local/interfax/logs/"
fi
if [[ -z "$DAYS_TO_KEEP_LOG" ]]; then
export DAYS_TO_KEEP_LOG="7"
fi
if [[ -z "$INTERVAL" ]]; then
export INTERVAL="1"
fi
if [[ -z "$LCR_REFRESH_INTERVAL" ]]; then
export LCR_REFRESH_INTERVAL="2"
fi
if [[ -z "$USER_ID" ]]; then
export USER_ID=""
fi
if [[ -z "$PASSWORD" ]]; then
export PASSWORD=""
fi
if [[ -z "$DB_HOST" ]]; then
export DB_HOST=""
fi
if [[ -z "$DB_PORT" ]]; then
export DB_PORT="3306"
fi
if [[ -z "$DB_NAME" ]]; then
export DB_NAME="interfax75"
fi
if [[ -z "$MAX_ITEMS_IN_WIP" ]]; then
export MAX_ITEMS_IN_WIP="50000"
fi
if [[ -z "$COST_PRICE_RATIO_VERIFIED" ]]; then
export COST_PRICE_RATIO_VERIFIED="0.9"
fi
if [[ -z "$COST_PRICE_RATIO_DEMO_EVAL" ]]; then
export COST_PRICE_RATIO_DEMO_EVAL="0.3"
fi
if [[ -z "$COST_PRICE_RATIO_PAYING" ]]; then
export COST_PRICE_RATIO_PAYING="0.5"
fi
if [[ -z "$MESSAGES_DATABASE" ]]; then
export MESSAGES_DATABASE="/usr/local/interfax/message_database/"
fi
if [[ -z "$SWITCH_NODE_NAME" ]]; then
export SWITCH_NODE_NAME="US"
fi
mkdir -p /etc/mono/registry/LocalMachine/software/interfax/findroute/parameters/
envsubst < values.xml.tmpl > \
/etc/mono/registry/LocalMachine/software/interfax/findroute/parameters/values.xml
mono-service /usr/local/interfax/bin/FindRouteService.exe && \
sleep 10 && tailf $LOG_FOLDER*.log
Comments
0 comments
Please sign in to leave a comment.