18

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.

2
  • Stop, ubuntu doesn't use sysv, it uses upstart. Mar 20, 2013 at 5:20
  • 1
    Create another case in startup script. Example: start-debug and then you can run: /etc/init.d/jboss-as start-debug
    – Guntis
    Mar 24, 2013 at 16:14

4 Answers 4

10

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
        ;;
2
  • 1
    As for the exported environment vars, that appears not to be the case - service's man page says that TERM and LANG are the only ones which are passed to the script. But of course, one can always bypass service by running /etc/init.d/MyNiftyService start whatever1 whatever2... Mar 20, 2013 at 8:23
  • I will resort to Alien's bypass. Want to put it as an answer? Mar 24, 2013 at 5:34
6

In Ubuntu, startup parameters are typically found in:

/etc/default/<service_name>
1
  • 2
    Right but I don't want to change that every time I need a change... During development it's quite often. And I need RHEL 6. Edited the question. Mar 20, 2013 at 5:19
1

You can configure an EnvironmentFile in your service file:

[Service]
EnvironmentFile=/etc/sysconfig/my-service
ExecStart=my-service.sh ${ARG1} ${ARG2}

and create the /etc/sysconfig/my-service with the vars:

ARG1=first
ARG2=second
0

I would go with sourcing additional parameters from a system specific file after checking for its existence, as suggested above.

I do not like adding any additional options to the service startup.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .