简体   繁体   English

服务启动和停止脚本 [暂停]

[英]Services start and stop script [on hold]

Can someone help me with the Bash script for starting and stopping services.有人可以帮助我使用 Bash 脚本来启动和停止服务。

The requirement is if there are 4 servers: Server 1, Server 2, Server 3, Server 4, we need to start and stop the services in a sequential order.要求是如果有 4 台服务器:服务器 1、服务器 2、服务器 3、服务器 4,我们需要按顺序启动和停止服务。

Suppose if we do some patch updates and shutdown the servers the all the services on Server 4 should go down and then 3 then 2 then 1. On reboot, it should be vice versa ie Services on Server 1, then 2 then 3 and finally 4.假设如果我们进行一些补丁更新并关闭服务器,服务器 4 上的所有服务应该 go 关闭,然后 3 然后 2 然后 1。重新启动时,反之亦然,即服务器 1 上的服务,然后是 2,然后是 3,最后是 4 .

Please suggest how this can be automated.请建议如何实现自动化。

I am very new to Scripting, Can someone help me with this.我对脚本很陌生,有人可以帮我解决这个问题。

EDIT: This community is horrible, getting "-2" for telling this person what would be needed?编辑:这个社区太可怕了,告诉这个人需要什么得到“-2”? They clearly state they are new, and it clearly marked my profile as "NEW CONTRIBUTOR".他们显然是 state 他们是新的,并且清楚地将我的个人资料标记为“新贡献者”。 I attempt to help this person know what they have to give additionally, plus a basic outline.我试图帮助这个人知道他们必须额外提供什么,以及一个基本的大纲。

There has been talk about how unwelcoming this community is and even a blog post about it.人们一直在谈论这个社区是多么不受欢迎,甚至还有一篇关于它的博客文章。 https://stackoverflow.blog/2018/04/26/stack-overflow-isnt-very-welcoming-its-time-for-that-to-change/ and after reading it I thought "well cool they have brought it up and are working on it." https://stackoverflow.blog/2018/04/26/stack-overflow-isnt-very-welcoming-its-time-for-that-to-change/读完后我觉得“很酷,他们提出来了并且正在努力。” guess not.可能不会。

You are ridiculous, I will be deleting my account following this edit.你太荒谬了,我将在此编辑后删除我的帐户。

yep是的

Original:原来的:

So some additional information will be needed here.所以这里需要一些额外的信息。 It is not really possible to do much with what is present other than general idea flow, which I encluded at the end.除了我最后总结的一般想法流之外,实际上不可能对现有的东西做太多事情。

Needed:需要:

  • What flavor of Linux are you using?你用的是什么口味的 Linux? Matters as there is more than one option to start/stop services proper.很重要,因为有多个选项可以正确启动/停止服务。
  • What application/applications?什么应用程序/应用程序? Is this a public one, custom one, special stop procedures?这是公共的、定制的、特殊的停止程序吗?
  • You can't stop all services, as ssh/sshd is one of them.您不能停止所有服务,因为 ssh/sshd 就是其中之一。
  • Why is reboot needed or were you just using that as a services up wording?为什么需要重新启动,或者您只是将其用作服务升级的措辞?

Basic flow:基本流程:

Down:下:

Initialize an array of variables for all the services per machine.
ssh machine 4, run down commands, verify down, send back ok for variables.
logic verify machine 4 down success.
ssh machine 3, repeat down procedure 
.... (Repeat as needed)
logic verify all machines down.
announce clear.

Upgrade your software.升级您的软件。

Up:向上:

Initialize an array of variables for all the services per machine.
ssh machine 1, run up commands, verify up, send back ok for variables.
logic to verify machine 1 up.
... (Repeat as needed)
logic verify all up
announce all clear.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM