Commit 1ad7d4a4 by unknown

fix Ubuntn_18.04 OS ps app run error, will while start Daemon and plugin

Version: 1.3.1 RC
parent 443c9bf2
......@@ -22,33 +22,33 @@
<ProjectGuid>{B24A017B-387C-49C2-A321-3554AD9A1D48}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>familyMart_takeaway</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>familyMart_takeaway</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
......
......@@ -12,7 +12,7 @@
#define BUFSZ 150
// 监控 App 间隔周期 (单位: s)
#define MONITOR_APP_INTERVAL 60
#define MONITOR_APP_INTERVAL 120
#define MONITOR_APP_NAME "takeaway"
// POS Real Start Command :: nohup /opt/pos/fmtakeout/takeaway > /dev/null &
#define MONITOR_APP_START_COMMAND "nohup /opt/pos/fmtakeout/takeaway > /dev/null & "
......@@ -21,6 +21,8 @@
#define MONITOR_LOG_DIR "/opt/pos/fmtakeout/"
#define MONITOR_LOG_NAME "/opt/pos/fmtakeout/fmPluginDaemon.log"
#define MONITOR_PS_APP_NAME "/opt/pos/fmtakeout/ps"
void init_daemon()
{
......@@ -65,7 +67,7 @@ int does_service_work()
int count;
char buf[BUFSZ];
char command[150];
sprintf(command, "%s%s%s" ,"ps -ef | grep ", MONITOR_APP_NAME , " | grep -v grep | wc -l" );
sprintf(command, "%s%s%s%s" , MONITOR_PS_APP_NAME, " -ef | grep ", MONITOR_APP_NAME , " | grep -v grep | wc -l" );
if((fp = popen(command,"r")) == NULL)
err_quit("popen");
......@@ -92,13 +94,31 @@ void main()
fclose(fp);
fp = NULL;
}
// 判断 fmtakeout 目录下是否存在 有可执行权限的 ps 程序
fp = fopen(MONITOR_LOG_NAME, "a"); //为记录后续状态,对日志文件进行追加;
if (access(MONITOR_PS_APP_NAME, X_OK) == 0) {
fprintf(fp, "FmPluginDaemon:: Current Time Is:%s And The ps App Exist And Has Execute Permission \n", asctime(localtime(&t)));//转换为本地时间输出
fclose(fp);
fp = NULL;
}
else {
fprintf(fp, "FmPluginDaemon:: Current Time Is:%s And The ps App Non-Exist Or No Execute Permission \n", asctime(localtime(&t)));//转换为本地时间输出
fclose(fp);
fp = NULL;
exit(0);
}
while(1)
{
sleep( MONITOR_APP_INTERVAL ); //等待一分钟再写入
count = does_service_work();
fp=fopen(MONITOR_LOG_NAME,"a"); //为记录后续状态,对日志文件进行追加;
sleep( MONITOR_APP_INTERVAL ); //等待2分钟后再写入
count = does_service_work();
fp = fopen(MONITOR_LOG_NAME, "a"); //为记录后续状态,对日志文件进行追加;
if ( fp != NULL ) {
time(&t);
......
......@@ -66,10 +66,12 @@ std::string g_plugin_relogin_ods_reason; // 插件重新登录 ODS 的原因;
#ifdef WIN32
bool bInitDone = false; //初始化完成
std::string g_pluginAppName = "takeaway_d";
std::string g_psAppFullName = "E:\\zouwuyang\\FamilyMart\\PosPluginClient\\familyMart_takeaway\\bin\\ps";
std::string g_appBootStriptFile = "E:\\zouwuyang\\FamilyMart\\PosPluginClient\\familyMart_takeaway\\bin\\run_cream.sh";
#else
bool bInitDone = false; //初始化完成
std::string g_pluginAppName = "takeaway";
std::string g_psAppFullName = "/opt/pos/fmtakeout/ps";
std::string g_appBootStriptFile = "/opt/pos/bin/run_cream.sh";
#endif
......@@ -318,7 +320,7 @@ int main(int argc,char *argv[])
if (g_local_pos_init_data.length() && enableLocalPosInitReqTimeOutLimit > 18 ) {
LOG(INFO) << "PosPlugin Haven't Receive Pos Init Tcp Data, Try Enable Local Pos Init Data File";
if (PosHandle::check_pos_already_exist() ) {
LOG(INFO) << "PosPlugin Haven't Receive Pos Init Tcp Data, Check Pos Listen Port Is Ok, Prepare Login ODS...... ";
LOG(INFO) << "PosPlugin Haven't Receive Pos Init Tcp Data, Check Pos Listen Port Is Ok, Prepare Login ODS...... ";
g_init_data = g_local_pos_init_data;
bInitDone = true;
}
......
......@@ -22,32 +22,32 @@
<ProjectGuid>{395675BD-3E73-4656-A9D0-24A94B28C20C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>takeaway_ut</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
......
......@@ -238,9 +238,9 @@ pid_t getPidByName(const char *name)
DIR *pdir = NULL;
struct dirent *pde = NULL;
FILE *pf = NULL;
char buff[128];
char buff[300] = {0};
pid_t pid;
char szName[128];
char szName[300] = {0};
pid_t nowPid = getpid();
LOG(INFO) << "this process pid is:" << nowPid;
// 遍历/proc目录下所有pid目录
......@@ -346,12 +346,22 @@ void create_process_daemon() {
std::string strDaemonAppPath(strBinPath.data());
strDaemonAppPath.append("fmPluginDaemon");
// 判断 fmtakeout 目录下是否存在 有可执行权限的 fmPluginDaemon 程序
if (access(strDaemonAppPath.c_str(), X_OK) == 0) {
LOG(INFO) << "create_process_daemon:: DaemonAppPath:" << strDaemonAppPath.c_str() << " Exist And Has Execute Permission ";
} else {
LOG(INFO) << "create_process_daemon:: DaemonAppPath:" << strDaemonAppPath.c_str() << " Non-Exist Or No Execute Permission ";
return;
}
// 判断 fmtakeout 目录下是否存在 有可执行权限的 ps 程序
if (access(g_psAppFullName.c_str(), X_OK) == 0) {
LOG(INFO) << "create_process_daemon:: psAppPath:" << g_psAppFullName.c_str() << " Exist And Has Execute Permission ";
}
else {
LOG(INFO) << "create_process_daemon:: psAppPath:" << g_psAppFullName.c_str() << " Non-Exist Or No Execute Permission ";
return;
}
// 3、判断daemon程序是否已经启动,已经启动着无需重复启动;
if ( does_daemon_work() )
......@@ -369,14 +379,14 @@ int does_daemon_work()
{
#ifdef WIN32
LOG(INFO) << "does_daemon_work:: DaemonApp Is Running, No Need Check Status ";
return 0;
return 1;
#else
FILE* fp;
int count;
char buf[150];
char command[150];
sprintf(command, "%s%s%s", "ps -ef | grep ", "fmPluginDaemon", " | grep -v grep | wc -l");
sprintf(command, "%s%s%s%s", g_psAppFullName.c_str(), " -ef | grep ", "fmPluginDaemon", " | grep -v grep | wc -l");
if ((fp = popen(command, "r")) == NULL) {
LOG(INFO) << "does_daemon_work:: Check DaemonApp Is Running Command Error !!! popen Failed Skip DaemonApp";
......
......@@ -3,6 +3,8 @@
#include <string>
extern std::string g_psAppFullName;
//函数名: GetProcDir()
//功 能: 获取当前程序的路径
std::string GetProcDir();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment