![]() I removed the interaction and added the following harmless endless loop, waiting for the process to be killed: // App can only be stopped by killing the processĬonsole.WriteLine("Started in service mode. While /etc/rc.local seems to free the memory continuously, the cronjob requires more and more memory. Its main benefit is the opportunity you get with the graceful cancellation to clean-up the code of your background tasks when the. NET Core 2.0 and later versions) or in any process/host (starting in. 534 escaping to avoid errors, 535 using date and cron to run a job on. Unfortunately, what happens, is that the program, started by Cron or by /etc/rc.local skips the ReadLine() and runs into an endless loop, messing up the memory (and maybe swap on hard drive) with an endless number of Enter 'exit' to close MyApp. The IHostedService interface provides a convenient way to start background tasks in an ASP.NET Core web application (in. 133 coproc command, 423 core dumps, preventing, 349 cp command copying one. Using this code, I wanted to keep the program running until a user inputs exit or until this "service" is killed. Here is the last part of the C# code of my console application: // App can be quit by keyboard input "exit"Ĭonsole.WriteLine("Enter 'exit' to close MyApp.") ReadLine() waiting for a certain input).ĭetails: I found out what happened. Tl dr Avoid user interaction in the console app (e.g. There is no problem when starting manually or from /etc/local.rc, but just when starting from the cronjob. I have no idea at all what could be the problem. Su service -c 'sh /home/service/my-app.sh' &Īgain, it started perfectly fine after reboot, and there is also no memory leak any more. Now I tried to remove the cronjob and added the launcher script to the /etc/local.rc file instead: # Start MyApp But: When I restart MyApp manually, there is no memory leak any more. When I cancel MyApp after reboot, I see that the "memory leak" is immediately stopped. ![]() After about 10 minutes, the whole free space is gone, and MyApp is quit by the system. ![]() the total size of /home/service does not increase. But, when calling df repeatedly, I noticed that the free disk space of / was continuously decreasing! I tried to find out which file it is, but ncdu did not show any difference over time. In this case, the interval is specified using a cron expression /15 which means to run every 15 seconds. Fire-and-Forget Jobs Fire-and-forget jobs are executed only once and almost immediately after creation. The RecurringJob.AddOrUpdate method creates a recurring background job and accepts two parameters the job which is a lambda, and the interval to trigger the job. No Windows Service or separate process required. I wanted to start the file after reboot, so I created a cronjob for the launcher script, using crontab -e: /home/service/my-app.shĪfter reboot, MyApp lauches perfectly fine. An easy way to perform background processing in. There is a simple launcher script in my home folder, called my-app.sh: cd /home/service/my-app NET Core 3.0 Console App, running on a Ubuntu 18.04 server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |