File: //etc/rc.d/rc6.d/K25btpanelhids
#!/bin/bash
# chkconfig: 2345 55 25
# description: BT-Panel-Hids
### BEGIN INIT INFO
# Provides: BT-Panel-Hids
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts BT-Panel-Hids
# Description: starts the BT-Panel-Hids Service
### END INIT INFO
target_dir=/www/server/panel/plugin/bt_hids
cd $target_dir
server_start()
{
status_path="/www/server/panel/data/hids_data/status.pl"
# 如果status.pl文件不存在,创建默认开启状态
if [ ! -e "$status_path" ]; then
echo "status.pl 文件不存在,创建默认开启状态"
echo "True" > "$status_path"
fi
if [ -e "$status_path" ]; then
echo "status.pl 文件存在"
status=$(cat /www/server/panel/data/hids_data/status.pl)
if [ "$status" = "True" ]; then
isStart=$(ps aux |grep '/bt_hids/load_hids.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
echo -e "Starting BT-Panel-Hids ... \c"
btpython /www/server/panel/plugin/bt_hids/load_hids.py &
sleep 0.5
isStart=$(ps aux |grep '/bt_hids/load_hids.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
echo -e "\033[31mfailed\033[0m"
echo -e "\033[31mError: BT-Panel-Hids service startup failed.\033[0m"
return;
fi
echo $isStart > "/www/server/panel/data/hids_data/pid.pl"
echo -e " \033[32mdone\033[0m"
else
echo "Starting BT-Panel-Hids.. (pid $isStart) already running"
fi
else
echo "status_file is false"
fi
fi
}
service_stop()
{
echo -e "Stopping BT-Panel-Hids...\c";
pids=$(ps aux |grep '/bt_hids/load_hids.py'|grep -v grep|awk '{print $2}')
arr=($pids)
for p in ${arr[@]}
do
kill -9 $p
done
rmmod hids_driver
echo -e " \033[32mdone\033[0m"
}
service_status()
{
isStart=$(ps aux |grep '/bt_hids/load_hids.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" != '' ];then
echo -e "\033[32mBT-Panel-Hids (pid $(echo $isStart)) already running\033[0m"
else
echo -e "\033[31mBT-Panel-Hids not running\033[0m"
fi
# $target_dir/tools get_status
}
case "$1" in
'start')
server_start
;;
'stop')
service_stop
;;
'restart')
service_stop
sleep 1
server_start
;;
'status')
service_status
;;
'default')
# echo 选项为空
;;
esac