init script for a server

I have compiled and installed Trinitycore (for personal use) and I want it to start with the system as a service.

My /usr/local/etc/rc.d/worldserver files is:

Code:
#!/bin/sh
#
# $FreeBSD:  $
#
# PROVIDE: worldserver
# REQUIRE: SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf[.local] to enable worldserver
#
# worldserver_enable (bool):    Set to "NO" by default.
#                               Set it to "YES" to enable worldserver.
# worldserver_args (str):               Custom additional arguments to be passed
#                               to worldserver (default empty).
#

. /etc/rc.subr

name="worldserver"
rcvar=worldserver_enable

load_rc_config $name

: ${worldserver_enable="NO"}
: ${worldserver_pidfile="/var/run/worldserver.pid"}
: ${worldserver_lockfile="/var/spool/lock/worldserver.lock"}

pidfile="/var/run/worldserver.pid"
required_files="/usr/local/etc/worldserver.conf"
command="/usr/local/bin/screen -d -m -S worldserver /usr/local/bin/worldserver"

run_rc_command "$1"

and when I start it with the command [cmd=]service worldserver start[/cmd] I get:

Code:
/usr/local/etc/rc.d/worldserver: WARNING: no shebang line in /usr/local/bin/screen
[: /usr/local/bin/screen: unexpected operator
Starting worldserver.

What am I doing wrong?
 
Why are you starting it in a screen session? Clearly it's expecting a shell script. Why don't you wrap that screen command in a shell script and try that?
 
Turn on command echo (I think that's what it's called) and use script(1) to capture the output to a log file to see what is wrong:

# script /tmp/worldserver.log sh -x /usr/local/etc/rc.d/worldserver start
 
estrabd said:
Why are you starting it in a screen session? Clearly it's expecting a shell script. Why don't you wrap that screen command in a shell script and try that?

I start it in screen to access the server console and because it don't have daemon mode. I put the screen line in a .sh file, now it works ^_^
 
Great.

I don't know what your daemon is doing, and for debugging this seems okay. But keep in mind that in order to truly daemonize a process you have to do a couple of things. First, most daemons start by being created as a child in a parent process, then the child kills the parent. This allows the system to track it as a true daemon (I forget the default parent name). The second thing is that I would definitely not run screen or that child process as root - you need to use something like setuid(2). On second thought, also check out daemon(8). It might do both of these things for you. I don't know what to tell you regarding the debugging. Like I said, screen seems fair enough. Lastly, be careful what you're putting in /tmp. It could introduce security issues unless you take certain precautions. This all might be better posted to the group in a different thread for greater exposure.

Brett
 
Back
Top