gpt4 book ai didi

How to write a working rc.d script for OpenBSD to launch a ruby program that lives in /sbin/?(如何为OpenBSD编写一个有效的rc.d脚本来启动一个位于/sbin/中的ruby程序?)

转载 作者:bug小助手 更新时间:2023-10-22 13:15:34 33 4
gpt4 key购买 nike



This is everything that I've done:

I wrote the rc.d/ script, it looks like this:

这就是我所做的一切:我写了rc.d/脚本,它看起来是这样的:


#!/bin/ksh

daemon="/usr/local/sbin/dynaruby"
name="dynaruby"

. /etc/rc.d/rc.subr

rc_cmd $1

The program needs an environment variable to work. I tried setting it up following the man page of rc.d. It says to create an entry in login.conf, so I did, and that looks like this:

程序需要一个环境变量才能工作。我试着按照rc.d的手册页设置它。它说要在login.conf中创建一个条目,我照做了,看起来是这样的:


dynaruby:\
:setenv=DYNARUBY_KEY="BupCxeBEflVyNK05ypuz25bXuoRc9Rg61qKnOBohyH0=,Xwsirr99KDqkz3Ncytn2AA==":\
:tc=default:

I also did cap_mkdb /etc/login.conf for good measure, but still when I do rcctl reload/start dynaruby I always get dynaruby(failed). I tried having a file entry in /etc/login.conf.d/ without :tc=default: (tried both :tc=daemon: and nothing at all) instead of having it inside the main login.conf but with the same results. Any insight on how I could debug this further would be greatly appreciated.

我也做了cap_mkdb/etc/login.conf,但当我做rcctl-reload/start dynaruby时,我总是得到dynaruby(失败)。我尝试在/etc/login.conf.d/中设置一个文件条目,但没有:tc=default:(同时尝试了:tc=daemon:但什么都没有),而不是在主login.conf中设置,但结果相同。如果我对如何进一步调试这一点有任何见解,我们将不胜感激。


EDIT: I forgot to say that I also added the service in /etc/rc.conf.local

编辑:我忘了说我还在/etc/rc.conf.local中添加了服务


更多回答
优秀答案推荐

I've managed to force the env variable into the script by overriding the default rc_start

通过重写默认的rc_start,我已经成功地将env变量强制到脚本中


#!/bin/ksh

daemon="/usr/local/sbin/dynaruby"

. /etc/rc.d/rc.subr

rc_start() {
export DYNARUBY_KEY="YOUR,KEY"
exec /usr/local/sbin/dynaruby &
}
rc_cmd $1

This is not the intended way to do this, but I guess it works. Without exec the program will run fine until the rc.d framework kills it with error Timeout: No process found. This might be fixed by overriding the pexp too, but I found just using exec / & to be the easiest.

这不是预定的方法,但我想它是有效的。如果没有exec,程序将运行良好,直到rc.d框架用错误Timeout:No process将其杀死。这可能也可以通过重写pexp来解决,但我发现使用exec/是最简单的。


更多回答

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com