PS: 语言表达能力有点差,需要修改的多多建议
适用条件
- 
自己适用源码编译的 https://github.com/nknorg/nkn (里面有教程,看不到的话晚点我整理个详细的。)
 - 
Linux 环境
 - 
我的脚本中每次启动都会删除 Log 的日志文件。不需要自行删除
 - 
欢迎大牛改成一键式傻瓜脚本
 
准备
- 运行目录 
/root/.go/src/github.com/nknorg/nkn该目录不同人有所不同, 自行修改 - 自动更新脚本
 - 配合掉线自动运行脚本使用
 
使用说明
- 创建 /root/monitor-scripts/02-nkn-auto-update.sh
 - 创建 /root/monitor-scripts/99-monitor.sh
 - 添加 定时任务 crontab -e 这个不会的请自行搜索
 
* * * * * /root/monitor-scripts/99-monitor.sh &
*/5 * * * * /root/monitor-scripts/02-nkn-auto-update.sh &
自动更新脚本
#!/bin/bash
# */5 * * * * /root/monitor-scripts/02-nkn-auto-update.sh &
sleep 1
cd /root/.go/src/github.com/nknorg/nkn
LOCAL=$(git rev-parse HEAD)
# 获取远端库信息
#!/bin/bash
# */5 * * * * /root/monitor-scripts/02-nkn-auto-update.sh &
sleep 1
cd /root/.go/src/github.com/nknorg/nkn
LOCAL=$(git rev-parse HEAD)
# 获取远端库信息
git fetch
UPSTREAM=$(git rev-parse @{u})
if [ $LOCAL != $UPSTREAM ]
then
    export GOPATH=$HOME/.go
    export PATH=/root/go/bin:$GOPATH/bin:$PATH
    killall nknd
    pkill   nknd
    git pull origin master
    make deepclean
    make vendor
    make
    pid=`ps -ef | grep "nknd" | grep -v grep | awk '{print $2}'`
    if [ -n "$pid" ];
    then
        kill -9 $pid
        killall nknd
        pkill   nknd
    fi
fi
掉线自动运行脚本 (开机也会自启动)
#!/bin/bash
# *   * * * * /root/monitor-scripts/99-monitor.sh &
func_nkn_monitor()
{
    pid=`ps -ef | grep nknd | grep -v grep | awk '{print $2}'`
    if [ -z "$pid" ];
    then
        rm -rf /root/.go/src/github.com/nknorg/nkn/Log/*
        cd /root/.go/src/github.com/nknorg/nkn
        
        /usr/bin/nohup ./nknd -p 你的钱包密码 --no-check-port > /dev/null 2>&1 &
    fi
}
本人自行编译的脚本命令 (Ubuntu 18.04)
    cd /root
    apt-get update
    apt-get install -y wget git curl make g++ golang-glide
    wget https://storage.googleapis.com/golang/go1.10.2.linux-amd64.tar.gz
    tar zxf go1.10.2.linux-amd64.tar.gz
    export GOPATH=$HOME/.go
    export PATH=/root/go/bin:$GOPATH/bin:$PATH
    rm -rf /root/go1.10.2.linux-amd64.tar.gz
    source /root/.bashrc
    mkdir -p /root/.go/src/github.com/nknorg
    cd /root/.go/src/github.com/nknorg
    git clone https://github.com/nknorg/nkn.git
    cd nkn/
    make deepclean
    make vendor
    make
傻瓜式一步一步来
安装 一行代表一条执行命令
    cd /root
    apt-get update
    apt-get install -y wget git curl make g++ golang-glide
    wget https://storage.googleapis.com/golang/go1.10.2.linux-amd64.tar.gz
    tar zxf go1.10.2.linux-amd64.tar.gz
    export GOPATH=$HOME/.go
    export PATH=/root/go/bin:$GOPATH/bin:$PATH
    rm -rf /root/go1.10.2.linux-amd64.tar.gz
    source /root/.bashrc
    mkdir -p /root/.go/src/github.com/nknorg
    cd /root/.go/src/github.com/nknorg
    git clone https://github.com/nknorg/nkn.git
    cd nkn/
    make deepclean
    make vendor
    make
    mkdir Log
添加钱包文件
钱包文件的所有内容 放到 这个文件 里 `/root/.go/src/github.com/nknorg/nkn/wallet.dat`
设置 定时 任务
- 创建 /root/monitor-scripts/02-nkn-auto-update.sh
 - 创建 /root/monitor-scripts/99-monitor.sh
 - 运行 两个命令
 
chmod +x /root/monitor-scripts/02-nkn-auto-update.sh
chmod +x /root/monitor-scripts/99-monitor.sh
- 内容看上面的
运行crontab -e添加 2 行 
*   * * * * /root/monitor-scripts/99-monitor.sh &
*/5 * * * * /root/monitor-scripts/02-nkn-auto-update.sh &