# SCM Manager as service in rc.d - preventing system from boot.



## freebsd_dev (Sep 8, 2020)

*1. Case study*
Hi, I'm trying to create a service from SCM Manager ( https://www.scm-manager.org/ ). I would like to have this program always enabled whenever system boots up. The program is written in JAVA. I will handle port redirection by apache later (as it is listening on 8080 for now).

*2. Issue*
The program is working, I'm able to navigate to the home page of SCM Manager using web browser, but script is preventing system from boot and any other service won't start because the JAVA binary won't return the control unless the server would be killed by hitting CTRL+X or CTR+D I think. In this way I'm unable to SSH into server (SSHD is not started I suppose). I can fix this by physically plugging USB keyboard to the server and kill the program by key, but what next?

*3. Script code*


```
#!/bin/sh

# PROVIDE: scm_manager
# REQUIRE:
# KEYWORD:
#

. /etc/rc.subr

name=scm_manager
rcvar=scm_manager_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"

export JAVA_HOME=/usr/local/openjdk11
export JAVA_BIN=$JAVA_HOME/bin/java
export PID_FILE=/var/run/scm-manager.pid
export BASE_DIR=/storage/scm
export REPO_DIR=$BASE_DIR/lib
export SCM_HOME=/storage/scm/repositories\
export CLASS_PATH=$CLASSPATH_PREFIX:"$BASE_DIR"/conf:"$REPO_DIR"/*
export EXTRA_JVM_ARGUMENTS="-Djava.awt.headless=true -Dlogback.configurationFile=logging.xml"

scm_manager_start()
{
        $JAVA_BIN \
                $EXTRA_JVM_ARGUMENTS \
                -classpath "$CLASS_PATH" \
                -Dapp.name="scm-server" \
                -Dapp.pid=$PID_FILE \
                -Dapp.repo=$REPO_DIR \
                -Dbasedir=$BASE_DIR \
                sonia.scm.server.ScmServerDaemon \
                "$@"
}

scm_manager_stop()
{
        echo "Stopping SCM MANAGER is not implemented yet."
}

: ${scm_manager_enable="NO"}
                   
run_rc_command "$1"
```

EDIT:
I solved my problem by using "DAEMON" program ( https://www.freebsd.org/cgi/man.cgi?query=daemon&sektion=8 ) And it is working great now! What do you think guys, did I solved the problem in a "FreeBSD way"  ?


----------



## SKull (Sep 9, 2020)

You did. I haven't heard about that tool until now.

Of course, to gain real FreeBSD street cred, you'd have to run it in a jail. 
(which is super simple btw)


----------

