xref: /f-stack/start.sh (revision 06399ef3)
1a9643ea8Slogwang#!/bin/bash
2a9643ea8Slogwang
3a9643ea8Slogwangfunction usage() {
4a9643ea8Slogwang    echo "F-Stack app start tool"
5a9643ea8Slogwang    echo "Options:"
6a9643ea8Slogwang    echo " -c [conf]                Path of config file"
7a9643ea8Slogwang    echo " -b [N]                   Path of binary"
8a7b42f3dSTonghao Zhang    echo " -o [N]                   Other ARGs for app"
9a9643ea8Slogwang    echo " -h                       show this help"
10a9643ea8Slogwang    exit
11a9643ea8Slogwang}
12a9643ea8Slogwang
13a9643ea8Slogwangconf=config.ini
14a9643ea8Slogwangbin=./example/helloworld
15a9643ea8Slogwang
16a7b42f3dSTonghao Zhangwhile getopts "c:b:o:h" args
17a9643ea8Slogwangdo
18a9643ea8Slogwang    case $args in
19a9643ea8Slogwang         c)
20a9643ea8Slogwang            conf=$OPTARG
21a9643ea8Slogwang            ;;
22a9643ea8Slogwang         b)
23a9643ea8Slogwang            bin=$OPTARG
24a9643ea8Slogwang            ;;
25a7b42f3dSTonghao Zhang         o)
26a7b42f3dSTonghao Zhang            others=$OPTARG
27a7b42f3dSTonghao Zhang            ;;
28a9643ea8Slogwang         h)
29a9643ea8Slogwang            usage
30a9643ea8Slogwang            exit 0
31a9643ea8Slogwang            ;;
32a9643ea8Slogwang    esac
33a9643ea8Slogwangdone
34a9643ea8Slogwang
35*06399ef3SYuYangif ! type "bc" > /dev/null 2>&1; then
36*06399ef3SYuYang    echo "please install bc"
37*06399ef3SYuYang    exit
38*06399ef3SYuYangfi
39*06399ef3SYuYang
40a9643ea8Slogwangallcmask0x=`cat ${conf}|grep lcore_mask|awk -F '=' '{print $2}'`
41a9643ea8Slogwang((allcmask=16#$allcmask0x))
42a9643ea8Slogwang
43a9643ea8Slogwangnum_procs=0
44a9643ea8SlogwangPROCESSOR=$(grep 'processor' /proc/cpuinfo |sort |uniq |wc -l)
45a9643ea8Slogwangfor((i=0;i<${PROCESSOR};++i))
46a9643ea8Slogwangdo
47a9643ea8Slogwang    mask=`echo "2^$i"|bc`
48a9643ea8Slogwang    ((result=${allcmask} & ${mask}))
49a9643ea8Slogwang    if [ ${result} != 0 ]
50a9643ea8Slogwang    then
51a9643ea8Slogwang        ((num_procs++));
52a9643ea8Slogwang    fi
53a9643ea8Slogwangdone
54a9643ea8Slogwang
55a02c88d6Slogwangfor((proc_id=0; proc_id<${num_procs}; ++proc_id))
56a9643ea8Slogwangdo
57a9643ea8Slogwang    if ((proc_id == 0))
58a9643ea8Slogwang    then
59a7b42f3dSTonghao Zhang        echo "${bin} --conf ${conf} --proc-type=primary --proc-id=${proc_id} ${others}"
60a7b42f3dSTonghao Zhang        ${bin} --conf ${conf} --proc-type=primary --proc-id=${proc_id} ${others} &
61a9643ea8Slogwang        sleep 5
62a9643ea8Slogwang    else
63a7b42f3dSTonghao Zhang        echo "${bin} --conf ${conf} --proc-type=secondary --proc-id=${proc_id} ${others}"
64a7b42f3dSTonghao Zhang        ${bin} --conf ${conf} --proc-type=secondary --proc-id=${proc_id} ${others} &
65a9643ea8Slogwang    fi
66a9643ea8Slogwangdone
67