构建 SysV 或 Upstart 兼容的 Bash 脚本的注意事项
我刚刚敲出了一个快速脚本,用于使用 rsync 使从属 Web 服务器与主服务器保持同步。 (https://github.com/simonjgreen/liveFolderSync/blob/master/liveFolderSync.sh)
我想让它在启动时运行,并可以通过通常的 /etc/init.d/... 或服务命令进行控制,然而这是我一直陷入的一个领域。我发现 init.d 脚本和 upstart 脚本都非常混乱,并且无法在任何地方找到从头开始的指南。
我想要对其进行的唯一控制是启动/停止/重新启动。显然稍后我会将配置移至 /etc 中的单独文件中,但这已经在卡片上,因此超出了这个问题的范围。
任何指示/建议和最佳实践都会有所帮助。我应该补充一点,我是在 Ubuntu 上执行此操作的。
I've just knocked out a quick script for keeping a slave web server in sync with a master using rsync. (https://github.com/simonjgreen/liveFolderSync/blob/master/liveFolderSync.sh)
I'd like to make this run on boot and be controllable via the usual /etc/init.d/... or service commands, however this is an area I've always fallen down in. I find both init.d scripts and upstart scripts horrendously confusing, and can't find a guide anywhere for starting from scratch.
The only control I'd like to have over it is start/stop/restart. Obviously later I will move the config into a separate file in /etc but that's already on the cards so outside the scope of this question.
Any pointers/advise and best practices would be helpful. I should add that I'm doing this on Ubuntu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要开始使用 Sys V 初始化脚本,我建议使用以下链接:
对于特定于 Upstart 的说明,我建议从以下内容开始:
目前,还有129 个问题 AskUbuntu,其中有几个将为您指明正确的方向:
To get started with Sys V init scripts, I suggest the following links:
For instructions specific to Upstart, I would recommend starting with:
At present, there are also 129 questions on AskUbuntu, several of which will point you in the right direction: