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
Related
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.
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.
I created a worker service in .net core 6 like example here and deployed it in Centos. its unit is like
[Unit]
Description=my test app
[Service]
Type=notify
ExecStart=/usr/bin/DaneshAfzar
[Install]
WantedBy=multi-user.target
systemctl start DaneshAfzar.service raises an error : Job for DaneshAfzar.service failed because the control process exited with error code. see "systemctl status DaneshAfzar.service" and "journalctl -xe" for details
output of journalctl -xe :
Failed at step EXEC spawning /usr/bin/DaneshAfzar: Permission Denied
I used chmod 777 for the whole directory but error persists.
Let's asume the service ist called myservice. I think it is better to deploy your .net service to the /opt/myservice directory or to /usr/local/myservice .
Then the structure would look like this:
# Folder path
/opt/myservice
# path of the executable
/opt/myservice/myservice
# or
/opt/myservice/myservice.dll
only the file /opt/myservice/myservice.dll must be executable
A service file then could be like this:
[Unit]
Description=IG Render Service
[Service]
WorkingDirectory=/opt/myservice
ExecStart=/usr/bin/dotnet myservice.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=myservice
# Optionaly define a specific user to run the service
# User=someuser
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
hope this helps.
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
When I deploy a cloud service to Windows Azure it causes a number of VSPerf.exe instances to start - anything from 1 to 5.
Between them they consume all the CPU and none of the processes ever terminate themselves.
If I remotely connect to the instance and terminate the processes manually they restart on the next request. If the process is terminated during the request then the request succeeds and the page displays and functions as expected.
The only difference between this is a previous deployment is I have since upgraded to .NET 4.5 and therefore upgraded the cloud service to server 2012.
What could be causing this?
Update
For every failed start up 2 events are logged:
VsPerf Tool Error: Error starting data collection with a dedicated process D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Performance Tools\VSPerf.
.NET Runtime version 4.0.30319.18010 - Loading profiler failed during CoCreateInstance. Profiler CLSID: '{44a86cad-f7ee-429c-83eb-f3cde3b87b70}'. HRESULT: 0x80040111. Process ID (decimal): 1444. Message ID: [0x2504].
Update 2
The VSPerf issue does not occur after a new instance is created or the machines are reimaged (at least thats a fix (an annoying and time consuming fix) for now).
Check the Azure publish settings in Visual Studio, I'd bet you have enabled profiling on the Advanced tab.
Same issue, 2 processes of VSPerf.exe burning 100% of CPU on 2nd role instance. IIS becomes unresponsive on that instance. We had the exact same issue 4 months back, disappeared "somehow" when profiling was enabled just when we were debugging this issue with MSFT support (someone inside MSFT knows this issue). But without being able to repro the issue (we only had screenshots) it was dropped.
Since I see it again, 5 minutes back and since Azure SDK 2.0 makes it easy to grab diagnostic logs (unlike the configuration ritual from SDK 1.8), here is something useful for the next folks to make sense off
The core error is Application VsPerf Tool Error: Error starting data collection with a dedicated process D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Performance Tools\VSPerf. with the detailed logs (4 entries) below. Interestingly I had 2 processes of VSPerf.exe burning 100% of CPU and also had 2 log entries ....
{555908d1-a6d7-4695-8e1e-26931d2012f4} Service Control Manager 7011 System A timeout (30000 milliseconds) was reached while waiting for a transaction response from the iphlpsvc service. <Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='Service Control Manager' Guid='{555908d1-a6d7-4695-8e1e-26931d2012f4}' EventSourceName='Service Control Manager'/><EventID Qualifiers='49152'>7011</EventID><Version>0</Version><Level>2</Level><Task>0</Task><Opcode>0</Opcode><Keywords>0x8080000000000000</Keywords><TimeCreated SystemTime='2013-06-23T17:37:25.557218700Z'/><EventRecordID>1269</EventRecordID><Correlation/><Execution ProcessID='520' ThreadID='1104'/><Channel>System</Channel><Computer>RD00155DA909B8</Computer><Security/></System><EventData><Data Name='param1'>30000</Data><Data Name='param2'>iphlpsvc</Data></EventData></Event> WebApp_IN_1 6/23/2013 5:37 PM 2 520 1104
{555908d1-a6d7-4695-8e1e-26931d2012f4} Service Control Manager 7011 System A timeout (30000 milliseconds) was reached while waiting for a transaction response from the Schedule service. <Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='Service Control Manager' Guid='{555908d1-a6d7-4695-8e1e-26931d2012f4}' EventSourceName='Service Control Manager'/><EventID Qualifiers='49152'>7011</EventID><Version>0</Version><Level>2</Level><Task>0</Task><Opcode>0</Opcode><Keywords>0x8080000000000000</Keywords><TimeCreated SystemTime='2013-06-23T17:37:56.259560100Z'/><EventRecordID>1270</EventRecordID><Correlation/><Execution ProcessID='520' ThreadID='1104'/><Channel>System</Channel><Computer>RD00155DA909B8</Computer><Security/></System><EventData><Data Name='param1'>30000</Data><Data Name='param2'>Schedule</Data></EventData></Event> WebApp_IN_1 6/23/2013 5:37 PM 2 520 1104
00000000-0000-0000-0000-000000000000 VSPERF 4100 Application VsPerf Tool Error: Error starting data collection with a dedicated process D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Performance Tools\VSPerf. <Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='VSPERF'/><EventID Qualifiers='57635'>4100</EventID><Level>2</Level><Task>0</Task><Keywords>0x80000000000000</Keywords><TimeCreated SystemTime='2013-06-23T17:40:37.000000000Z'/><EventRecordID>266</EventRecordID><Channel>Application</Channel><Computer>RD00xxxxxxxxx</Computer><Security/></System><EventData><Data>Error starting data collection with a dedicated process D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Performance Tools\VSPerf.</Data></EventData></Event> WebApp_IN_1 6/23/2013 5:40 PM 2 0 0
00000000-0000-0000-0000-000000000000 VSPERF 4100 Application VsPerf Tool Error: Error starting data collection with a dedicated process D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Performance Tools\VSPerf. <Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='VSPERF'/><EventID Qualifiers='57635'>4100</EventID><Level>2</Level><Task>0</Task><Keywords>0x80000000000000</Keywords><TimeCreated SystemTime='2013-06-23T17:40:41.000000000Z'/><EventRecordID>267</EventRecordID><Channel>Application</Channel><Computer>RD00xxxxxxxxx</Computer><Security/></System><EventData><Data>Error starting data collection with a dedicated process D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Performance Tools\VSPerf.</Data></EventData></Event> WebApp_IN_1 6/23/2013 5:40 PM 2 0 0
The closest I've found to a workaround is to create a startup task
<Task commandLine="VSPerf.cmd" executionContext="elevated" taskType="background" />
where VSPerf.cmd is a simple launcher
PowerShell -ExecutionPolicy Unrestricted .\VSPerf.ps1
exit /B 0
for a PowerShell script which attempts to kill over-active VSPerf instances:
function Restart-VSPerf {
$procs = (
gwmi -Query "SELECT IDProcess,PercentProcessorTime FROM Win32_PerfFormattedData_PerfProc_Process WHERE Name='vsperf' AND PercentProcessorTime > 25" |
Foreach-Object { $_pid = $_.IDProcess ; gwmi -Query "SELECT Handle,CommandLine FROM win32_process WHERE Name='vsperf.exe' AND Handle=$_pid" | Select-Object Handle, CommandLine }
)
if ($procs) {
# Get VSPerf path.
# NB The regex uses conditional matching with an expression, as described in https://msdn.microsoft.com/en-us/library/36xybswe.aspx
# to ensure that a single capturing group gets the contents of quoted arguments and unquoted arguments.
$regex = [regex] '^(("?)((?(?<=")[^"]*|[^"\s]*))\2(\s+|$))+$'
$vsperf = $regex.Match($procs[0].CommandLine).Groups[3].Captures[0].Value
& $vsperf /detach
# Kill
$procs | Foreach-Object { Stop-Process -Force -Id $_.Handle }
# Restart
Start-Sleep -s 1
$procs | Foreach-Object {
$_args = ($regex.Match($_.CommandLine).Groups[3].Captures[1..99] | Select-Object -ExpandProperty Value)
Start-Process $vsperf -ArgumentList "$_args"
}
}
}
while (1) {
Start-Sleep -s 180
Restart-VSPerf
}
It works sometimes but not always. Suggestions for reliability improvements welcome.