Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

« Newer Snippets
Older Snippets »
4 total  XML / RSS feed 

tracd debian init script

tracd init script on debian stable. consists of two parts, /etc/init.d/tracd and /etc/default/tracd

This is /etc/init.d/tracd

#! /bin/sh
#
# tracd           Trac standalone server daemon
#
# Author: cocoaberry
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Trac standalone server"
NAME=tracd
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

# defaults for tracd
TRACD_PORT=8080
TRACD_BIND_ADDRESS=0.0.0.0
TRACD_EXTRA_OPTS=

# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
        . /etc/default/$NAME
fi

#
# Function that starts the daemon/service.
#
d_start() {
        start-stop-daemon --start --background --make-pidfile --quiet \
                --pidfile $PIDFILE --chuid $TRACD_USER \
                --exec $DAEMON -- $TRACD_EXTRA_OPTS --port $TRACD_PORT --hostname $TRACD_BIND_ADDRESS $TRACD_ENVIRONMENTS
}

#
# Function that stops the daemon/service.
#
d_stop() {
        start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
                --name $NAME
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
  restart|force-reload)
        #
        # If the "reload" option is implemented, move the "force-reload"
        # option to the "reload" entry above. If not, "force-reload" is
        # just the same as "restart".
        #
        echo -n "Restarting $DESC: $NAME"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0



This is /etc/default/tracd

# Default settings for tracd. This file is sourced by
# /etc/init.d/tracd

# MAJOR HACK - disable globbing so $TRACD_EXTRA_OPTS on cmdline won't expand
# the *
set -f
# The user that tracd runs as
TRACD_USER=tracd
# The environments that tracd manages. If more than one, separate
# with spaces
TRACD_ENVIRONMENTS=/home/tracd/trac-env
# Extra options to tracd
TRACD_EXTRA_OPTS="--auth *,/home/tracd/trac.htdigest,TracRealm"
# The port that tracd binds to. The default is 8080
# TRACD_PORT=8080
# The addresses that tracd binds to. The default is 0.0.0.0
# TRACD_BIND_ADDRESS=0.0.0.0

firebird auto increment trigger

This is a trigger to implement auto-increment/identity columns in Firebird. Another version is using a stored procedure to
get the value of the generator before inserting it then returning the saved generator value. This is needed because Firebird
generators are outside transaction control so reading the generator value again after using it may yield a different number
because it has already been used in a different transaction.

CREATE GENERATOR testgen;

SET TERM $$ ;
CREATE TRIGGER trg_gen_test FOR test_table
ACTIVE
BEFORE INSERT AS
BEGIN
  new.identity_column = gen_id(testgen, 1);
END $$
SET TERM ; $$


SET TERM $$ ;

CREATE PROCEDURE proc_insert ( val1 VARCHAR(20), val2 VARCHAR(20) ) RETURNS 
(generated_id INTEGER)
AS
BEGIN
  generated_id = gen_id(testgen, 1);
  INSERT INTO test_table (identity_column, col1, col2) VALUES (:generated_id, :val1, :val2);
  SUSPEND;
END $$

SET TERM ; $$

/* call the above procedure like this from code (PHP):
SELECT generated_id FROM proc_insert('a', 'b');
of course you can prepare and use placeholders/bind params for the proc parameters
*/

ASP/VBScript ADO parameterized query


use like:

Set rs = execute_query(conn, "SELECT custid, custname FROM customers WHERE (somefield > ?) AND (someotherfield < ?)", Array(someValue, someOtherValue));

where conn is a "ADODB.Connection"

Function create_variant_input_parameter(command, name, value)
  Dim param
  ' 12 -> adVariant
  ' 1 -> adParamInput
  Set param = command.CreateParameter(name, 12, 1, 0, value)  
  Set create_variant_input_parameter = param
End Function

Function execute_query(connection, querytext, parameters)
  Dim cmd, i, rs
  Set cmd = Server.CreateObject("ADODB.Command")
  cmd.CommandText = querytext
  ' 1 -> adCmdText
  cmd.CommandType = 1
  For i = 0 To UBound(parameters)
    cmd.Parameters.Append(create_variant_input_parameter(cmd, "", parameters(i)))    
  Next
  Set cmd.ActiveConnection = connection 
  Set rs = cmd.Execute()
  Set execute_query = rs
End Function

ASP/JScript ADO parameterized query

ASP/JScript ADO parameterized query.

use like:

var rs = executeQuery(conn, "SELECT custid, custname FROM customers WHERE somefield > ?", [someValue]);

where conn is a "ADODB.Connection"

Requires that you first include the "adojavas.inc" include file to get definitions for the adXXX constants.

function executeQuery(conn, qry, params) {
  if (arguments.length == 2) { params = []; }
  var cmd, i;
  cmd = Server.CreateObject("ADODB.Command");
  cmd.CommandText = qry;
  cmd.CommandType = adCmdText;
  for (i = 0; i < params.length; i++) {
    cmd.Parameters.Append(cmd.CreateParameter("", adVariant, adParamInput, 0, params[i]));
  }
  cmd.ActiveConnection = conn;
  return cmd.Execute();
}

« Newer Snippets
Older Snippets »
4 total  XML / RSS feed