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.
Related
I have developed a Windows-worker service and I want to start it in a docker-based environment for automated testing. Therefore I built it with the following command:
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true
Additionally I have the following Dockerfile:
FROM mcr.microsoft.com/windows/servercore/insider:10.0.17763.107
COPY ["Install/", "C:/Service/Name/"]
RUN powershell New-Service -Name "Name" -BinaryPathName "C:\Service\Name\Name.exe"
When trying to start the service with Start-Service -Name "Name" the startup takes long and the service stays in the state Starting and then I get an 1053-error in the Eventlog (LogName=System).
Due to the fact, that the service did not start I made another one, that is mainly based on the template in Visual Studio, so it should only log a message to the eventlog. This service has the same behavior. When installing it on my local machine everything works fine.
Do you have any ideas why the service remains in the state Starting even though it does already the tasks of the Running-state?
I solved the problem now, because I found the following issue: https://github.com/dotnet/runtime/issues/50020
UseWindowsService() does not work in Docker, so I had to specify WindowsServiceLifetime:
services.AddSingleton<IHostLifetime, WindowsServiceLifetime>();
I'm trying to publish a small .NET Core 3.1 Web App on Azure App Service (Linux), and the app won't start.
No matter if I'm publishing using Visual Studio, or Azure DevOps, i'm getting the following error on my Linux Azure App Service (which, by the way, already contains two other apps):
2021-06-23T22:19:47.102376527Z _____
2021-06-23T22:19:47.102415627Z / _ \ __________ _________ ____
2021-06-23T22:19:47.102422327Z / /_\ \___ / | \_ __ \_/ __ \
2021-06-23T22:19:47.102426627Z / | \/ /| | /| | \/\ ___/
2021-06-23T22:19:47.102430627Z \____|__ /_____ \____/ |__| \___ >
2021-06-23T22:19:47.102434927Z \/ \/ \/
2021-06-23T22:19:47.102438927Z A P P S E R V I C E O N L I N U X
2021-06-23T22:19:47.102442827Z
2021-06-23T22:19:47.102446327Z Documentation: http://aka.ms/webapp-linux
2021-06-23T22:19:47.102449927Z Dotnet quickstart: https://aka.ms/dotnet-qs
2021-06-23T22:19:47.102453427Z ASP .NETCore Version: 3.1.13
2021-06-23T22:19:47.102457227Z Note: Any data outside '/home' is not persisted
2021-06-23T22:19:47.307988432Z Running oryx create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -defaultAppFilePath /defaulthome/hostingstart/hostingstart.dll -bindPort 8080 -userStartupCommand 'dotnet WebApplication1.dll'
2021-06-23T22:19:47.378242802Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2021-06-23T22:19:47.382799606Z Could not find operation ID in manifest. Generating an operation id...
2021-06-23T22:19:47.382816206Z Build Operation ID: 7f48597c-0791-46e5-bffd-b0007d8b27b7
2021-06-23T22:19:49.335414280Z Writing output script to '/opt/startup/startup.sh'
2021-06-23T22:19:49.567879341Z Running user provided startup command...
2021-06-23T22:19:49.610748271Z A compatible installed .NET Core SDK for global.json version [3.1.409] from [/home/site/wwwroot/global.json] was not found
2021-06-23T22:19:49.610783071Z Install the [3.1.409] .NET Core SDK or update [/home/site/wwwroot/global.json] with an installed .NET Core SDK:
2021-06-23T22:19:49.610825071Z It was not possible to find any installed .NET Core SDKs
2021-06-23T22:19:49.610829471Z Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
2021-06-23T22:19:49.610835971Z https://aka.ms/dotnet-download
2021-06-23T22:19:50.944Z ERROR - Container procoding-me_0_8935305e for site procoding-me has exited, failing site start
2021-06-23T22:19:50.961Z ERROR - Container procoding-me_0_8935305e didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2021-06-23T22:19:50.978Z INFO - Stopping site procoding-me because it failed during startup.```
I've tried to create the web app on azure again, and even tried to publish the same code of the other apps, and the same problem occurs.
Anybody has a hint of the cause of this problem?
So, after a long day of trying to figure this thing out I managed to publish and app to an app service running linux. I'm using an App Service Plan (Linux, B1) that lives in a "shared" resource group since I want to run multiple apps on it. I'm also deploying the infrastructure using Bicep and the pipeline is yaml.
The issue was, as it seems, that when I was deploying the app through Azure DevOps, it was nesting the app archive in another zip-file. The app zip-file needs to be the root-folder in the app, not obvious unless you download the files that are being executed in the app service itself.
Yeah, also I'm using the self-contained version of deployment here. You can read more about it here. I had no success doing it with the framework-dependent way unless I published the app from Visual Studio 2022.
So, in the end, here are the snippets that made the thing work for me:
azure-pipelines.yaml - Build stage
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
projects: '**/*Api.csproj'
arguments: '--configuration $(buildConfiguration) -r linux-x64 --self-contained true --output $(Build.ArtifactStagingDirectory)'
modifyOutputPath: false
publishWebProjects: false
zipAfterPublish: true
displayName: 'Dotnet Publish'
- task: PublishBuildArtifacts#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
ArtifactName: drop
azure-pipelines.yaml - Deploy stage
- task: AzureRmWebAppDeployment#4
inputs:
azureSubscription: '$(azureSubscription)'
appType: webAppLinux
WebAppName: '$(output_appServiceName)'
packageForLinux: '$(Pipeline.Workspace)/**/a.zip' #Since we are not specifying the folder name in the steps prior, the folder will be called just a.zip, this is fine since the deployment is going to rename it any way in the app service file system anyway(in Kudu)
The app service resource in Bicep
resource appService 'Microsoft.Web/sites#2021-01-01' = {
name: '${serviceName}-${environment}-app'
location: resourceGroup().location
kind: 'app'
properties: {
serverFarmId: planId
siteConfig: {
alwaysOn: true
http20Enabled: true
linuxFxVersion: 'DOTNETCORE|5.0'
appSettings: [
{
name: 'WEBSITE_RUN_FROM_PACKAGE'
value: '1'
}
]
}
}
}
Hope this helps.
P.S. Having "corrupted" zip-files in the app service (Kudu) can cause the app to fail. I suggest anyone having this issue to either delete all files from wwwroot or simply delete the app service resource and deploy it from scratch to make sure it can start properly.
I am attempting to start a new Blazor (ASP.NET Core hosted) project and properly publish to linux-arm, linux-arm doesn't seem to be the issue at the moment.
I am able to get it running, however, Browser > Dev Tool > Console is showing the following errors:
GET http://localhost:5000/_framework/_bin/rpiServer.Client.pdb (404) Not Found blazor.webassembly.js:1
GET http://localhost:5000/_framework/_bin/rpiServer.Client.pdb (404) Not Found blazor.webassembly.js:1
Having my startup project as rpiServer.Client or rpiServer.Server during Publish yields the same errors when all is setup on the RPI.
These are the steps I used to Publish and get the Hosting Environment running:
dotnet publish -r linux-arm --output R:\...\rpiServer (on Windows for the RPI), then on the RPI, executing sudo chmod +755 ./rpiServer.Server and finally ./rpiServer.Server to start the website.
Note, I can find _framework folder but is isn't under the main folder, I first need to open rpiServer.Client/dist/ to find the folder. I also tried to copy this folder to the root of the Website, no changes to the error messages.
Does anyone know the intended process/step for publishing and intended file structure. I will provide more details when requested.
I installed a Windows Service under an account type user in service installer. When I try to start it from service lists I can't find it. If I change the account type to local service in the installer then I can find it. I need to built it under a user account. How to solve this?
save this text to a batch file(.bat) and run in the sample folder with your window service
#ECHO OFF
ECHO -----------------------------------------------------------------------------------------
ECHO ------------------------------ Auto Install Windows Service -----------------------------
ECHO -----------------------------------------------------------------------------------------
ECHO --- Typing the path of Windows Service need to install
#SET /p serviceName=
IF NOT "%serviceName%" == "" (
ECHO --- Installing "%serviceName%"
ECHO -------------------------------------------------------------------------------------
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil %serviceName% -i
net start yourservicename
ECHO -------------------------------------------------------------------------------------
PAUSE
)
Sometimes this happen when you install the service and the List Service Window is open. just install the service with the service windows close, sound silly but it works.
I was trying to attach a volume to the docker container but none of the ways I tried worked. I am working with an Azure Windows 2016 vm
Here the docker info:
Containers: 2
Running: 1
Paused: 0
Stopped: 1
Images: 108
Server Version: 1.12.2-cs2-ws-beta
Storage Driver: windowsfilter
Windows:
Logging Driver: json-file
Plugins:
Volume: local
Network: nat null overlay
Swarm: inactive
Default Isolation: process
Kernel Version: 10.0 14393 (14393.321.amd64fre.rs1_release_inmarket.161004-2338)
Operating System: Windows Server 2016 Datacenter
OSType: windows
Architecture: x86_64
CPUs: 2
Total Memory: 7 GiB
Name: wfgendocker
ID: QBKJ:RZAU:ADAI:WS4U:JV2K:IB5I:52K6:MWTD:NS3X:KRP6:SH6T:QKDT
Docker Root Dir: C:\ProgramData\docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
So in my docker file I am copying over my IIS website into inetpub/root
and my goal is to mount /inetpub on the container to the local machine so changes to the scripts and web.config can be done at run time.
At first I tried VOLUME /inetpub in the dockerfile which build successfully, but then when I ran the container, it give me the following error.
encountered an error during CreateContainer: failure in a Windows system call: The directory is not empty
But there is no mention anywhere in the docker documentation about the volume needing to be empty.
So then I tried attaching the volume at run, such as, docker run -p 80:80 -v C:/build/inetpub:C:/inetpub web/iis .
this gave me the same error as above. but when i try
docker run -p 80:80 -v C:/build/inetpub:C:/randomtest web/iis .
it works, but I can't modify the files else the container stops.
The last thing I tried was working with docker-compose,
in my service I have
volumes:
- ./inetpub:/inetpub
which give the following error
Cannot create container for service wfgen: invalid volume spec "/inetpub": invalid volume specification
I tried many variations of - ./inetpub:/inetpub but they always gave me the same error.
Thanks for any help, I ve been stuck on this for days without any results.
Here is my docker file
FROM microsoft/iis:10.0.14393.206
SHELL ["powershell"]
#adding windows features to vm
RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \
Install-WindowsFeature Web-Asp-Net45
#temp tempfile
RUN mkdir C:\temp
#adding wfgen_admin user to vm
RUN mkdir C:\createUser
COPY createUser/ /createUser
RUN createUser/wfgen_adminCreate.ps1
#installing the services and starting them
RUN mkdir C:\aprogramfiles
COPY wfgenServices/ /aprogramfiles
RUN aprogramfiles/.\winsvc-install.cmd
#copying wfgen webcontent to vm
COPY inetpub/wwwroot/ /inetpub/wwwroot
RUN createUser/wfgen_admin_grant_access.ps1
#removing default website that runs on port 80
RUN Remove-WebSite -Name 'Default Web Site'
#creating a new iis website with the copied wfgen website i am not sure if i have the right commands here
RUN powershell -NoProfile -Command \
Import-module IISAdministration; \
New-IISSite -Name "wfgenroot" -PhysicalPath C:\inetpub\wwwroot - BindingInformation "*:80:";
#converting weforms and ws to applications
RUN ConvertTo-WebApplication "IIS:/Sites/wfgenroot/wfgen";
RUN ConvertTo-WebApplication "IIS:/Sites/wfgenroot/wfgen/WfApps/WebForms";
RUN ConvertTo-WebApplication "IIS:/Sites/wfgenroot/wfgen/ws"
#Setting the authentication type of the website
RUN Set-WebConfiguration system.web/authentication 'IIS:/Sites/wfgenroot' -value #{mode='Windows'}
RUN Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value true -PSPath 'IIS:/Sites/wfgenroot/wfgen'
RUN New-SelfSignedCertificate -CertStoreLocation createUser -DnsName 127.0.0.1
RUN New-WebBinding -Name "wfgenroot" -IP "*" -Port 443 -Protocol https
RUN $Thumbprint = (Get-ChildItem -Path Microsoft.PowerShell.Security\Certificate::LocalMachine\My | Where-Object {$_.Subject -match "127.0.0.1"}).Thumbprint;
RUN get-item Microsoft.PowerShell.Security\Certificate::LocalMachine\My\$Thumbprint | new-item 0.0.0.0!443
#RUN createUser/appcmdrun.ps1
#exposing port 80
EXPOSE 80
EXPOSE 443
WORKDIR /inetpub
So I've just tried this:
docker run --rm -v c:/folder:c:/somefolder microsoft/iis
and it works perfectly, I can create files, I can delete them, etc.
docker info:
C:\Users\core>docker info
Containers: 2
Running: 1
Paused: 0
Stopped: 1
Images: 6
Server Version: 1.12.2-cs2-ws-beta
Storage Driver: windowsfilter
Windows:
Logging Driver: json-file
Plugins:
Volume: local
Network: nat null overlay transparent
Swarm: inactive
Security Options:
Kernel Version: 10.0 14393 (14393.321.amd64fre.rs1_release_inmarket.161004-2338)
Operating System: Windows 10 Enterprise
OSType: windows
Architecture: x86_64
CPUs: 4
Total Memory: 7.865 GiB
Name: pytop
ID: FENS:OO6R:J273:I5BB:2OGZ:HAMM:6YFX:53BP:XBA5:G3LE:QNKE:FLJ3
Docker Root Dir: C:\ProgramData\Docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
127.0.0.0/8
I'm using docker beta.
This is because at the moment windows containers support only empty directories. I needed to map only logs volume and this command in Dockerfile helped me:
RUN ["powershell", "Remove-Item", "C:\\inetpub\\wwwroot\\Portals\\Logs\\*", "-Recurse"]
Then I simply issued docker run --rm -d -p 8000:80 -v c:/Logs:c:/inetpub/wwwroot/Portals/Logs --name site-v my-image-name
Got info from here.