# Problem writing init script for server

## cvance090685

I have installed a srcds dedicated server for left4dead2 and I wanted to write an init script to get it to start nicely. Valve provided their own startup script, and I checked the final code executed and it was:

```
./srcds_linux +ip 10.0.2.1 -game left4dead2 +map c1m1_hotel
```

I created the following init script to attempt to emulate that command:

```
#!/sbin/runscript

depend() {

   need net

}

start() {

   ebegin "Starting Left 4 Dead 2 server"

   echo $L4D2_OPTS

   start-stop-daemon --start --chroot /opt/halflife/servers/left4dead2/ --chuid games:games --exec srcds_linux \

      -- ${L4D2_OPTS}

   pwd

   eend $?

}

#stop() {

#   ebegin "Stopping Left 4 Dead 2 server"

#   start-stop-daemon --stop --exec /opt/halflife/servers/left4dead2/srcds_linux \

#      --pidfile /var/run/left4dead2.pid

#   eend $?

#}   

```

$L4D2_OPTS is set in /etc/conf.d/left4dead2 and is +ip 10.0.2.1 -game left4dead2 +map c1m1_hotel

The binary scrds_linux is located at /opt/halflife/servers/left4dead2 and it paths that it uses for library files are relative paths, which is why I used the --chroot option, but the output of /etc/init.d/left4dead2 start is:

```

* Starting Left 4 Dead 2 server ...

+ip 10.0.2.1 -game left4dead2

/sbin/start-stop-daemon: Unable to start srcds_linux: No such file or directory (No such file or directory)

/etc/init.d                                                               [ ok ]

```

I don't understand why it cannot find the binary, can anyone help me out?

----------

## erik258

well, you're starting in a chroot.  IT might be that it can't start srcds_linux, but it might also be that it can't access some other file.  srcds_linux might be linked against something that isn't in the chroot (you could find out with ldd srcds_linux).  Another possibility - the most likely from my current perspective -s that /var/run/left4dead2.pid  can't be created because there is no var/run in the chroot location.

In short, try removing --chroot, and if it works, you know you have to add something to your chroot directory, /opt/halflife/servers/left4dead2/.

----------

## cvance090685

Thanks for the attention, when I removed the chroot option while writing the script, the current working directory is /etc/init.d and the srcds_linux binary is trying to locate files based on a relative path, so for example it looks for /opt/halflife/servers/left4dead2/foo/bar but when I run it without the chroot it looks for /etc/init.d/foo/bar which obviously doesn't exist. Is there a way to change the working directory with start-stop-daemon so that the relative paths work properly?

----------

## erik258

http://linuxreviews.org/man/start-stop-daemon/

perhaps chdir rather than chroot ?

----------

