zoukankan      html  css  js  c++  java
  • linux上应用随机启动

    这是个go项目,其他的可以参考。

    首先要有个脚本比如demo

    #!/bin/bash
    #
    # etcd This shell script takes care of starting and stopping Etcd
    #
    # chkconfig: 2345 80 20
    #
    ### BEGIN INIT INFO
    # Provides: etcd
    # Required-Start: $network $syslog
    # Required-Stop: $network $syslog
    # Default-Start:
    # Default-Stop:
    # Short-Description: start and stop etcd
    ### END INIT INFO
     
    ## Source function library.
    #. /etc/rc.d/init.d/functions
    export JAVA_HOME=/usr
    export PATH=$JAVA_HOME/bin:$PATH
    GOPATH=/opt/etcdrepo/etcd
    ETCD_HOME=$GOPATH
    
    etcd_pid() {
        echo `ps aux | grep "etcd>" | grep -v grep | awk '{ print $2 }' | tail -n 1`
       }
     
    start(){
        pid=$(etcd_pid)
        if [ -n "$pid" ]
        then
             echo "Etcd is already running (pid: $pid)"
        else
             #Start etcd
             echo "Starting etcd"
             ulimit -n 100000
             umask 007
             sudo $ETCD_HOME/bin/etcd -data-dir machines/machine1 -name machine1 & > log.txt
        fi
        return 0
    }
     
    stop(){
        pid=$(etcd_pid)
        if [ -n "$pid" ]
        then
            echo -n -e "
    killing processes which didn't stop after $SHUTDOWN_WAIT seconds"
            kill -9 $pid
        else
            echo "Etcd is not running"
        fi
        return 0
    }
     
    case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        pid=$(etcd_pid)
        if [ -n "$pid" ]
        then
            echo "Etcd is running with pid: $pid"
        else
            echo "Etcd is not running"
        fi
        ;;
    esac
    exit 0

    2. 将这个脚本放入 /etc/init.d下或者 /etc/rc.d/init.d下

    3. 设置权限

       

    sudo chmod 777 demo
    sudo chkconfig --add demo
    sudo chkconfig --list demo
    sudo service demo start  找不到服务的时候  可以用 sudo /sbin/service demo start 
    

     4. reboot linux试下吧!

  • 相关阅读:
    使用python-gitlab包在gitlab上自动创建分组
    navicat连接远程mysql失败
    Python shell介绍
    Python任务流taskflow
    Python导包问题
    demo27-数组去重
    demo26-通过循环输出数据到页面显示
    demo25-for循环
    Visual Studio 2005 快捷键汇总
    三维立体图片效果
  • 原文地址:https://www.cnblogs.com/ilawrence/p/3945588.html
Copyright © 2011-2022 走看看