rv1109运行环境 - housekeeper-software/tech GitHub Wiki

/etc/profile,虽然有SIP/webrtc,但是我们使用相同的profile

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

if [ "$PS1" ]; then
	if [ "`id -u`" -eq 0 ]; then
		export PS1='[\u@\h:\w]# '
	else
		export PS1='[\u@\h:\w]$ '
	fi
fi

export PAGER='/bin/more '
export EDITOR='/bin/vi'

# Source configuration files from /etc/profile.d
for i in /etc/profile.d/*.sh ; do
	if [ -r "$i" ]; then
		. $i
	fi
	unset 
done

export LOGNAME=root
export QT_QPA_FB_DRM=1
export QT_QPA_PLATFORM=linuxfb:rotation=0
export RKMEDIA_LOG_LEVEL=ERROR
export LD_LIBRARY_PATH=/outdoor/app:$LD_LIBRARY_PATH
export PATH=/usr/local/node/bin:/usr/local/python/bin:$PATH
python /usr/local/python/bin/python2.7-config --prefix /usr/local/python
python /usr/local/python/bin/python2.7-config --libs /usr/local/python/lib/
export LOCAL_CMD_CONFIG=/root
export HASPUSER_PREFIX=/oem/auth

自启脚本 /etc/init.d/S99_webrtc,webrtc/sip公用

#!/bin/bash

LOGFILE="/tmp/webrtc.log"

echo "Script executed on $(date)" >> $LOGFILE

export LOGNAME=root
export QT_QPA_FB_DRM=1
export QT_QPA_PLATFORM=linuxfb:rotation=0
export RKMEDIA_LOG_LEVEL=ERROR
		
export PATH=/usr/local/node/bin:/usr/local/python/bin:$PATH
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/outdoor/app
export HASPUSER_PREFIX=/oem/auth
python /usr/local/python/bin/python2.7-config --prefix /usr/local/python
python /usr/local/python/bin/python2.7-config --libs /usr/local/python/lib/

case "$1" in
    start)
        echo "Starting webrtc service..." >> $LOGFILE
		if [ -f "/data/jingxi/shadow/startup.py" ];then
			echo "run app from python!" >> $LOGFILE
			cd /data/jingxi/shadow
			chmod +x startup.py
			python /data/jingxi/shadow/startup.py &
		else
			echo "run app direct!" >> $LOGFILE
			chmod +x /outdoor/app/res/daemon.py
			python /outdoor/app/res/daemon.py 100 /outdoor/app/outdoorapp /outdoor/app &
		fi
		;;
    stop)
        echo "Stopping webrtc service..." >> $LOGFILE
        ps -ef |grep daemon.py |awk '{print $2}'|xargs kill -9
		ps -ef |grep startup.py |awk '{print $2}'|xargs kill -9
		ps -ef |grep outdoorapp |awk '{print $2}'|xargs kill -9
        ;;
    *)
        echo "Usage: $0 {start|stop}" >> $LOGFILE
        exit 1
        ;;
esac

exit 0

daemon.py,此脚本实现启动指定app,并且监控其运行,一旦退出则自动重启app,此脚本位于 /outdoor/app/res/daemon.py

#!/usr/local/python/bin/python
# -*- coding: UTF-8 -*-
from __future__ import with_statement
from datetime import datetime
from struct import *
import subprocess
import os
import sys
import logging
import time

LogFile = '/tmp/daemon.log'
Log_Format = "%(levelname)s %(asctime)s - %(message)s"


def is_number(s):
    try:
        int(s)
        return True
    except ValueError:
        pass
    return False


def run(cmd, startup_dir, params):
    parameters = [cmd] + params
    process = subprocess.Popen(parameters, shell=False,cwd=startup_dir)
    code = process.wait()
    return code


def main(argv):
    num_args = len(argv)
    if num_args < 3:
        logging.error("cmdline parameters not enough,[exitcode,app,app startup path,app parameters...]")
        exit(1)
    if not is_number(argv[0]):
        logging.error("first parameter must be number,like -1,0,100")
        exit(1)
    exit_code = int(argv[0])
    while True:
        code = run(argv[1], argv[2], argv[3:])
        logging.info("{} exit code[{}]".format(argv[1], code))
        if exit_code > 0:
            if code == exit_code:
                break
        time.sleep(2)


if __name__ == '__main__':
    logging.basicConfig(filename=LogFile, format=Log_Format, level=logging.INFO)
    logging.info("argv{}".format(sys.argv[1:]))
    main(sys.argv[1:])

别墅门口机SIP版

nodejs 自启动脚本 /etc/init.d/S99_node

#!/bin/bash

export PATH=/usr/local/node/bin:/usr/local/python/bin:$PATH
python /usr/local/python/bin/python2.7-config --prefix /usr/local/python
python /usr/local/python/bin/python2.7-config --libs /usr/local/python/lib/ 

case "$1" in
    start)
        echo "Starting node service..." >> $LOGFILE		
        chmod +x /outdoor/app/res/daemon.py
        python /outdoor/app/res/daemon.py -1 node /outdoor/app/www app.js &
		;;
    stop)
        echo "Stopping node service..." >> $LOGFILE
        ps -ef |grep daemon.py |awk '{print $2}'|xargs kill -9
	ps -ef |grep node |awk '{print $2}'|xargs kill -9
        ;;
    *)
        echo "Usage: $0 {start|stop}" >> $LOGFILE
        exit 1
        ;;
esac

exit 0


daemon命令行解析

一般,通过daemon运行某个app,则如下:
python /outdoor/app/res/daemon.py [退出码] [可执行文件] [启动路径] [命令参数]
退出码:当进程退出码与此相同,则表示系统即将重启,daemon.py也不再重启之,设置为-1,表示一直守护并自动重启app
可执行文件,比如 : /outdoor/app/outdoorapp, node
启动路径: 执行文件需要在特定目录下运行,需要指定,比如 /outdoor/app, /outdoor/app/www
命令行参数:可以为空,或者 app.js