Skip to content

TransiTime Running

Claudiu Bogdan Minea edited this page Dec 19, 2021 · 3 revisions

Deploying and configuring the webapps

Deploy the Web and API WARs to the new Tomcat installation.

cp transitclockWebapp/target/web.war /opt/tomcat/webapps/
cp transitclockApi/target/api.war /opt/tomcat/webapps/

Get the API Key you set earlier. Run mysql -u DB_USER -p -D DB_NAME with the credentials for your first and main agency database (the one also containing webstructs).

mysql> SELECT * FROM ApiKeys;
+----------------------+----------------+------------------+-------------------------+--------------------+---------------+
| applicationName      | applicationKey | applicationUrl   | description             | email              | phone         |
+----------------------+----------------+------------------+-------------------------+--------------------+---------------+
|                      | YORAPIKEY      |                  |                         |                    |               |
+----------------------+----------------+------------------+-------------------------+--------------------+---------------+
1 row in set (0.00 sec)

Set Tomcat environment variables for your API keys and database (main one... again) credentials by editing the setenv file with this command nano /opt/tomcat/bin/setenv.sh:

export CATALINA_OPTS="-Dtransitclock.apikey=YORAPIKEY \
-Dtransitclock.configFiles=/usr/local/transitclock/config/AGENCY.xml \
-Dtransitclock.hibernate.configFile=/usr/local/transitclock/config/hibernate_AGENCY.cfg.xml"

export JAVA_OPTS="-Dtransitclock.apikey=YORAPIKEY \
-Dtransitclock.configFiles=/usr/local/transitclock/config/AGENCY.xml \
-Dtransitclock.hibernate.configFile=/usr/local/transitclock/config/hibernate_AGENCY.cfg.xml"

Restart Tomcat with sudo service tomcat restart.

Running the RMI and core apps „once”

I am going to run the following commands in "screens". These run in the background once executed. To see the output of a screen, run screen -r NAME. They're also set to run in a loop in order to recover from any unexpected crashes. To stop the process running in a specific screen run screen -X -S NAME quit. Names can have whatever structure you desire.

Run the RMI Registry, which is a small Java-specific TCP server which allows for communication between JVMs locally, on your machine. I believe this is how TC cores and the API communicate (while simple queries, like getting the list of WebAgencies and timestamps of AVL reports are queried directly from the database by the applets).

screen -S rmi -dm bash -c 'while true; do rmiregistry; done;'

Run the cores for each of your agencies. Please note the -Xmx4096M. I put it there because my install is for a rather large agency - that represents allocating 4 GB of RAM. You may remove this parameter and let it run with default options (1/4th of the physical memory or 1GB probably) if your GTFS and AVL are not of gargantuan sizes.

screen -S tccoreAGENCY -dm bash -c 'cd /path/to/transitime/build/;while true; do java -Xmx4096M -Dtransitclock.configFiles=/usr/local/transitclock/config/AGENCY.xml -Dtransitclock.logging.dir=/tmp -Dtransitclock.rmi.secondaryRmiPort=0 -jar transitclock/target/Core.jar; done;'
screen -S tccoreSECONDARYAGENCY -dm bash -c 'cd /path/to/transitime/build/;while true; do java -Dtransitclock.configFiles=/usr/local/transitclock/config/SECONDARYAGENCY.xml -Dtransitclock.logging.dir=/tmp -Dtransitclock.rmi.secondaryRmiPort=0 -jar transitclock/target/Core.jar; done;'

Running on boot

Run crontab -e and add the commands above at the end of the file (you may navigate with CTRL+V as a page down key) preceded by @reboot to have them run on system startup.

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

@reboot screen -S rmi -dm bash -c 'while true; do rmiregistry; done;'
@reboot screen -S tccoreAGENCY -dm bash -c 'cd /path/to/transitime/build/;while true; do java -Xmx4096M -Dtransitclock.configFiles=/usr/local/transitclock/config/AGENCY.xml -Dtransitclock.logging.dir=/tmp -Dtransitclock.rmi.secondaryRmiPort=0 -jar transitclock/target/Core.jar; done;'
@reboot screen -S tccoreSECONDARYAGENCY -dm bash -c 'cd /path/to/transitime/build/;while true; do java -Dtransitclock.configFiles=/usr/local/transitclock/config/SECONDARYAGENCY.xml -Dtransitclock.logging.dir=/tmp -Dtransitclock.rmi.secondaryRmiPort=0 -jar transitclock/target/Core.jar; done;'

Exit and save with CTRL+X and Y.

Updating your data

Basically, follow the same instructions as Importing data and restart the cores.

java \
  -Xmx1024M \
  -Dtransitclock.logging.dir=/tmp \
  -Dtransitclock.configFiles=/usr/local/transitclock/config/AGENCY.xml  \
  -jar transitclock/target/GtfsFileProcessor.jar \
  -storeNewRevs \
  -gtfsZipFileName /PATH/TO/YOUR/GTFS.zip \
  -maxTravelTimeSegmentLength 400
java \
  -Xmx1024M \
  -Dtransitclock.logging.dir=/tmp \
  -Dtransitclock.configFiles=/usr/local/transitclock/config/SECONDARYAGENCY.xml  \
  -jar transitclock/target/GtfsFileProcessor.jar \
  -storeNewRevs \
  -gtfsZipFileName /PATH/TO/YOUR/SECONDARYGTFS.zip \
  -maxTravelTimeSegmentLength 400

screen -X -S tccoreAGENCY quit
screen -X -S tccoreSECONDARYAGENCY quit

screen -S tccoreAGENCY -dm bash -c 'cd /path/to/transitime/build/;while true; do java -Xmx4096M -Dtransitclock.configFiles=/usr/local/transitclock/config/AGENCY.xml -Dtransitclock.logging.dir=/tmp -Dtransitclock.rmi.secondaryRmiPort=0 -jar transitclock/target/Core.jar; done;'
screen -S tccoreSECONDARYAGENCY -dm bash -c 'cd /path/to/transitime/build/;while true; do java -Dtransitclock.configFiles=/usr/local/transitclock/config/SECONDARYAGENCY.xml -Dtransitclock.logging.dir=/tmp -Dtransitclock.rmi.secondaryRmiPort=0 -jar transitclock/target/Core.jar; done;'

I recommend you to integrate this commands in your GTFS update pipeline.

Clone this wiki locally