Unable to run console app on windows azure - azure

I am working on yii2. I have created a cron service and via console app, I am calling it. Below is my code
namespace console\controllers;
use yii\console\Controller;
class TestController extends Controller {
public function actionIndex() {
echo "cron service runnning ";
}
public function actionMail($to) {
echo "Sending mail to " . $to;
}
}
By following one of the solution I am able to make things work
Console App Code
#Echo off
title My Cron Job
:: See title at the top
php E:\xampp\htdocs\yii test
pause
I have deployed this console app in my local(Windows 10) and testing machine(Windows Server 2012 R2). And in both the app works fine.
Output (Local and Testing Machine)
But when I try to apply the same method in my azure windows The output I am getting is
It doesn't display the message cron service running.
Environment Variable (php)
I have followed the same steps as mentioned in the solution. But I don't know why it's not working on my cloud.
Any help would be highly appreciated.

Related

Blazor WASM Azure Static Web App, Functions not working

I created a simple Blazor WASM webapp using C# .NET5. It connects to some Functions which in turn get some data from a SQL Server database.
I followed the tutorial of BlazorTrain: https://www.youtube.com/watch?v=5QctDo9MWps
Locally using Azurite to emulate the Azure stuff it all works fine.
But after deployment using GitHub Action the webapp starts but then it needs to get some data using the Functions and that fails. Running the Function in Postman results in a 503: Function host is not running.
I'm not sure what I need to configure more. I can't find the logging from Functions. I use the injected ILog, but can find the log messages in Azure Portal.
In Azure portal I see my 3 GET functions, but no option to test or see the logging.
With the help of #Aravid I found my problem.
Because I locally needed to tell my client the URL of the API I added a configuration in Client\wwwroot\appsettings.Development.json.
Of course this file doesn't get deployed.
After changing my code in Program.cs to:
var apiAddress = builder.Configuration["ApiAddress"] ?? $"{builder.HostEnvironment.BaseAddress}/api/";
builder.Services.AddHttpClient("Api",(options) => {
options.BaseAddress = new Uri(apiAddress);
});
My client works again.
I also added my SqlServer connection string in the Application Settings of my Static Web App and the functions are working as well.
I hope somebody else will benefit from this. Took me several hours to figure it out ;)

Making a Azure WebJob run a console application

I'm trying to setup a scheduled WebJob (every minute). I've made a Windows Console Application in VS 2019 like this:
using System;
using System.Net;
namespace EveryMinute
{
class Program
{
static void Main(string[] args)
{
WebRequest request = WebRequest.Create("https://some.url.com");
WebResponse response = request.GetResponse();
}
}
}
The output of this request is not important, I just need the url to be triggered every minute.
I can run the exe on my Windows computer. But when I create a WebJob with this exe attached, I keep getting a [failed] notice every minute.
Can anyone tell me what I am doing wrong?
Thank you for your help.
To make the answer visible to others, I'm summarizing the answer as below:
I don't know if I can send that dll together with other files in the
zip?
Yes, we need to add all the contents under Bin/Debug(/net472) path in a .zip file.
We can also deploy the webjob in vs by clicking publish button.
If your job fails, you can find the detailed error message in the Run Details.

communicate with console application in service fabric

I've just started a PoC on service fabric for a project and I'm stuck on something that should have been straightforward but has become a real pain ...
What I need to do is host a console app returning some values in the service fabric and be able to call it on demand and get back its return value.
So I've created a simple exe looking like this, hosted in a GuestExe
static void Main(string[] args)
{
Console.WriteLine("123");
File.AppendAllText("hello.txt" + DateTime.Now.ToString(), "Hello world!");
//Console.ReadLine();
}
First, if the readline is commented, the explorer shows the guestExe as failing and the file is not created.
If I uncomment it, the guest exe will appear as being good in the explorer, and the console app will be started on it's own (despite I didn't ask for it), the file will be created, and I won't be able to call it.
cluster image
I've tried to just hit few things in my browser : the endpoint above, http://localhost:19081/PoC9/GuestExe?cmd=instance and same without the cmd argument.
If anyone has any idea of how that should be done, please help :)

Getting Error When Starting Node in ASP.NET Core 2.0

I first create a vanilla asp.net core 2.0 web site with vs2017. Then, I add node starting by updating startup.cs with these lines:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddNodeServices(options => {
options.LaunchWithDebugging = true;
options.DebuggingPort = 9229;
});
}
I create a view that returns some data and when I run it locally, it works. Here is that code:
public async Task<IActionResult> NodeTest([FromServices] INodeServices nodeServices)
{
ViewData["ResultFromNode"] =
await nodeServices.InvokeAsync<string>("NodeSrc/myNodeModule.js");
return View(viewName: "NodeTest");
}
My myNodeModule.js is as follows:
module.exports = function (callback) {
var message = 'Hello from Node js script at ' +
new Date().toString() + ' process.versions ' +
process.version;
callback(/* error */ null, message);
};
When I run this locally with vs2017 it works. When I use VSTS and deploy, even after adding a process variable of ASPNETCORE_ENVIRONMENT to Development, I still get an error when I try to browse to the page. The error i below.
My 2 questions are:
1. How can I get better errors reported
2. How can I get node to run on the server in both debug and production modes.
Error:
Error.
An error occurred while processing your request.
Request ID: 0HL87NKEP2GL6:00000002
Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
You need to specify Copy if newer in Copy to Output Directory of JS file properties (Right click the JS file=>Properties=>Change Copy to Output Directory to Copy if newer).
BTW: it works fine in local without changing Copy to Output directory, it looks for the file in project root path. Did test with Using Node Services in ASP.NET Core article
Regarding development environment in Azure Web app, you can do it in Application settings of web app:
Go to azure portal
Select your web app
Select Application Settings
Add ASPNETCORE_ENVIRONMENT with Development value in App Settings.

My custom Windows Service is not writing to my custom Event Log

I have written a custom Windows Service that writes data to a custom Event Log (in the Windows Event Viewer).
For dev'ing the biz logic that the service uses, I created a Windows Form which simulates the Start/Stop methods of the Windows Service.
When executing the biz logic via the Windows Forms, info is successfully written to my custom Event Log. However, when I run the same biz logic from the custom Windows Service, information is failing to be written to the Event Log.
To be clear, I have written a library (.dll) that does all the work that I want my custom service to do - including the create/write to the custom Event Log. My Form application references this library as does my Windows Service.
Thinking the problem is a security issue, I manually set the custom Windows Service to "Log on" as "Administrator", but the service still did not write to the Event Log.
I'm stuck on how to even troubleshoot this problem since I can't debug and step into the code when I run the service (if there is a way to debug a service, please share).
Do you have any ideas as to what could be causing my service to fail to write to the event log?
I use it like this. There can be some typos. Writed it on my phone browser...
public class MyClass
{
private EventLog eventLog = new EventLog();
public void MyClass()
{
if (!System.Diagnostics.EventLog.SourceExists("MyLogSource"))
System.Diagnostics.EventLog.CreateEventSource("MyLogSource", "MyLogSource_Log");
eventLog.Source = "MyLogSource";
eventLog.Log = "MyLogSource_Log";
}
private void MyLogWrite()
{
eventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
}
To debug a running service you need to attach to the process. See here for the steps.
You could also add parameter checking to the Main entry point and have a combination service and console app which would start based on some flag. See this SO post for a good example but here's a snippet:
using System;
using System.ServiceProcess;
namespace WindowsService1
{
static class Program
{
static void Main(string[] args)
{
if (args == null)
{
Console.WriteLine("Starting service...");
ServiceBase.Run(new ServiceBase[] { new Service1() });
}
else
{
Console.WriteLine("Hi, not from service: " + args[0]);
}
}
}
}
The above starts the app in console mode if there any parameters exist and in service mode if there are no parameters. Of course it can be much fancier but that's the gist of the switch.
I discovered why my service wasn't writing to the Event Log.
The problem had nothing to do with any part of the code/security/etc that was attempting to write to the EL. The problem was that my service wasn't successfully collecting the information that is written to the EL - therefore, the service wasn't even attempting to write the log.
Now that I fixed the code that collects the data, data is successfully writing to the event log.
I'm open to having this question closed since the question was amiss to the real problem.

Resources