In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what to do if the .net program cannot be started through crontab". In the daily operation, I believe that many people have doubts about what to do when the .net program cannot be started through crontab. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt that "the .net program cannot be started through crontab." Next, please follow the editor to study!
I. description of the problem
The .net gateway program needs to set a scheduled restart, according to the daily operation, first drop the running PID kill, and then execute the startup service.
If you put the script on the crontab scheduling task, you can PID kill the service, but you can't start the service. You can start it successfully by running the script manually.
The .net service restart script test1.sh is as follows:
[root@localhost ~] # cat test1.sh #! / bin/bashID= `ps-ef | grep YTGateWayServiceZZ | grep-v "grep" | awk'{print $2} '`for id in $ID;dokill-9$ iddonesleep 3 against Nohup dotnet / home/gateway1/YTGateWayServiceZZ.dll > / dev/null 2 > & 1 &
After trying to write the. Net program as a service, it is found that it can be restarted normally.
Second, write .net programs as services
First drop the kill of the service started by the execution path, and then execute the config.sh script to write the program into a service.
And write it into the crontab scheduled task, and the program can be restarted normally through the test.
[root@localhost ~] # cat config.shallop systemctl restart gateway1.service binbash # find the dotnet command location dotnet= `which dotnet` # write .net core to run in service mode cat > / usr/lib/systemd/system/gateway1.service conf & & echo "0 * / 6 * conf" > conf & & crontab conf & & rm-f conf
Execute script config.sh
[root@localhost ~] # chmod + x config.sh [root@localhost ~] #. / config.sh
Manage Custom Service commands
# systemctl status gateway1.service# systemctl start gateway1.service# systemctl restart gateway1.service# systemctl enable gateway1.service III. Reason why the script cannot be started through crontab
After writing the. net program as a service test, it is likely to be caused by the failure to find system environment variables during crontab execution.
Check the script and find that only the dotnet command does not use the absolute path. Try to add the dotnet command to the absolute path and you can start it successfully.
[root@localhost ~] # which dotnet/usr/local/bin/dotnet [root@localhost ~] # cat test1.sh #! / bin/bashID= `ps-ef | grep YTGateWayService | grep-v "grep" | awk'{print $2} '`for id in $ID;dokill-9$ iddonesleep 3transition Nohup / usr/local/bin/dotnet / root/publish/YTGateWayService.dll > / dev/null 2 > & 1 & at this point, the study of "what if .net programs cannot be started through crontab" is over. I hope to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.