Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Database Administration » Running the Database Server » Running the server outside the current session

Running the server outside the current session Next Page

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 stop responding. 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:

    dbsrv10 -ud demo
  2. Use the dbspawn tool to start the database server. For example:

    dbspawn dbsrv10 demo

    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 dbeng10 and dbsrv10 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.

    If you want to ensure that a daemon is running one or more applications that will use the database server, you can use dbspawn 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 you start any applications
    dbspawn dbsrv10 demo
    if ( $status != 0 ) then
       echo Failed to start demo server
       exit
    endif
    # ok, now you 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 you start any applications
    dbspawn dbsrv10 demo
    if [ $? != 0 ]; then
       echo Failed to start demo server
       exit
    fi
    # ok, now you 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/sqlanywhere10/bin/dbsrv10",
    "dbsrv10", "-ud", "demo" );
       exit(1);
    }
    /* parent process */
    ...

    Note that the -ud option is used.

See also