I have a .NET 6.0 minimal api that i have configured in my program.cs to run as a systemd service as seen below
if (Debugger.IsAttached == false)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
builder.Host.UseWindowsService();
builder.WebHost.ConfigureKestrel(serverOptions =>
{
int port = 1000;
int.TryParse(config.GetValue<string>("MicroServicePort"), out port);
serverOptions.ListenAnyIP(port, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
listenOptions.UseHttps(config.GetValue<string>("WindowsCertificatePath"));
});
});
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
builder.Host.UseSystemd();
builder.WebHost.ConfigureKestrel(serverOptions =>
{
int port = 1000;
int.TryParse(config.GetValue<string>("MicroServicePort"), out port);
serverOptions.ListenAnyIP(port, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
listenOptions.UseHttps(config.GetValue<string>("LinuxCertificatePath"), config.GetValue<string>("CertificatePassword"));
});
});
}
}
I have published this service using the following Visual Studio profile
I did a self contained deployment thus I haven't installed the .NET runtime on the target linux server. As for the linux server, the uname -m command prints
x86_64 and the uname -a command prints:
Linux LoadTesting 4.18.0-305.el8.x86_64 #1 SMP Thu Apr 29 08:54:30 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux
I then moved the published files to the linux (RedHat) server using WinSCP.
Below is the .service configuration file that i have put in /etc/systemd/system
[Unit]
Description=WebAPI
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=on-failure
RestartSec=60
User=johndoe
ExecStart=/usr/local/bin/Microservices/LinuxServices/WebAPI/Publish/WebAPI.dll
[Install]
WantedBy=multi-user.target
And finally the error that i am noting when i check the service logs by journalctl | grep WebAPI is:
Feb 03 02:39:42 LoadTesting systemd[1]: Stopped WebAPI.
Feb 03 02:39:42 LoadTesting systemd[1]: Started WebAPI.
Feb 03 02:39:42 LoadTesting systemd[14975]: WebAPI.service: Failed to execute command: Exec format error
Feb 03 02:39:42 LoadTesting systemd[14975]: WebAPI.service: Failed at step EXEC spawning /usr/local/bin/Microservices/LinuxServices/WebAPI/Publish/WebAPI.dll: Exec format error
Feb 03 02:39:42 LoadTesting systemd[1]: WebAPI.service: Main process exited, code=exited, status=203/EXEC
Feb 03 02:39:42 LoadTesting systemd[1]: WebAPI.service: Failed with result 'exit-code'.
Feb 03 02:40:42 LoadTesting systemd[1]: WebAPI.service: Service RestartSec=1min expired, scheduling restart.
Feb 03 02:40:42 LoadTesting systemd[1]: WebAPI.service: Scheduled restart job, restart counter is at 47.
Feb 03 02:40:42 LoadTesting systemd[1]: Stopped WebAPI.
I am very new to deploying services/APIs to linux so if there is a obvious config that i ought to already have done, feel free to bring it up.
Related
swagger is accessible when I run it in the terminal.
enter image description here
enter image description here
swagger 404 when i create the service and start it.
[Unit]
Description=generatesql
After=network-online.target
[Service]
WorkingDirectory=/home/www/tool/generatesql/
ExecStart=/usr/bin/dotnet /home/www/tool/generatesql/DBChange.dll
KillMode=process
Restart=on-failure
RestartSec=10
[Install]
WantedBy=default.target
root#server:/home/www/tool/generatesql# systemctl start generatesql
root#server:/home/www/tool/generatesql# systemctl status generatesql
● generatesql.service - generatesql
Loaded: loaded (/etc/systemd/system/generatesql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-09-28 14:14:34 CST; 6s ago
Main PID: 437150 (dotnet)
Tasks: 26 (limit: 18829)
Memory: 21.7M
CGroup: /system.slice/generatesql.service
└─437150 /usr/bin/dotnet /home/www/tool/generatesql/DBChange.dll
9月 28 14:14:34 server systemd[1]: Started generatesql.
9月 28 14:14:35 server dotnet[437150]: info: Microsoft.Hosting.Lifetime[14]
9月 28 14:14:35 server dotnet[437150]: Now listening on: http://[::]:10001
9月 28 14:14:35 server dotnet[437150]: info: Microsoft.Hosting.Lifetime[0]
9月 28 14:14:35 server dotnet[437150]: Application started. Press Ctrl+C to shut down.
9月 28 14:14:35 server dotnet[437150]: info: Microsoft.Hosting.Lifetime[0]
9月 28 14:14:35 server dotnet[437150]: Hosting environment: Production
9月 28 14:14:35 server dotnet[437150]: info: Microsoft.Hosting.Lifetime[0]
9月 28 14:14:35 server dotnet[437150]: Content root path: /home/www/tool/generatesql/
enter image description here
I don't have anywhere to look at the logs, how can I locate this problem.
Im trying to host asp.net core app on linux ubuntu, and after configuring i get this error in service file:
Process: 4151 ExecStart=/usr/bin/dotnet /var/www/serije/Serije.dll (code=exited, status=150)
Main PID: 4151 (code=exited, status=150)
Jun 28 08:02:33 serv systemd[1]: app.service: Main process exited, code=exited, status=150/n/a
Jun 28 08:02:33 serv systemd[1]: app.service: Unit entered failed state.
Jun 28 08:02:33 serv systemd[1]: app.service: Failed with result 'exit-code'.
my service file looks like this:
[Unit]
Description=Example .NET Web API App running on CentOS 7
[Service]
WorkingDirectory=/var/www/serije
ExecStart=/usr/bin/dotnet /var/www/serije/Serije.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
Try to run app directly:
dotnet Serije.dll
(with correct paths)
Probably you'll get an error:
No framework found
We have a series of .NET Core console apps that are installed in a particular directory:
/users/apps/app1/MyApp1
/users/apps/app2/MyApp2
etc...
The apps run fine. However, we have a problem where the .NET runtime seems to place some files in a ".net" folder in the current user's home directory.
unclejoe#myhost::/home/unclejoe> ls -la
total 40
drwx------. 8 unclejoe mygroup 139 Jan 24 14:42 .
drwxr-xr-x. 90 root root 4096 Jan 21 15:29 ..
-rw-------. 1 unclejoe mygroup 15510 Jan 24 14:42 .bash_history
drwx------. 10 unclejoe mygroup 190 Jan 24 01:42 .net
Within the .net folder, we see a bunch of seemingly temp folders:
[unclejoe#myhost .net]$ ls -la
total 4
drwx------. 10 unclejoe mygroup 190 Jan 24 01:42 .
drwx------. 14 unclejoe mygroup 4096 Jan 23 16:28 ..
drwx------. 4 unclejoe mygroup 46 Jan 24 12:09 MyApp1
drwx------. 5 unclejoe mygroup 66 Jan 24 01:42 MyApp2
Drilling further:
[unclejoe#myhost MyApp1]$ ls -la
total 24
drwx------. 4 unclejoe mygroup 46 Jan 24 12:09 .
drwx------. 10 unclejoe mygroup 190 Jan 24 01:42 ..
drwx------. 2 unclejoe mygroup 8192 Jan 24 01:42 cz1zui3n.uma
drwx------. 2 unclejoe mygroup 8192 Jan 24 12:09 pvwttlkm.z4s
Drilling furthest:
[unclejoe#myhost MyApp1]$ cd cz1zui3n.uma
[unclejoe#myhost cz1zui3n.uma]$ ls -l
total 30808
-rw-r--r--. 1 unclejoe mygroup 330240 Jan 24 01:42 Autofac.dll
-rw-r--r--. 1 unclejoe mygroup 16384 Jan 24 01:42 Autofac.Extensions.DependencyInjection.dll
-rw-r--r--. 1 unclejoe mygroup 143609 Jan 24 01:42 MyApp1.deps.json
-rw-r--r--. 1 unclejoe mygroup 10752 Jan 24 01:42 MyApp1.dll
-rw-r--r--. 1 unclejoe mygroup 149 Jan 24 01:42 MyApp1.runtimeconfig.json
-rw-r--r--. 1 unclejoe mygroup 27136 Jan 24 01:42 Common.dll
The problem is we don't expect these artifacts (dlls/app binaries) to be pushed here as its eating up a lot of space over time, especially when these strange temp directories get created (and never cleaned up on its own). We do not specify any environment variable in our .NET code to point to this home location.
Question:
Do you know what's causing these directories and files to get created? It appears to get created when the app runs after some period of time.
Any areas that we should be checking to identify root cause?
Thanks!
Are the apps published as Single File Applications? If so, the documentation have some pointers.
Looking at the fact that it's extracting 3rd-party libraries, I'm guessing this may be relevant:
Previously in .NET Core 3.0, when a user runs your single-file app, .NET Core host first extracts all files to a directory before running the application. .NET 5 improves this experience by directly running the code without the need to extract the files from the app.
And this explains the location:
If extraction is used the files are extracted to disk before the app
starts:
If environment variable DOTNET_BUNDLE_EXTRACT_BASE_DIR is set to a
path, the files will be extracted to a directory under that path.
Otherwise if running on Linux or MacOS, the files will be extracted to
a directory under $HOME/.net.
If running on Windows, the files will be
extracted to a directory under %TEMP%/.net.
I would like to know how i can run a dotnet console application as a service on a raspberry pi.
I can start the application mannualy by typing '''./dotnet/garagedeur_pi/publish/Garagedeur'''
I've created a Garagedeur.Service file:
Description=Garagedeur
[Service]
ExecStart=/home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll
WorkingDirectory=/home/pi/dotnet/garagedeur/pi/publish
#Restart=always
#RestartSec=10
User=pi
[Install]
WantedBy=multi-user.target
When I check the status I get this:
● Garagedeur.service - Garagedeur
Loaded: loaded (/lib/systemd/system/Garagedeur.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-02-17 12:09:49 CET; 11min ago
Process: 1142 ExecStart=/home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll (code=exited, status=200/CHDIR)
Main PID: 1142 (code=exited, status=200/CHDIR)
Feb 17 12:09:49 raspberrypi systemd[1]: Started Garagedeur.
Feb 17 12:09:49 raspberrypi systemd[1142]: Garagedeur.service: Changing to the requested working directory failed: No such file or directory
Feb 17 12:09:49 raspberrypi systemd[1142]: Garagedeur.service: Failed at step CHDIR spawning /home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll: No such file or directory
Feb 17 12:09:49 raspberrypi systemd[1]: Garagedeur.service: Main process exited, code=exited, status=200/CHDIR
Feb 17 12:09:49 raspberrypi systemd[1]: Garagedeur.service: Failed with result 'exit-code'.
Any help is greatly appreciated.
Solution:
Just read the error message and see that garagedeur/pi/ is different from garagedeur_pi/. Also there is a difference between Garagedeur.dll and Garagedeur – M. Spiller Feb 17 at 11:33
You can look here how to create the service file Host ASP.NET on Linux with Nginx.
In your service file you have to add the location of .NET installation, like this:
ExecStart=/usr/bin/dotnet /home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll
Here a example:
[Unit]
Description=Garagedeur
[Service]
ExecStart=/usr/bin/dotnet /home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll
WorkingDirectory=/home/pi/dotnet/garagedeur/pi/publish
Restart=always
RestartSec=10
User=pi
[Install]
WantedBy=multi-user.target
The path /usr/bin/dotnet is depending were you have installed .NET. On my raspberry pi this path is /home/pi/dotnet-arm32/dotnet. You can finde the right path with the command
dotnet --info
I have a c# project that I migrated from VS2010 to VS2015.
Each VS version of project had it's own Repository entry.
I want to compare current to a version from old repository - is this possible?
My structure is:
C:\Repositories\ProjectA
C:\Repositories\ProjectA_OLD
Is there a way to do this within VisualSVN?
If not, I could unix "diff" the inidivdual .cs files IF I new where the old version ones are stored. When I look in C:\Repositories\ProjectA_OLD, I don't see a "trunk" I just see:
drwxrwx---+ 1 Administrators None 0 Jun 18 05:59 locks
drwxrwx---+ 1 Administrators None 0 Jun 18 05:59 hooks
-rwxr-x---+ 1 Administrators None 251 Jun 18 05:59 README.txt
drwxrwx---+ 1 Administrators None 0 Jun 18 05:59 conf
-r-xr-x---+ 1 Administrators None 2 Jun 18 05:59 format
drwxrwx---+ 1 Administrators None 0 Nov 4 05:34 db
Where are the previous versions of files?