创建Prometheus Service 命令启动脚本

前言

ubuntu 14.04的系统,因为是内网环境,特殊需求不允许连接外网,无法安装systemd相关命令,只能用service命令做启动。

• Prometheus 启动脚本

## sudo vim /etc/init.d/prometheus

代码如下(示例):

#!/bin/bash
### BEGIN INIT INFO
# Provides:          prometheus
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts prometheus
# Description:       starts the prometheus Process Manager daemon
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
prefix=/opt/prometheus/prometheus_2.36 # 安装的prometheus路径
exec_prefix=${prefix}
prometheus_BIN=${exec_prefix}/prometheus
prometheus_LOG=${exec_prefix}/prometheus.log
PID=$(ps -aux | grep "prometheus.yml" | grep -v grep | awk -F " " '{print $2}')

case "$1" in
    start)
        if [ -z "$PID" ]
        then
            # 原手动启动命令
            /usr/bin/nohup $prometheus_BIN --config.file="${exec_prefix}/prometheus.yml" --web.listen-address="0.0.0.0:9090" --storage.tsdb.path="/opt/prometheus/prometheus_2.36/data" --storage.tsdb.retention=365d --web.enable-lifecycle > $prometheus_LOG 2>&1 &
        else
            echo -e "prometheus is running Pid:$PID \n"
            exit 0
        fi
        echo -e "Starting prometheus $PID \n"
    ;;
    stop)
        if [ -z "$PID" ]
        then
            echo "not found prometheus: $PID"
        else
            kill -9 $PID
            echo "stop prometheus.service"
        fi
    ;;
    reload)
        if [ -z "$PID" ]
        then
           echo "not found prometheus: $PID"
        else
            kill -1 $PID
           echo "reload prometheus:$PID"
        fi
    ;;
    status)
        if [ -z "$PID" ]
        then
            echo "prometheus is stopped"
        else
            echo "prometheus is running"
        fi
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    *)
        echo "Usage: $0 {start|stop|reload|status|restart}"
        exit 1
    ;;
esac

• 赋执行权限

sudo chmod +x /etc/init.d/prometheus

• 验证结果

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值