×

Application Manager程序管理器

消耗积分:0 | 格式:zip | 大小:0.00 MB | 2022-06-22

李春梅

分享资料个

授权协议 MIT
开发语言 C/C++
操作系统 跨平台
软件类型 开源软件

软件简介

Application Manager,程序管理器,可以用来替代supervisor和cron-tab,用来管理计算机上部署的各种类型的程序,支持定视任务,长任务,提供命令行和REST接口。

Setup build environment on Ubuntu

apt-get install g++ git make zlib1g-dev libssl-dev cmake
apt-get install libboost-all-dev libcpprest-dev libjsoncpp-dev libace-dev libgoogle-glog-dev libcctz-dev

 

REST APIs

# Application Manager
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
![coverage](https://img.shields.io/badge/coverage-90%25-yellowgreen.svg?maxAge=2592000)
![version](https://img.shields.io/badge/version-1.1.0-blue.svg?maxAge=2592000)

## Introduction
Application Manager is a daemon application to manage different types of sub-applications(process), each application can be a specific jobs, the app-manager will make sure all defined applications running on-time with defined behavior. provide REST APIs for integrate with outside app, provide command-line to start/stop and register new app easily. Also can be a JWT server.

The internal timer is multi-threaded with high-precision that can be used to replace Linux cron-tab and supervisor.


Supported applications  | Behavior
---|---
Long running application | Monitor app running all time and restart when exited immediately
Short runing application | Periodic startup app
Periodic long running application |Long running applicatin but will be restart periodic
Extra Features | Application can define avialable time range in a day
Application can define envionment variables
Application can define resource (memory & CPU) limitation (cgroup on Linux)
SSL support
Collect host/app resource usage
Remote run shell commands
JWT authentication


## Setup build environment on CentOS/Ubuntu/Debian
```
git clone https://github.com/laoshanxi/app-manager.git
sudo sh app-manager/autogen.sh
```
## Build
```
cd app-manager
make
```

## REST APIs

Method | URI | Desc
---|---|---
GET | /app/$app-name | Get an application infomation
GET | /app/$app-name/testrun?timeout=5 | Test run an application
GET | /app/$app-name/testrun/output?process_uuid=uuidabc | Get the stdout and stderr for the test run
GET | /app-manager/applications | Get all application infomation
GET | /app-manager/resources | Get host resource usage
GET | /app-manager/config | Get all the configuration
PUT | /app/$app-name | Register a new application
POST| /app/$app-name?action=start | Start an application
POST| /app/$app-name?action=stop | Stop an application
POST| /authenticate | JWT authenticate
DELETE| /app/$app-name | Unregister an application

## How to install
**CentOS**:
```
wget https://github.com/laoshanxi/app-manager/releases/download/v1.0/appmanager-1.0-1.x86_64.rpm
sudo yum install ./appmanager-1.0-1.x86_64.rpm -y
```
If you directly run command line from installation console, there will have issue on dependency libraries, you need source /opt/appmanager/script/app.bashrc to get the environment. for the new console will be OK, the source operation was automaticlly add to /etc/bashrc
```
$ appc view
appc: error while loading shared libraries: libcpprest.so.2.10: cannot open shared object file: No such file or directory

$ source /opt/appmanager/script/app.bashrc 

$ appc view
id user  active pid   return memory name        command_line
1  root  start  4485  0      0.3M   period      /bin/sleep 20
2  root  start  2048  0      1.9M   ping        ping www.baidu.com
```
**Ubuntu**:
```
$ apt-get install appmanager_1.0_amd64.deb
```

## Show all sub command

```
$ appc
Commands:
  view        List application[s]
  config      Display configurations
  resource    Display host resource usage
  start       Start a application
  stop        Stop a application
  restart     Restart a application
  reg         Add a new application
  unreg       Remove an application
  test        Test run an application and get output
  sh          Use shell run a command and get output

Run 'appc COMMAND --help' for more information on a command.

Usage:  appc [COMMAND] [ARG...] [flags]
```


## List application[s]

```
$ appc view
id user  active pid   return memory name        command_line
1  root  start  2350  0      0.3M   period      /bin/sleep 20
2  root  start  1860  0      1.9M   ping        ping www.baidu.com
$ appc view -n ping
id user  active pid   return memory name        command_line
1  root  start  1860  0      1.9M   ping        ping www.baidu.com
```

## Display host resource usage

```
$ appc resource
{
   "cpu_cores" : 4,
   "cpu_processors" : 4,
   "cpu_sockets" : 1,
   "host_name" : "myubuntu",
   "mem_freeSwap_bytes" : 1023406080,
   "mem_free_bytes" : 3755048960,
   "mem_totalSwap_bytes" : 1023406080,
   "mem_total_bytes" : 5189935104,
   "net_ip" : [
      {
         "docker0" : "172.17.0.1"
      },
      {
         "enp0s3" : "10.0.2.15"
      }
   ]
}
```

## Display configurations

```
$ appc config
{
        "Applications" : 
        [
                {
                        "active" : 1,
                        "command_line" : "/bin/sleep 20",
                        "daily_limitation" : 
                        {
                                "daily_end" : "23:00:00",
                                "daily_start" : "09:00:00"
                        },
                        "env" : 
                        {
                                "TEST_ENV1" : "value",
                                "TEST_ENV2" : "value"
                        },
                        "keep_running" : true,
                        "name" : "period",
                        "posix_timezone" : "CST+8:00:00",
                        "resource_limit" : 
                        {
                                "cpu_shares" : 100,
                                "memory_mb" : 200,
                                "memory_virt_mb" : 300
                        },
                        "run_as" : "root",
                        "run_once" : false,
                        "start_interval_seconds" : 30,
                        "start_interval_timeout" : 0,
                        "start_time" : "2018-01-01 16:00:00",
                        "working_dir" : "/opt"
                },
                {
                        "active" : 1,
                        "command_line" : "ping www.baidu.com",
                        "name" : "ping",
                        "run_as" : "root",
                        "run_once" : false,
                        "working_dir" : "/tmp"
                }
        ],
        "Description" : "myhost",
        "LogLevel" : "DEBUG",
        "RestListenPort" : 6060,
        "SSLCertificateFile" : "server.crt",
        "SSLCertificateKeyFile" : "server.key",
        "SSLEnabled" : true,
        "ScheduleIntervalSeconds" : 2
}

```

## Register a new application

```
$ appc reg
Register a new application:
  -n [ --name ] arg              application name
  -u [ --user ] arg (=root)      application process running user name
  -c [ --cmd ] arg               full command line with arguments
  -w [ --workdir ] arg (=/tmp)   working directory
  -a [ --active ] arg (=1)       application active status (start is true, stop
                                 is false)
  -t [ --start_time ] arg        start date time for short running app (e.g., 
                                 '2018-01-01 09:00:00')
  -s [ --daily_start ] arg       daily start time (e.g., '09:00:00')
  -d [ --daily_end ] arg         daily end time (e.g., '20:00:00')
  -m [ --memory ] arg            memory limit in MByte
  -v [ --virtual_memory ] arg    virtual memory limit in MByte
  -p [ --cpu_shares ] arg        CPU shares (relative weight)
  -d [ --daily_end ] arg         daily end time (e.g., '20:00:00')
  -e [ --env ] arg               environment variables (e.g., -e env1=value1 -e
                                 env2=value2)
  -i [ --interval ] arg          start interval seconds for short running app
  -x [ --extra_time ] arg        extra timeout for short running app,the value 
                                 must less than interval  (default 0)
  -z [ --timezone ] arg          posix timezone for the application, reflect 
                                 [start_time|daily_start|daily_end] (e.g., 
                                 'WST+08:00' is Australia Standard Time)
  -k [ --keep_running ] arg (=0) monitor and keep running for short running app
                                 in start interval
  -f [ --force ]                 force without confirm.
  -h [ --help ]                  help message

  
$ appc reg -n ping -u kfc -c 'ping www.google.com' -w /opt
Application already exist, are you sure you want to update the application (y/n)?
y
{
   "active" : 1,
   "command_line" : "ping www.google.com",
   "name" : "ping",
   "pid" : -1,
   "return" : 0,
   "run_as" : "kfc",
   "working_dir" : "/opt"
}
```


## Remove an application
```
appc unreg -n ping
Are you sure you want to remove the application (y/n)?
y
Success
```

## Start an application
```
$ appc start -n ping
```

## Stop an application
```
$ appc stop -n ping
```

## Test run an application and get stdout
``` sh
$ appc test -n ping -t 5
PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
64 bytes from 220.181.112.244: icmp_seq=1 ttl=55 time=20.0 ms
64 bytes from 220.181.112.244: icmp_seq=2 ttl=55 time=20.1 ms
64 bytes from 220.181.112.244: icmp_seq=3 ttl=55 time=20.1 ms
64 bytes from 220.181.112.244: icmp_seq=4 ttl=55 time=20.1 ms
64 bytes from 220.181.112.244: icmp_seq=5 ttl=55 time=20.1 ms
```

## Run a shell command and get stdout
``` sh
$ appc sh -e LD_LIBRARY_PATH=/opt/appmanager/lib64 -c "appc view" 
{
        "active" : 0,
        "command_line" : "/bin/sh -c 'export LD_LIBRARY_PATH=/opt/appmanager/lib64;appc view'",
        "env" : 
        {
                "LD_LIBRARY_PATH" : "/opt/appmanager/lib64"
        },
        "memory" : 0,
        "name" : "58de823f-cecf-4b67-b362-d08db46167f6",
        "pid" : -1,
        "return" : 0,
        "run_as" : "root",
        "run_once" : true,
        "working_dir" : "/tmp"
}

id user  active pid   return memory name        command_line
1  root  start  2605  0      0.3M   period      /bin/sleep 20
2  root  start  1860  0      1.9M   ping        ping www.baidu.com
3  root  stop   0     0      0      58de823f-c* /bin/sh -c 'export LD_LIBRARY_PATH=/opt/appmanager/lib64;appc view'
Process already finished or killed by timeout event
application <58de823f-cecf-4b67-b362-d08db46167f6> removed.
```

![example](https://github.com/laoshanxi/app-manager/blob/master/doc/example.gif?raw=true) 

## Remote run a shell command
![appc_sh](https://github.com/laoshanxi/app-manager/blob/master/doc/appc_sh.gif?raw=true) 

## Usage scenarios
1. Integrate with package installation script and register startup command to app manager automaticlly
2. Install on remote host to execute command remotly and get output (can build-up web ssh)
3. Get resource usage (cpu/memory) for each application and host resource status

## 3rd party deependencies
- [C++11](http://www.cplusplus.com/articles/cpp11)
- [ACE](https://github.com/DOCGroup/ACE_TAO)
- [Microsoft cpprestsdk](https://github.com/Microsoft/cpprestsdk)
- [boost](https://github.com/boostorg/boost)
- [jsoncpp](https://github.com/open-source-parsers/jsoncpp)
- [log4cpp](http://log4cpp.sourceforge.net)
- [jwt_cpp](https://thalhammer.it/projects/jwt_cpp)

## Design
### Thread model

URI
GET /app/$app-name
GET /app-manager/applications
GET /app-manager/config
PUT /app/$app-name
POST /app/$app-name?action=start
POST /app/$app-name?action=stop
DELETE /app/$app-name

Show all sub command

$ appc
Commands:
  view        List application[s]
  config      Display configurations
  start       Start a application
  stop        Stop a application
  reg         Add a new application
  unreg       Remove an application

Run 'appc COMMAND --help' for more information on a command.

Usage:  appc [COMMAND] [ARG...] [flags]
 

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"//m.obk20.com/www/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'Application Manager程序管理器',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"https://www.elecfans.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);