dinsdag 25 oktober 2022

Check uptime linux en mysql

 Voor linux gebruik het commando

uptime


voor mysql:

gebruikt:

SELECT DATE_SUB(now(), INTERVAL variable_value SECOND) "LAST STARTUP" from performance_schema.global_status where variable_name='Uptime';


of in linux:

service mysql status

woensdag 17 augustus 2022

asp.net in linux

in asp.net 

add systemd support

var builder = WebApplication.CreateBuilder(args);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
    builder.Host.UseSystemd(); // for linux...
}


    <PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />

add forwarding for nginx

var app = builder.Build();

//for nginx
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

 

on ubuntu create a directory in:

/var/www/<appname>

build / publish asp.net project for linux

dotnet publish -c Release -r linux-x64 --no-self-contained

Check if .net runtime is installed if it does not work you can also use --self-contained in your build command

copy contents to directory

give permission to <appname> dir with command:

chmod 775 -R /var/www/<appname>

set execute rechten op exe file

chmod +x /var/www/<appname dir>/<appname> (without dll) in linux

Systemd

Create a service file in systemd

create an empty <appname>.service file (touch filename)

put in the following content (nano filename)

[Unit]

Description=app description

After=network.target


[Service]

WorkingDirectory=/var/www/uitgekookt-logistics-route-generation-api/current

ExecStart=/var/www/<appdir>/<linux generated file without extension / appname>

Restart=always

# Restart service after 10 seconds if the dotnet service crashes:

RestartSec=10

KillSignal=SIGINT

User=www-data

Environment=ASPNETCORE_ENVIRONMENT=Production

Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

Environment=AllowedHosts=*

Environment=ApplicationInsights__InstrumentationKey=

Environment=Connectionstrings__ABC=abc

Environment=ASPNETCORE_URLS=http://localhost:5040


Enable service:

sudo systemctl enable <appname>.service

Start

sudo systemctl start <appname>.service


NGINX

For nginx create an <appname> file in /etc/nginx/sites-available/ dir

with contents:

server {

    listen 50400; //external port

    listen [::]:50400; 

    location / {

        proxy_pass         http://127.0.0.1:5040; //portnumber of .net api

        proxy_http_version 1.1;

        proxy_set_header   Upgrade $http_upgrade;

        proxy_set_header   Connection keep-alive;

        proxy_set_header   Host $host;

        proxy_cache_bypass $http_upgrade;

        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header   X-Forwarded-Proto $scheme;

    }

}

create a systemlink from sites-available to sites-enabled:

ln -s /etc/nginx/sites-available/<appname> /etc/nginx/sites-enabled/<appname>

allow port 50400 in firewall (ufw enable)

reload nginx (nginx -s reload)

when there are issues with the application scan the log via:

sudo journalctl -fu <appname>.service


Meer info:

Host ASP.NET Core on Linux with Nginx | Microsoft Docs


vrijdag 24 juni 2022

install mysql on linux

 How To Install MySQL on Ubuntu 20.04 | DigitalOcean

check if mysql is running systemctl list-units --type=service --state=running or

systemctl --type=service

grant acces to user

open port in firewall for external communication


Run SQL file in MySQL database from terminal? (tutorialspoint.com)

woensdag 15 juni 2022

python - django - wagtail cms

install python 3.9

install pip for use in commandline:

download :get-pip.py

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
install pip:
python3 get-pip.py

see: https://www.geeksforgeeks.org/how-to-install-pip-in-macos

install wagtail; see https://wagtail.org/developers/


when modulenotfound exception use:

python -m pip install django
python -m pip install wagtail

dinsdag 14 juni 2022

static web app configuration

 place a staticwebapp.config.json file in the root of your application.

Configure Azure Static Web Apps | Microsoft Docs

fe:

{
  "navigationFallback": {
    "rewrite": "/index.html",
    "exclude": [
      "/assets/icons/*.{png,jpg,gif,webp}",
      "/assets/images/*.{png,jpg,gif,webp}",
      "/assets/*.{json}"
    ]
  },
  "mimeTypes": {
    ".json": "text/json",
    ".webp": "image/webp"
  },
  "routes": [
    {
      "route": "index.html",
      "headers": {
        "Cache-Control": "no-store"
      }
    }
  ]
}

zondag 1 mei 2022

create windows service with .net core

Build a windows service on windows server you need to compile the assemblies with win-x64 runtime

dotnet build -c Release --runtime win-x64 --no-self-contained

dotnet publish-c Release --runtime win-x64 --no-self-contained


use sc.exe util to install the windows service

sc.exe create "ServiceName" binpath="Dir\Service.exe"


info:

sc.exe create | Microsoft Docs