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