Main ✸ Source Code ✸ Downloads ✸ API Documentation ✸ Mailing Lists ✸ Bugs ✸ Developers
You'll find an example initscript for Naviserver in the contrib directory (contrib/start-scripts/naviserver.SuSE). So far it was tested on SuSE Linux 10.1.
Place it into the /etc/init.d directory. You have to modify only a few variables.
To activate it, use insserv (-v gives you verbose information, see also the man page):
server:/etc/init.d # insserv -v naviserver
The following options are available:
server:/etc/init.d # ./naviserver .
Usage: ./naviserver <command>
.
where <command> is one of start - start nsd stop - stop nsd restart - stop nsd if running; start nsd try-restart - restart a running server only realstop - stop nsd and create a lockfile version - show version and release information probe - figure out if config changed since last start status - check whether nsd is running
server:/etc/init.d # ./naviserver start Starting Naviserver daemon done
There is no danger in using start again:
Naviserver daemon is already running (/usr/local/ns/logs/nsd.pid) done
server:/etc/init.d # ./naviserver stop Shutting down Naviserver daemon (Success or program was not running) done
Same as stop but it also creates a lockfile in the /var/lock directory. The idea behind is that if you use an external mechanism to ensure the running of your service (e.g. a simple cron job that checks every n minutes) there are situations (e.g. maintenance) where you don't want the server to be restarted automatically. The external mechanism would only start the server if it is not running and no lockfile is found. When using start or restart manually, the lockfile is deleted.
Using restart will stop an already running server, wait a specified period of seconds (SLEEPTIME) and then start the server. SLEEPTIME is available so that a running server and your application code has enough time to close all tasks. Otherwise, if the restart is to fast it might happen that the server runs into the 'address already in use' trap.
server:/etc/init.d # ./naviserver restart Shutting down Naviserver daemon (Success or program was not running) done Starting Naviserver daemon done
This one restarts only an already running server.
Prints out version and release information. When a server is running shows also the commandline used to start the server.
server:/etc/init.d # ./naviserver version . Naviserver daemon started with: /usr/local/ns/bin/nsd -i -t /etc/naviserver/nsd.conf -u nsadmin -g nswww . NaviServer/4.99.2
Echos reload when a change of the config file(s) is newer than the date and time of the server pidfile (or when the server is not running). For that to work it simply looks for all files with a '.conf' extension in the directory of the (main) configfile.
Is the server running? Yes:
server:/etc/init.d # ./naviserver status Checking for naviserver daemon nsd: done
...and no:
server:/etc/init.d # ./naviserver status Checking for naviserver daemon nsd: failed
You should only have to make a few modifications to the script. It has to know the user and group the server will run under, the location of the configuration and pidfile and the server binary. Things that could be parsed out of the configfile, BTW...
# Decision about starting normal or in a chroot cage # Default: no # # Note: You have to set up a specific chroot environment # before setting this to 'yes' will result in any success. # NS_CHROOT=no # # Decision about using the built-in watchdog that automatically restarts # the server if it crashes. # Default: no # NS_WATCHDOG=no NS_USER=nsadmin NS_GROUP=nswww NS_CONFIG=/etc/naviserver/nsd.conf NS_MESSAGES=/var/log/rc${nsd_ident}.out NS_BINARY=/usr/local/ns/bin/nsd NS_HOME=/usr/local/ns/ NS_PIDFILE=/usr/local/ns/logs/nsd.pid