# Configuring CasJobs

## General Architecture

There are 3 parts to CasJobs these may be on different machines:

- The BatchAdmin Database - need to check several tables
- The WebSite - need to check web.config
- The JobsService - need to check the config , install and start the windows service

## BatchAdmin

CasJobs centers around the Admin Database. This may be put on any machine. The website and Service config files contain connection strings for this database.

### Attaching BatchAdmin

Attach the BatchAdminDb with owner SA
If you do not have a batch login you need to create one.
To connect the batch login to the batch user in the BatchAdmin run the following command

    use BatchAdmin
    EXEC sp_change_users_login 'Update_One', 'batch','batch'

This systen also needs a test login and test needs acces to batch admin account as a reader.

### Users

Every user has a row in the users table with all details. The Privielges column contians the users priveleges as a comma separated list of Strings. For admin users add admin to this list.
The table also contains the location of the MYDB. If you move MYDBs this will need to be modified.

### Servers

The Servers Table contains the queues which appear on the website. To add a new Queue or server simply add a row to the table. If a string is entered in the privs colum then only users with that privilege may see the queue. Currently this is how to allow Collab see certain queues - i.e. put the word collab in the privs for the queue

If you add a priv to a server the special user ADMIN needs to also be given this priv.

You also need to create linked_servers between the mydb machine and any servers added to the table. Do this using sp_addlinkedserver or use the Enterprise manager.

## WebSite

Check CasJobs from the fermilab cvs. This is the website. Set it up in IIS by making a virtual directory to point at your checkout. You should checkout a particular version if you are not developing hence something like

     cvs -d cvsuser@sdss.fnal.gov:/cvs/sdss co CasJobs -r v1_6_5

Edit web.config to put in the appropriate connection string for the batchadmin database and the smtp mailer.

## JobsService

Also in the CasJobs checkout you will find a JobsService diretory.

The JobsService is a windows service which manages the batch queues. Jobs are submitted via the website and writtien in the jobs table of batchadmin. This process scans the table and executes jobs.

to install this open a dos prompt and cd to JobsService\bin\Release there type :

    InstallUtil JobsService.exe

This will prompt you for a username and password - you need admin privs to install a service.
On win2003 machines you need to specify the name as user@fermi.win.fnal.gov or the appropriate domain. On other systems the usual SDSS/user works.

### Modify config

The Config for the service is the file JobsService.exe.config - modify this to put the connection string for batachadmin database in it.

### Start it up

Once installed this is a windows Service you will see it under services as 'CasJobs Jobs Service'. In the Service manager you should set this to Automatic and start it.

If you are upgrading you need to stop the service or you can not replace the file.

# Moving mydbs

This is a little messy but there is a script to help -> movemydbs.sql