在 CentOS 7 上启动 ruby 应用程序作为服务

Start ruby app as service on CentOS 7

我有一个 ruby 脚本(实际上是来自 Oxidized project 的示例脚本),它是用 Ruby 编写的并打开一个 UDP 端口 (514) 侦听系统日志消息和在后台执行一些代码。

Cent运行 上的系统 OS 7. 我想在 OS 启动时自动将此脚本作为 "service" 启动。然而,该脚本需要 运行 作为特定用户(氧化)并且应该可以使用正常的 "service ... [start|stop|status|...|" 行为进行控制。实现此目标的最佳方法是什么?

启动服务可以由 2 个不同的启动系统管理。

CentOS6 使用 System V(旧引导系统)

CentOS7 使用 Systemd(新引导系统)(Systemd 确实支持 System V 脚本。)

这是一个link"How to write startup script for systemd" https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd

这里是link"How to write a System V init script to start, stop, and restart my own application or service" https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html