• linux开机 自动挂载和启动jar包


    一、 自动挂载和启动jar包

    1、开机配置文件增加命令

    vi /etc/rc.local

    增加 sh  /home/startup.sh(需要启动的脚本)

    2、startup.sh

    #!/bin/sh
    # 获取当前脚本所在路径
    dir=$(cd `dirname $0`; pwd)
    jar_name="test.jar"
    conf_file="mount.conf"
    file_path=${dir}/${conf_file}
    log_file=${dir}/"startup.log";
    # 加载环境配置 source
    /etc/profile source ~/.bash_profile java_path=${JAVA_HOME} sudo echo -e " " runtime: `date '+%Y-%m-%d %H:%M:%S'` " " >> ${log_file} if [[ ! -f ${dir}/${conf_file} ]];then echo -e "33[31m ${dir}/${conf_file} does not exist! 33[0m" echo -e "${dir}/${conf_file} does not exist! " >> ${log_file} exit 1 fi # 挂载
    # sed 过滤'#'开头的;while read -a line 逐行读取, $line第一列, ${line[1]}第二列
    sed -e '/^#/d' ${file_path} | more | while read -a line || [ -n "$line" ]; do
    # -n 不为空,-a 且 if [ -n "$line" -a -n "${line[1]}" ]; then echo mount "$line ${line[1]}" >> ${log_file}; mount "$line" "${line[1]}"; fi done; # 启动jar cd ${dir}echo -e "33[36m now start jar... 33[0m" pid=$(pgrep -f ${msg_jar}) if [[ -n $pid ]];then kill -9 $pid fi
    # nohup 程序不挂起
    nohup ${java_path}/bin/java -jar ${dir}/${msg_jar} & sleep 10 pid=$(pgrep -f ${msg_jar}) if [[ -z $pid ]];then echo -e "33[31m start ${dir}/${msg_jar} occured error, please read ${jar_name} log.33[0m" echo -e "start ${dir}/${msg_jar} occured error, please read ${jar_name} log." >> ${log_file} exit 1 else echo -e "33[36m start ${dir}/${msg_jar} successful, pid is $pid .33[0m" echo -e "start ${dir}/${msg_jar} successful, pid is $pid ." >> ${log_file} fi

    二、sudo 执行命令,获取不到环境配置

    1、sudo visudo

    修改 Defaults env_reset 为 Defaults !env_reset,不让sudo重置环境变量

    2、sudo vi ~/.bashrc

    增加 alias sudo=sudo PATH=$PATH

    执行 source ~/.bashrc 生效

    3、sudo java -version或者 java -jar 就能通过sudo执行。

  • 相关阅读:
    最常见VC++编译错误信息集合
    网站运营最全总结
    KdPrint/DbgPrint and UNICODE_STRING/ANSI_STRING
    poj 2155 matrix
    【hdu2955】 Robberies 01背包
    【hdu4570】Multi-bit Trie 区间DP
    2014 SCAU_ACM 暑期集训
    qpython 读入数据问题: EOF error with input / raw_input
    【转】Python version 2.7 required, which was not found in the registry
    华农正方系统 登录地址
  • 原文地址:https://www.cnblogs.com/day1day1up/p/15387280.html
Copyright © 2020-2023  润新知