Ubuntu – init.d script is not executed

bashinit.dsh

I have an /etc/init.d script that starts my webserver.
I made it executable and added it (update-rc.d webserver defaults).
When I execute the script from the command line it works fine (./webserver).

But after rebooting my system my webserver is not running.

#!/bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

cd ~/projects/webserver
./.build/debug/webserver &
exit 0

Is the user directory a problem (I am logged in as root)?

Best Answer

The type of tilde expansion you want is performed in reference to the current user of the shell. For example, when you log in as root ~ is /root. If the script runs before you log in, then ~ cannot be expanded to the directory you want.

Use the full path to the file in your script.

For future reference, here are some useful examples of using tilde expansion in scripts

Related Question