Application Manager,程序管理器,可以用来替代supervisor和cron- tab,用来管理计算机上部署的各种类型的程序,支持定视任务,长任务,提供命令行和REST接口。
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
git clone https://github.com/laoshanxi/app-manager.git sudo sh app-manager/autogen.sh
cd app-manager make
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
$ 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
$ apt-get install appmanager_1.0_amd64.deb
$ 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]
$ 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
$ 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" } ] }
$ 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 }
$ 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" }
appc unreg -n ping Are you sure you want to remove the application (y/n)? y Success
$ appc start -n ping
$ appc stop -n ping
$ 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
$ 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.
$ 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]