How to Pass Custom Arguments to Init.d Service Scripts in RHEL/CentOS 6


2 views

When working with traditional SysVinit services on RHEL 6 systems, the service command wrapper doesn't natively support passing additional arguments to the underlying init script. This becomes problematic when you need to:

  • Start services with debug flags
  • Pass configuration parameters
  • Enable special modes during startup

The most straightforward solution is to bypass the service wrapper and call the init script directly:

/etc/init.d/jboss-as start debug

For JBoss AS specifically, you might need to modify the init script to properly handle arguments:

case "$1" in
    start)
        if [ "$2" = "debug" ]; then
            JBOSS_OPTS="$JBOSS_OPTS --debug 8787"
        fi
        # Rest of start logic
        ;;
esac

Another clean method is using environment variables:

JBOSS_MODE=debug service jboss-as start

Then modify your init script to check the variable:

if [ "$JBOSS_MODE" = "debug" ]; then
    JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
fi

For frequent use, create a custom wrapper script:

#!/bin/bash
# /usr/local/bin/jboss-service

case "$1" in
    start-debug)
        /etc/init.d/jboss-as start debug
        ;;
    *)
        service jboss-as "$@"
        ;;
esac

While RHEL 6 uses SysVinit, it's worth noting how systemd handles arguments differently:

# For systems using systemd (RHEL 7+)
systemctl start jboss-as@debug.service

The traditional service command in RHEL/CentOS doesn't natively support passing arguments to init scripts. When you run:

service jboss-as start debug

The debug parameter gets ignored because the service wrapper only accepts the service name and basic commands (start/stop/restart).

Method 1: Modify the Init Script

Edit /etc/init.d/jboss-as to accept parameters:

case "$1" in
    start)
        if [ "$2" == "debug" ]; then
            /opt/jboss/bin/standalone.sh --debug
        else
            /opt/jboss/bin/standalone.sh
        fi
        ;;
    stop)
        # normal stop logic
        ;;
esac

Method 2: Use Direct Init Script Invocation

Bypass the service wrapper:

/etc/init.d/jboss-as start debug

Method 3: Environment Variables

Set variables in /etc/sysconfig/jboss-as:

JBOSS_OPTS="--debug"

Then reference in init script:

/opt/jboss/bin/standalone.sh $JBOSS_OPTS

For newer systems using systemd, create an override file:

systemctl edit jboss-as.service

[Service]
ExecStart=
ExecStart=/opt/jboss/bin/standalone.sh --debug
  • Document any custom parameters in script headers
  • Implement proper parameter validation
  • Consider creating separate service files for different modes
  • Test thoroughly in your environment