大网数据广告活动
服务器运维问答

Linux: How to pass parameters to `service foo start` (at command line)?

· 52CE 我爱测

I'd like to pass an argument to the service I am starting. E.g. starting a server in a debug mode. Like, service jboss-as start debug Or such. But service seems not to support that. Is there some way? (For RHEL 6 if that matters.…

问题原文

原帖链接 · Ondra Žižka · CC BY-SA 3.0

I'd like to pass an argument to the service I am starting. E.g. starting a server in a debug mode. Like,

service jboss-as start debug

Or such. But service seems not to support that.

Is there some way? (For RHEL 6 if that matters.)

Note: This is similar to Ubuntu/Linux: how are startup parameters typically defined for startup scripts (sysvinit)? but not the same.

已采纳解答

原帖链接 · Laurentiu Roescu · CC BY-SA 3.0

In RHEL you have /etc/sysconfig folder. Here you define startup parameters. And in your startup script you include something like:

if [ -f /etc/sysconfig/$prog ] ; then
    . /etc/sysconfig/$prog
fi

Check existing services for examples.

For development you can put your startup parameters in an exported variable (for example in .bashrc) which you can manually override any time you wish.

EDIT

If you really want to use service there are some other options.

Your script should support at least start and stop. But you can also implement a debug command. And start your program with:

service foo debug

Another way will be to check for the second argument in your script and you start your program with:

service foo start debug

Modify your init script to something like:

case "$1" in
  start)
        if [ "$2" = "debug" ]
        then
                start_debug
        else
                start
        fi
        ;;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-03-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。