Why my application ran by Fast Startup? How to prevent that? - visual-c++

Here's a weird one. My application(MFC, really out one) relies on a service(C++). Both app and service are my coding. And I found if I shutdown my PC while app running and power-on, the app will be ran by system. And it doesn't work well with my service.
To be more detailed, my app and service communicate through NamedPipe, so if the app ran by system, it could go wrong.
Which already has been confirmed is that if I turned off 'fast startup' in power option and my app won't run after a shutdown then power-on action any more.
My app won't run with 'restart' exactly match the description of
system option
I promised that I didn't add any 'let my app run by fast startup' that kind of code.
I'm really confusing right now and there're few articles about Windows Fast Startup mechanism. I did found an article from MSDN about fast-startup boot and cold boot. But it's all about drivers, not Win32 desktop apps.
Here's the link:
https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/distinguishing-fast-startup-from-wake-from-hibernation
Could anyone please help?
No code for now.
I don't want my app ran by system automatically.
(btw, in common sense, we should initially code for that, but

Related

How can I run my Node JS program the whole time

I wrote a WhatsApp bot using the whatsapp-web.js module. My program only runs locally when I start it. But it should run 24/7. Can somebody help me? And how exactly do I have to proceed?
There's a lot to unpack here. I'm going to assume from the nature of your question that you're new to javascript and node development, so welcome!
Normally when we have an application that we want to have run "24/7" we have to deploy that application to a server, meaning a machine that lives somewhere on the internet. We do this because our local machines turn off, or are rebooted, or loose power. If we want something to run all the time, we'll typically put it on a machine that's running all the time.
There are a ton of options for this, "cloud computing" companies like AWS, Google GCP, Azure, DigitalOcean, Heroku, etc...
Since there are too many options to review each one, I'll describe how I like to do it.
I prefer to use a virtual machine deployed to a cloud provider. Most of them have a free tier where you can run a small, low powered machine for free. This should work fine for your chatbot.
Sign up for an account with, for example, Google, and create a free VM following their instructions. I recommend using Ubuntu 20.04 LTS for the VM image.
Next, you'll want to create a service unit file for systemd. Systemd is the thing that runs on linux that manages startup processes. A Unit file will look something like this:
[Unit]
Description=Readings API Service
After=network.target
[Service]
EnvironmentFile=/etc/environment
Type=simple
User=app
WorkingDirectory=/home/app/deploy/packages/api
ExecStart=/usr/local/bin/node /home/app/deploy/packages/api/server.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
In the above, I've created a user named "app" on the linux system, and created a folder named "deploy" in that user's home directory. I'm telling systemd to start that program when the computer starts, and to restart it if there's an error and it accidentally crashes.
It's going to take a bit of research and studying to understand all this and how it works, but hopefully this will get you started.

Foxx apps debugging workflow?

What is the recommended workflow to debug Foxx applications?
I am currently working on a pretty big application and it seems to me I am doing something wrong, because the way I am proceeding does not seem to be maintanable at all:
Do your changes in Foxx app (eg new endpoints).
Upload your foxx app to ArangoDB.
Test your changes (eg trigger API calls).
Check the logs to see if something went wrong.
Go to 1.
i experienced great time savings, shifting more of the development workflow to the terminal client 'arangosh'. Especially when debugging more complex endpoints, you can isolate queries and functions and debug each individually in the terminal. When done debugging, you merge your code in Foxx app and mount it. Require modules as you would do in Foxx, just enter variables as arguments for your functions or queries.
You can use arangosh either directly from the terminal or via the embedded terminal in the Arangodb frontend.
You may also save some time switching to dev mode, which allows you to have changes in your code directly reflected in the mounted app without fetching, mounting and unmounting each time.
That additional flexibility costs some performance, so make sure to switch back to production mode once your Foxx app is ready for deployment.
When developing a Foxx App, I would suggest using the development mode. This also helps a lot with debugging, as you have faster feedback. This works as follows:
Start arangod with the dev-app-path option like this: arangod --javascript.dev-app-path /PATH/TO/FOXX_APPS /PATH/TO/DB, where the path to foxx apps is the folder that contains a database folder that contains your foxx apps sorted by database. More information can be found here.
Make your changes, no need to deploy the app or anything. The app now automatically reloads on every request. Change, try out, change try out...
There's currently no debugging capabilities. We are planning to add more support for unit testing of Foxx apps in the near future, so you can have a more TDD-like workflow.

Scheduler on Azure

I need to be able to generate some type of Scheduling service within Windows Azure, but which is the best and most resilient?
Currently I have a Windows Service running Quartz, which works okay, but on a Windows Server. I need this to run in the cloud.
The tasks, read/write to a database and some will send emails.
I've looked over all the possible solutions in Stack Overflow, but they appear to be old and not updated to the latests Azure Platform.
Any suggestions or pointers?
The most adapted solution might be a worker role, MS has a tutorial specifically for what you're looking for: http://www.windowsazure.com/en-us/develop/net/tutorials/multi-tier-web-site/4-worker-role-a/
This would definitely a less expensive solution than instantiating a virtual machine, but might require some work.
I ended up using the Azure Mobile service and the Scheduler that come with it, which works a treat
I run a Worker Role using Quartz .NET to schedule stuff. Works great!
https://github.com/quartznet/quartznet
Obviously, that would be difficult to do on the cloud since you won't be able to install services or anything that could run in the background. A less than perfect solution would be to have a workstation under your control handle the scheduling and send updates to the web server which would then write them to the DB server. Otherwise, you should self host the website and application, etc.

Role Instances are taking longer than expected - Workaround issues

Whenever we get the error "Role Instances are taking longer than expected". The only possible options to do are .
Shutdown the emulators and try again.
Restart the machine and see if that helps.
Uninstall the Azure Tools for that version.
Some times uninstalling the same takes a long time,some times even days. It appears that some process or service is blocking the same. Has anyone faced this before ? If yes does anyone know which process would be blocking the same?
When an instance starts it will run the OnStart method on the worker/web role (depending on your service type). The more stuff you have in there, the more time it will take to start up the role. Common caveats are the Cache as mentioned and blob/table storage (if you do read/write/create when you start the role).
Try minimizing the OnStart's workload and moving any storage stuff in async tasks.
I have had similar problems as well in the past
IISConfigurator could not map the web roles in IIS. In my case it was due to corrupted file system ACLs on the code directory. See logs under C:\Users\YOUR_USER_NAME\AppData\Local\dftmp\IISConfiguratorLogs\
Another cause might be that something else has tied up the Port Numbers that Azure is trying to bind your web role on. Or that the ports that the local storage needs for tables/blobs and queues (10000-10002) have been taken by another app. Open a command prompt and run netstat -anb
Try running the Visual Studio using "Run as Administrator" option.

Best solution to host a (command line) Windows application?

I have a Windows application that does some calculations and is called from command line. On my Windows machine, I have a PHP script running under Apache that executes the application and shows the output.
Is there any hosting solution that I can use to do the same? I can't figure out if EC2 or Azure are the right solutions. Basically, I need a web server + ability to execute my application.
Suggestions? Thanks.
You can host your application on AppHarbor, the .NET Platform-as-a-Service. You can either port your web frontend to .NET or try to get your PHP stuff working with Phalanger. AppHarbor is working on Background Tasks, which might be a good match for your workload.
I would just run the PHP script you already have under IIS in a Windows Azure web role.
If it is a Windows Application and you have the source code I would go with an Azure Worker Role. The advantage of using a PaaS (as Azure) instead of an IaaS (as Amazon) is that you wont have to bother of keeping the server up to date.
The real investment in time will be when you rewrite your application to make it work as a Worker Role. The time needed to do this work depends on how your application works right now. If is uses a lot of disc access it might be difficult and perhaps an Amazon server would be better. But if it only crunches numbers in memory an Azure Worker Role is a very good candidate.
The real advantage of using an Amazon server is that you probably wont need to do any work at all. Except maintaining the server.
As described in the question both Azure and EC2 will do the job very well. This is the kind of task both systems are designed for.
So the question becomes really: which is best? That depends on two things: what the application needs to do and your own experience and preference.
As it's a Windows application there should probably be a leaning towards Azure. While EC2 supports Windows, the tooling and support resources for Azure are probably deeper at this point.
If cost is a factor then a (somewhat outdated) resource is here: http://blog.mccrory.me/2010/10/30/public-cloud-hourly-cost-comparison/ -- the conclusion is that, by and large, Azure and Amazon are roughly similar for compute charges.
Steve Marx has a blog post that describes how to run another web server (i.e not IIS) on Azure
This potentially has everything you need - you can deploy Apache and your executable and run it in exactly the same way.
Alternatively - you can deploy your executable along side a bit of code in a worker role that would run that application periodically, all depending on your exact requirements

Resources