4. Automatic Startup Techniques

The Batch Manager should be left to run continuously—like a service. However, the Batch Manager is not a service. It is a graphical application—and so you will need to employ various techniques to ensure the Batch Manager keeps running continuously. In other words, if the computer the Batch Manager is running on goes down, the Batch Manager must also be restarted when the computer is brought back up again.

In this section we explore some of the techniques you might use to avoid having to restart the Batch Manager manually whenever the compute

r it is running on is restarted. Please do not consider the suggestions offered here as complete solutions. Certain issues, such as security, are not taken into account.

Tip

In the previous section we learned how to pass arguments to the Batch Manager client at runtime. These arguments can also be used in a startup script that executes when a computer reboots and a user is logged on.

4.1. Windows

Windows XP enables you to define a user that logs onto the computer automatically when the computer starts. In this case, the user would be the Batch Manager admin user we have been referring to. This auto log on capability, along with a shortcut to a .BAT script you create, will cause the Batch Manager to automatically start and connect. Again, this will ensure that if the computer the Batch Manager is running on is restarted, the Batch Manager will restart also.

4.1.1. Step 1: Configuring User Auto Log On

The first step is to configure the computer the Batch Manager is running on to log on a specified user when it starts. This step requires you to manually store relevant user information in the Windows registry. We will not cover the details on this step in this document. However, you can learn more about how to turn on automatic log on in Windows XP by visiting the Microsoft help and support website. At the time this product guide was published, the following URL linked to a Microsoft article on this very topic: http://support.microsoft.com/kb/315231.

4.1.2. Step 2: Creating .BAT File

Once the Batch Manager admin user has been set up to be automatically logged on, the next step is to create a batch (.BAT) script file. This .BAT file, when executed, will run the Batch Manager and connect it to your xTuple ERP database. Below is a sample script which incorporates what we learned in Section 3, “Runtime Options”:

Example .BAT File

The .BAT file example shown in the screenshot will perform the following tasks:

  • Start the BatchManager.exe client located in C:\xtbatch

  • Connect the Batch Manager to the server xtupleserver (you could use the IP address), database postbooks_live, on port 5432

  • Log on the Batch Manager as user "batch" using password "!postbooks!"

  • Set an idle interval of 30 seconds, rest interval of 30 seconds, and a refresh interval of 600 seconds

4.1.3. Step 3: Adding Shortcut for .BAT File

Finally, you will need to create a shortcut for your .BAT file and place it in the Startup folder for the user who is configured to log on automatically. To accomplish this, follow these steps:

  1. Log on to the computer as the Batch Manager admin user

  2. Right-click on the Windows START button

  3. Select the "Explore" option

  4. This will land you in the "Start Menu" directory

  5. Within the "Start Menu" directory, open the "Programs" folder

  6. Within the "Programs" directory, open the "Startup" folder

  7. Drag the .BAT shortcut into the "Startup" folder

Once you have completed the steps above, the setup for this technique is complete. The Batch Manager admin user will be automatically logged on when the computer reboots―and the Batch Manager .BAT script will be executed..

Tip

You may also want to set the screen saver for the auto log on user to "On resume, display Welcome screen". You might also want to set a wait time of one minute. By doing so, you lock out unauthorized usage of this computer within one minute of log on.

4.2. Mac

There are several ways to start the Batch Manager automatically on OSX when the machine it is running on is rebooted. In this section we will cover one of those strategies—to give you some ideas for how this can be accomplished. The method we will describe comes with the following two requirements:

  • The Batch Manager admin user must be configured for automatic login

  • A shell script be modified and installed.

We will show you how to satisfy both requirements in this section.

4.2.1. OSX Shell Script

Save the shell script below in your Batch Manager admin user's home directory as startbm.command. This is the shell script that will be launched when the admin user is automatically logged in.

Note

You will need to edit the first six parameters to match your environment.

#!/bin/bash
# Autostart of BatchManager for OSX
# Name this file 'startbm.command' and should be located under your users home directory
# To start the BatchManager in OSX upon Login, create a Login Item for a user that will 
# login upon system startup.
# Navigate to System -> Accounts -> Login Items, and add 'startbm.command' to the list.

################################################### 
## EDIT NEXT SIX LINES TO MATCH YOUR ENVIRONMENT ##
###################################################

BM_PATH='/Applications/BatchManager.app/Contents/MacOS/'
DB_SERVER='192.168.0.100'
DB_NAME='mydemodb'
DB_PORT='5432'
DB_USERNAME='myuser'
DB_PASSWD='mypassword'

#################################
## DO NOT EDIT BELOW THIS LINE ##
#################################

DB_URL=psql://$DB_SERVER/$DB_NAME:$DB_PORT
$BM_PATH/BatchManager -databaseURL=$DB_URL -username=$DB_USERNAME -passwd=$DB_PASSWD &
exit
4.2.1.1. Setting Up User for Auto Login

Once the shell script has been modified and saved to the correct location, your next step is to attach the script to the admin user's login items. To attach the script to the admin user's login items, follow these steps:

  1. Select the System Preferences icon

  2. Select the "Accounts" option under the System section

  3. Then, set up the user for automatic login, as shown in the following screen:

Set Up User for Automatic Log In

Finally, follow these last steps:

  1. Highlight the user in the "My Account" column

  2. Select the "Login Items" tab

  3. Select the "+" symbol

  4. Then browse to locate and then add the startbm.command file from the user's home directory

  5. The following screen illustrates this process:

Link Shell Script to User

Once you have completed these steps, you are done! The Batch Manager will now restart automatically whenever the machine it is running on is rebooted.

4.3. Linux

To run the Batch Manager as if it were a service on Red Hat Linux, you will need to use the VNC server from RealVNC. An open source version of the VNC server is freely available. With the vnc-server rpm package installed on your Red Hat Linux server, you will have all the necessary tools installed to implement this solution. The first thing you need to do is install the Batch Manager and make sure it is set up and working correctly for the chosen user. We recommend that you set up an additional, separate user for the Batch Manager to run as. Once the Batch Manager is installed, you will next need to set up the VNC server for the same user you want to run the Batch Manager as. The easiest method for doing this is to log in as the user and run the following command:

vncserver :1

In this case we specified ':1' which specifies the terminal to use. As you will see, this detail will become important later. Typically ':1' will be sufficient; however, if you have other VNC server sessions set up, you may need to use a different number. For the rest of this document we will assume only one VNC server session is installed. When the 'vncserver :1' command runs, it will create a directory in the user's home called '.vnc' and ask for a password. Once the VNC server is running, you can log in with vncviewer and check to see what it looks like before continuing. Once done, you should shut down the server with the following command:

vncserver -kill :1

Next, you should edit the xstartup file in the .vnc directory. This file is run by the VNC server program when VNC is started. It allows you to run other applications at startup. In most cases, the last line of the xstartup file reads as follows:

twm &

It is just after this line that you want to add the call to the Batch Manager. The command is very similar to the one you would use to run the Batch Manager from the command line normally. In the command, you will want to include the options to specify the database, username, and password so that the Batch Manager will start up without prompting for a login. The only additional option you will want to add is the '-geometry' option. This option is typical for most GUI enabled applications and specifies the size and location of the active window. The example below illustrates the '-geometry' option and assumes that the user<literal>admin</literal> does not have a database password (typically a bad idea):

BatchManager -geometry 300x320+10+10 -databaseURL=psql://localhost/mydb:5432 -username=admin -noAuth

To guard against unforeseen circumstances and the inevitable user who always exits from applications before logging out, you might want to wrap the Batch Manager startup command in a loop:

while true ; do # loop forever
    BatchManager -databaseURL=psql://localhost/mydb:5432 -username=admin -noAuth
    sleep 600   # wait 10 minutes before restarting the BatchManager if it exits
    done        # to guard against eating machine time if the BatchManager fails repeatedly

Finally, you should save and exit the xstartup file.

Now you will need to update the /etc/sysconfig/vncserver configuration file. If your system does not have one, then you will have to find or create one. Note that some versions of Linux store these service startup files in other directories, such as /etc/rc.d or /etc/initd.d. In this file there is a line which looks like the following:

VNCSERVERS="1:myusername"

This line may or may not be commented out with a '#' symbol. If it is, you need to uncomment it by removing that symbol and any additional spaces at the front of the line. The significance of this line is that it tells the VNC server service which servers to start up for which user at boot up. As you can see, the example above references the same server number we used earlier, along with the username separated by a colon. On your system, you should change the server number and user name to the correct values Save and exit the configuration file. Now you will need to make sure that the VNC server service is started when the system is booted. The easiest way to do this on your Red Hat Linux server is by using the 'chkconfig' command. Logged in as the administrator of the server, you would issue the following command:

chkconfig –add vncserver

At this point, the only thing left to do is start the service and make sure it is working correctly. To start the service, you should issue another administrator command:

service vncserver start

You should see a message indicating that the service was started successfully. Now log into the VNC session and check to make sure the Batch Manager is running correctly. If it is, you have successfully completed the set up. If it is not running, you will need to determine what caused it to fail and correct the problem.