Contents Index Running the server outside the current session Understanding Windows services

ASA Database Administration Guide
  Running the Database Server
    Running the server outside the current session

Running the UNIX database server as a daemon


To run the UNIX database server in the background, and to enable it to run independently of the current session, you run it as a daemon.

Do not use '&' to run the database server in the background 
If you use the UNIX & (ampersand) command to run the database server in the background, it will not work—the server will hang. You must instead run the database server as a daemon.

As well, attempting to start a server in the background from within a program using the typical fork()-exec() sequence will not work.

You can run the UNIX database server as a daemon in one of the following ways:

  1. Use the -ud option when starting the database server. For example:

    dbsrv9 -ud asademo
  2. Use the dbspawn tool to start the database server, for example:

    dbspawn dbsrv9 asademo

    One advantage of using dbspawn is that the dbspawn process does not terminate until it has confirmed that the daemon has started and is ready to accept requests. If for any reason the daemon fails to start, the exit code for dbspawn will be non-zero.

    When you start the daemon directly using the -ud option, the dbeng9 and dbsrv9 commands create the daemon process and return immediately (exiting and allowing the next command to be executed) before the daemon initializes itself or attempts to open any of the databases specified in the command.

    Using dbspawn can be useful when writing a script or other automated process that needs to start a server as a daemon prior to running one or more applications that will user the server because you want to ensure that the daemon is running before starting the applications. The following is an example of how to test this using a csh script.

    #!/bin/csh
    # start the server as a daemon and ensure that it is running before we start any applications
    dbspawn dbsrv9 asademo
    if ( $status != 0 ) then
       echo Failed to start asademo server
       exit
    endif
    # ok, now we can start the applications
    ...

    This example uses an sh script to test whether the daemon is running before starting the applications.

    #!/bin/sh
    # start the server as a daemon and ensure that it is running before we start any applications
    dbspawn dbsrv9 asademo
    if [ $? != 0 ]; then
       echo Failed to start asademo server
       exit
    fi
    # ok, now we can start the applications
    ...
  3. Spawn a daemon from within a C program, for example:

    ...
    if( fork() == 0 ) {
       /* child process = start server daemon */
       execl( "/opt/sybase/SYBSsa9/bin/dbsrv9", "dbsrv9", "-ud", "asademo" );
       exit(1);
    }
    /* parent process */
    ...

    Note that the -ud option is used.

For more information, see -ud server option and The Spawn utility.


Contents Index Running the server outside the current session Understanding Windows services