C# Mono 程序在 raspberry pi 自动执行时崩溃
C# Mono program crashes on raspberry pi when auto executed
我们有一个 C# mono 程序 运行ning on a raspberry pi 3. 当我手动执行时程序完全执行,即 sudo mono /pathtoexe 但是当它在重启时执行从 rc.local(rc.local 启动脚本文件 sudo /pathto .sh 文件,该文件又通过 sudo mono /paththexe 启动应用程序)程序仅部分执行,日志中没有可见错误。
请注意,我们试图克服的测试用例是让我们的应用程序 运行 在没有互联网的情况下运行,因为如果有互联网(手动和自动启动)
PI是Raspberry PI3运行ningRaspbianVersion 8 (Jessie)
Mono JIT 编译器版本 3.2.8 (Debian 3.2.8+dfsg-10)
这是 rc.local 文件:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
#hwclock -s
#sudo /etc/init.d/watchdog start&
sudo /home/pi/Vbox/./Main.sh&
#sudo /home/pi/Vbox/./Cmu.sh&
#/usr/bin/mono-service -p:/home/pi/Vbox /home/pi/Vbox/VboxV2.exe
sudo iwconfig wlan0 txpower off
#sudo mono /home/pi/Vbox/Vbox.exe
#sudo python /home/pi/Audio/audio_play.py
#iptables-restore < /etc/iptables.ipv4.nat
exit 0
这里要注意的主线是
须藤 /home/pi/Vbox/./Main.sh&
Main.sh 文件是:
#!/bin/bash
Date=`date +%d_%m_%Y`
ErrorLogPath="/home/pi/LOG/GatewayWrapperError_$Date.log"
LogPath="/home/pi/LOG/GatewayWrapperLog_$Date.log"
## Fail over Block
function Failover
{
ErrorIn=
Datetime=`date +%d-%m-%Y:%H-%M-%S`
echo "Error: Program"
printf "$Datetime: Error executing $ErrorIn program. Sending E-Mail notification \n">>$ErrorLogPath
echo "Error: notification"
#sudo mono --runtime=v4.0 /home/pi/EXE/Email.exe &
#wait
printf "$Datetime: Gateway notification sent \n">>$ErrorLogPath
#sudo wvdial 3gconnect &
#sleep 30
echo "wvdial run succed"
#sudo reboot
}
function main
{
## Executing Net_Connection_Program Core
# {(
# ExecutionDateTime=`date +%d-%m-%Y:%H-%M-%S`
# printf "$ExecutionDateTime: Net_Connect.sh started. \n">>$LogPath
# echo "Net_Connect Started"
# sudo /home/pi/Wrapper/./NetConnect.sh &
# #sudo /home/pi/Wrapper/./test.sh &
# )} ||
# {(
# Failover "Net_Connect_Core"
#)}
echo "Started"
## Executing Gateway Core
{(
ExecutionDateTime=`date +%d-%m-%Y:%H-%M-%S`
printf "$ExecutionDateTime: ES900G started. \n">>$LogPath
echo "ES900G Started"
sudo mono --runtime=v4.0 /home/pi/Vbox/VboxV2.exe &> /home/pi/LOG/GatewayWrapperLog_24_09_2018.log
)} ||
{(
Failover "Gateway_Core"
)}
}
##Master Call
main;
当程序通过脚本执行时,日志停止于此:
Function: Main Started
73574f
Vbox Version 1.0.0.0
ERROR: ConnectMQTT - Exception connecting to the broker
代码中的主要函数如下:
static void Main()
{
try
{
Thread.Sleep(5000);
Helper.WriteLine("Function: Main Started");
const string path = "/home/pi/Vbox/vboxid.txt";
VboxId = File.ReadAllText(path);
Console.WriteLine(VboxId);
Version = $"{Assembly.GetExecutingAssembly().GetName().Version}";
Helper.WriteLine($"Vbox Version {Version}");
CommMqttClient = null;
if (string.IsNullOrEmpty(VboxId)) return;
MQTT.ConnectMqtt(); //This is last error printed in the log shown above. The program seems to crash after this
Task.Factory.StartNew(VideoStorage.StartStorage);
Audio = new AudioPublicAnnouncement();
LiveStreaming = new VideoStreaming();
VideoRetrieve = new VideoRetrieve();
Console.ReadLine();
}
catch (Exception e)
{
Helper.WriteLine("Error - Main: " + e.Message, ConsoleColor.Red);
}
}
在上面的代码中,如果手动执行程序,则可以。这是我面临的主要问题..
请注意,这是以前的代码维护者编写的,我被带进来解决这个问题。他目前不可用,过去 3 天我一直在努力解决这个问题。任何帮助将不胜感激。
谢谢,
Va运行
编辑:具有不停止执行的无限循环的最新代码:
static void Main()
{
try
{
Thread.Sleep(5000);
Helper.WriteLine("Function: Main Started");
const string path = "/home/pi/Vbox/vboxid.txt";
VboxId = File.ReadAllText(path);
Console.WriteLine(VboxId);
Version = $"{Assembly.GetExecutingAssembly().GetName().Version}";
Helper.WriteLine($"Vbox Version {Version}");
CommMqttClient = null;
if (string.IsNullOrEmpty(VboxId)) return;
MQTT.ConnectMqtt();
Task.Factory.StartNew(delegate
{
MQTT.PublishMessage("REBOOT", $"VBOXID:{VboxId};VERSION:{Version};TIME:{DateTime.Now:dd-MM-yyyy HH-mm-ss};", false);
});
Task.Factory.StartNew(VideoStorage.StartStorage);
Audio = new AudioPublicAnnouncement();
LiveStreaming = new VideoStreaming();
VideoRetrieve = new VideoRetrieve();
while (true)
{
Thread.Sleep(1000);
}
}
catch (Exception e)
{
Helper.WriteLine("Error - Main: " + e.Message, ConsoleColor.Red);
}
}
我将此问题标记为已解决。不幸的是,它与代码的执行方式有关。详细信息在问题的最后编辑中。 @knocte 是的,我们需要尽快执行此操作,但由于它是一个跨越 500 多个站点的生产系统 运行,我们需要对其采取经过计算和计划的方法。
感谢您的所有投入。非常感激。干杯!
我们有一个 C# mono 程序 运行ning on a raspberry pi 3. 当我手动执行时程序完全执行,即 sudo mono /pathtoexe 但是当它在重启时执行从 rc.local(rc.local 启动脚本文件 sudo /pathto .sh 文件,该文件又通过 sudo mono /paththexe 启动应用程序)程序仅部分执行,日志中没有可见错误。
请注意,我们试图克服的测试用例是让我们的应用程序 运行 在没有互联网的情况下运行,因为如果有互联网(手动和自动启动)
PI是Raspberry PI3运行ningRaspbianVersion 8 (Jessie) Mono JIT 编译器版本 3.2.8 (Debian 3.2.8+dfsg-10)
这是 rc.local 文件:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
#hwclock -s
#sudo /etc/init.d/watchdog start&
sudo /home/pi/Vbox/./Main.sh&
#sudo /home/pi/Vbox/./Cmu.sh&
#/usr/bin/mono-service -p:/home/pi/Vbox /home/pi/Vbox/VboxV2.exe
sudo iwconfig wlan0 txpower off
#sudo mono /home/pi/Vbox/Vbox.exe
#sudo python /home/pi/Audio/audio_play.py
#iptables-restore < /etc/iptables.ipv4.nat
exit 0
这里要注意的主线是 须藤 /home/pi/Vbox/./Main.sh&
Main.sh 文件是:
#!/bin/bash
Date=`date +%d_%m_%Y`
ErrorLogPath="/home/pi/LOG/GatewayWrapperError_$Date.log"
LogPath="/home/pi/LOG/GatewayWrapperLog_$Date.log"
## Fail over Block
function Failover
{
ErrorIn=
Datetime=`date +%d-%m-%Y:%H-%M-%S`
echo "Error: Program"
printf "$Datetime: Error executing $ErrorIn program. Sending E-Mail notification \n">>$ErrorLogPath
echo "Error: notification"
#sudo mono --runtime=v4.0 /home/pi/EXE/Email.exe &
#wait
printf "$Datetime: Gateway notification sent \n">>$ErrorLogPath
#sudo wvdial 3gconnect &
#sleep 30
echo "wvdial run succed"
#sudo reboot
}
function main
{
## Executing Net_Connection_Program Core
# {(
# ExecutionDateTime=`date +%d-%m-%Y:%H-%M-%S`
# printf "$ExecutionDateTime: Net_Connect.sh started. \n">>$LogPath
# echo "Net_Connect Started"
# sudo /home/pi/Wrapper/./NetConnect.sh &
# #sudo /home/pi/Wrapper/./test.sh &
# )} ||
# {(
# Failover "Net_Connect_Core"
#)}
echo "Started"
## Executing Gateway Core
{(
ExecutionDateTime=`date +%d-%m-%Y:%H-%M-%S`
printf "$ExecutionDateTime: ES900G started. \n">>$LogPath
echo "ES900G Started"
sudo mono --runtime=v4.0 /home/pi/Vbox/VboxV2.exe &> /home/pi/LOG/GatewayWrapperLog_24_09_2018.log
)} ||
{(
Failover "Gateway_Core"
)}
}
##Master Call
main;
当程序通过脚本执行时,日志停止于此:
Function: Main Started
73574f
Vbox Version 1.0.0.0
ERROR: ConnectMQTT - Exception connecting to the broker
代码中的主要函数如下:
static void Main()
{
try
{
Thread.Sleep(5000);
Helper.WriteLine("Function: Main Started");
const string path = "/home/pi/Vbox/vboxid.txt";
VboxId = File.ReadAllText(path);
Console.WriteLine(VboxId);
Version = $"{Assembly.GetExecutingAssembly().GetName().Version}";
Helper.WriteLine($"Vbox Version {Version}");
CommMqttClient = null;
if (string.IsNullOrEmpty(VboxId)) return;
MQTT.ConnectMqtt(); //This is last error printed in the log shown above. The program seems to crash after this
Task.Factory.StartNew(VideoStorage.StartStorage);
Audio = new AudioPublicAnnouncement();
LiveStreaming = new VideoStreaming();
VideoRetrieve = new VideoRetrieve();
Console.ReadLine();
}
catch (Exception e)
{
Helper.WriteLine("Error - Main: " + e.Message, ConsoleColor.Red);
}
}
在上面的代码中,如果手动执行程序,则可以。这是我面临的主要问题..
请注意,这是以前的代码维护者编写的,我被带进来解决这个问题。他目前不可用,过去 3 天我一直在努力解决这个问题。任何帮助将不胜感激。
谢谢, Va运行
编辑:具有不停止执行的无限循环的最新代码:
static void Main()
{
try
{
Thread.Sleep(5000);
Helper.WriteLine("Function: Main Started");
const string path = "/home/pi/Vbox/vboxid.txt";
VboxId = File.ReadAllText(path);
Console.WriteLine(VboxId);
Version = $"{Assembly.GetExecutingAssembly().GetName().Version}";
Helper.WriteLine($"Vbox Version {Version}");
CommMqttClient = null;
if (string.IsNullOrEmpty(VboxId)) return;
MQTT.ConnectMqtt();
Task.Factory.StartNew(delegate
{
MQTT.PublishMessage("REBOOT", $"VBOXID:{VboxId};VERSION:{Version};TIME:{DateTime.Now:dd-MM-yyyy HH-mm-ss};", false);
});
Task.Factory.StartNew(VideoStorage.StartStorage);
Audio = new AudioPublicAnnouncement();
LiveStreaming = new VideoStreaming();
VideoRetrieve = new VideoRetrieve();
while (true)
{
Thread.Sleep(1000);
}
}
catch (Exception e)
{
Helper.WriteLine("Error - Main: " + e.Message, ConsoleColor.Red);
}
}
我将此问题标记为已解决。不幸的是,它与代码的执行方式有关。详细信息在问题的最后编辑中。 @knocte 是的,我们需要尽快执行此操作,但由于它是一个跨越 500 多个站点的生产系统 运行,我们需要对其采取经过计算和计划的方法。 感谢您的所有投入。非常感激。干杯!