salt如何解决不能推送nohup执行启动命令问题

         

         最近由于需要研究下如何用salt推送filebeat安装和远程启动脚本,开始研究salt有些头大,但是经过两天的被虐大致了解如何编写简单的推送脚本也是一种收获。

下面红色的部分(nohup入restart.sh脚本里的内容)不能正常执行,经查找资料是因为公司的salt版本过低导致的,没办法就只能自己找了,后来突然想在另一台机器用rpm包安装下看看自带的启动脚本是什么样的,找台空机器安装后发现一个强大的功能。

cat restart.sh

ps -ef|grep filebeat|grep -v grep|awk '{print $2}'|xargs kill -9;

nohup ./filebeat -c benmu_product.yml >/dev/null 2>&1

 

cat install.sls 

/filebeat/restart.sh:
  file.managed:
    - user: root
    - mode: 755
    - source: salt://unix-filebeat/files/restart.sh

restart_filebeat:
  cmd.run:
    - name: cd /filebeat && sh restart.sh

 

salt bigdata1.com                     state.sls unix-filebeat

 

root  # cat files/filebeat.service 
[Unit]
Description=filebeat
Documentation=https://www.elastic.co/guide/en/beats/filebeat/current/index.html
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/filebeat/filebeat -c /filebeat/benmu_SIGN.yml -path.home /filebeat -path.config /filebeat -path.data /filebeat/data -path.logs /var/log/filebeat
Restart=always

[Install]
WantedBy=multi-user.target

-------------------------------------------------------------------

cat modify_new.sh

mv filebeat.service /lib/systemd/system/filebeat.service
systemctl daemon-reload

改后

 

/filebeat/filebeat.service:
  file.managed:
    - user: root
    - group: root
    - mode: 755
    - source: salt://unix-filebeat/files/filebeat.service


config_yml:
  cmd.run:
    - name: cd /filebeat/ && sh modify_new.sh
 

restart_filebeat:
  cmd.run:
    - name: systemctl restart filebeat.service 
 

 

这个非常牛掰,直接后续机器上执行systemctl restart filebeat.service 即可。

 

群号584912368

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值