A server typically runs as persistent process or is started on demand when a client makes a remote procedure call to it. Management applications can start remote servers by using the dced_server_start( ) routine. This is a srvrconf routine that takes as input server configuration data in the form of an attribute list.
Once a server has started, it tends to remain running until an administrator or management application stops it, but some applications may stop themselves if, for example, they do not detect activity within a specified time. To stop remote servers, applications can use the dced_server_stop( ) routine.
The following example shows how an application starts or stops a server:
dced_binding_handle_t dced_bh, conf_bh, exec_bh;
server_t conf, exec;
dced_string_t server_name;
uuid_t srvrconf_id, srvrexec_id;
error_status_t status;
.
.
.
/* Toggle the Starting or Stopping of a Server */
dced_binding_create("srvrconf@hosts/somehost",
dced_c_binding_syntax_default,
&conf_bh,
&status);
dced_binding_create("srvrexec@hosts/somehost",
dced_c_binding_syntax_default,
&exec_bh,
&status);
dced_inq_id(exec_bh, server_name, &srvrexec_id, &status);
if(status != error_status_ok) {
puts("Server is NOT running.");
dced_inq_id(conf_bh, server_name, &srvrconf_id, &status);
dced_server_start(conf_bh, &srvrconf_id, NULL, &srvrexec_id, &status);
}
else {
puts("Server is RUNNING.");
dced_server_stop(exec_bh, &srvrexec_id, srvrexec_stop_rpc, &status);
}
dced_binding_free(conf_bh, &status);
dced_binding_free(exec_bh, &status);
dced_binding_create( )
These routines create dced bindings to the srvrconf and srvrexec portions of the server management service on a specified host.
The binding handles created are used in all subsequent calls to appropriate dced API routines.
dced_inq_id( )
This routine returns the UUID that dced associates with the name input. Each name used to identify an object of each service has a UUID. If
dced maintains a UUID for a srvrexec object, the server is running. However, it is possible that the server is in an in-between state as it is starting up or shutting down. For a
more robust check as to whether the server is running, use the dced_object_read( ) routine to read the server_t structure for the srvrexec object. If the
exec_data.tagged_union.running_data.instance UUID is the same as the srvrconf UUID (srvrconf_id), the server is running.
dced_server_start( )
This routine starts the server via dced. The srvrconf binding handle and UUID are input. For special server configurations, you can
start a server with a specific list of attributes, but a value of NULL in the third parameter uses the attributes of the server configuration data. You can input a srvrexec UUID for
dced to use, or allow it to generate one for you.
dced_server_stop( )
This routine stops a running server identified by its srvrexec UUID. The cleanest stop method is to cause dced to use the
rpc_mgmt_server_stop_listening( ) routine so that all outstanding remote procedure calls complete before the server stops.
dced_binding_free( )
Each call to the dced_binding_create( ) routine requires a corresponding call to dced_binding_free( ) to release the binding resources
allocated.