Skip to content

TQPro API Server - jsvc Setup Guide

This guide explains how to set up and use the jsvc-based service manager for TQPro API Server, which provides safe log rotation without server restart.

Prerequisites

1. Install jsvc

# Ubuntu/Debian
sudo apt-get update
sudo apt-get install jsvc

# RHEL/CentOS/Rocky Linux
sudo yum install jsvc

# Verify installation
jsvc -help

2. Set up log directory

# Create log directory
sudo mkdir -p /var/log/tqpro

# Set ownership (replace 'nino' with your username)
sudo chown nino:nino /var/log/tqpro

# Verify permissions
ls -ld /var/log/tqpro

3. Verify Java is installed

# Check Java installation
java -version

# If JAVA_HOME is not set, add to ~/.bashrc:
export JAVA_HOME=/usr/lib/jvm/default-java

Installation

1. The service script is already created at:

/home/nino/src/tqpro/config/tlinq-service.sh

2. Make it executable (already done):

chmod +x /home/nino/src/tqpro/config/tlinq-service.sh
sudo ln -s /home/nino/src/tqpro/config/tlinq-service.sh /usr/local/bin/tlinq-service

4. Optional: Set up automatic log rotation with logrotate

# Edit the logrotate config to set your username and path
nano /home/nino/src/tqpro/config/logrotate-tlinq.conf

# Change these lines:
#   create 0644 TLINQ_USER TLINQ_GROUP  ->  create 0644 nino nino
#   TLINQ_HOME="/path/to/tqpro/config"  ->  TLINQ_HOME="/home/nino/src/tqpro/config"

# Install the logrotate configuration
sudo cp /home/nino/src/tqpro/config/logrotate-tlinq.conf /etc/logrotate.d/tlinq
sudo chown root:root /etc/logrotate.d/tlinq
sudo chmod 644 /etc/logrotate.d/tlinq

# Test the configuration
sudo logrotate -d /etc/logrotate.d/tlinq

Usage

Starting the Server

cd /home/nino/src/tqpro/config
./tlinq-service.sh start

Output:

Starting TQPro API Server with jsvc...
✓ TQPro API Server started successfully
  PID: 12345
  Logs: /var/log/tqpro/tlinq-stdout.log
        /var/log/tqpro/tlinq-stderr.log
  Java logs: /var/log/tqpro/tlinqserver-*.log

Checking Status

./tlinq-service.sh status

Output:

✓ TQPro API Server is running
  PID: 12345
  Uptime: 2-03:45:12
  Memory: 512.34 MB
  Logs: /var/log/tqpro/tlinq-stdout.log
        /var/log/tqpro/tlinq-stderr.log

Last 5 error log lines:
  2025-11-24 18:30:15.123 [INFO   ] Server started successfully
  ...

Rotating Logs (WITHOUT RESTARTING!)

./tlinq-service.sh rotate

Output:

Rotating log files...
  Rotated stdout: /var/log/tqpro/tlinq-stdout.log.20251124-183015
  Rotated stderr: /var/log/tqpro/tlinq-stderr.log.20251124-183015
✓ Log files rotated successfully
  New logs: /var/log/tqpro/tlinq-stdout.log
            /var/log/tqpro/tlinq-stderr.log
  Old logs compressed in background

This is the key feature! You can now safely rotate logs without restarting the server.

Viewing Logs in Real-time

# View stderr (most useful - shows errors and startup messages)
./tlinq-service.sh logs stderr

# View stdout
./tlinq-service.sh logs stdout

# View Java logging framework logs
./tlinq-service.sh logs java

# View all (defaults to stderr)
./tlinq-service.sh logs

Stopping the Server

./tlinq-service.sh stop

Restarting the Server

./tlinq-service.sh restart

Migration from Old Startup Script

Old script (start-tlinq.sh):

nohup java ... >tlinq.log 2>tlinq.err &
# Problem: Cannot rotate logs without restart

New script (tlinq-service.sh):

./tlinq-service.sh start
# Solution: Can rotate logs with: ./tlinq-service.sh rotate

Migration Steps:

  1. Stop the old server:

    # Find the PID
    ps aux | grep TQProApiServer
    # Kill it
    kill <PID>
    

  2. Start with new script:

    cd /home/nino/src/tqpro/config
    ./tlinq-service.sh start
    

  3. Verify it's working:

    ./tlinq-service.sh status
    tail -f /var/log/tqpro/tlinq-stderr.log
    

Log File Locations

1. jsvc stdout/stderr logs (System.out.println, startup messages):

  • /var/log/tqpro/tlinq-stdout.log
  • /var/log/tqpro/tlinq-stderr.log
  • These are rotated by ./tlinq-service.sh rotate or logrotate

2. Java logging framework logs (logger.info(), logger.severe(), etc.):

  • /var/log/tqpro/tlinqserver-0-0.log
  • /var/log/tqpro/tlinqserver-1-0.log (after auto-rotation)
  • These auto-rotate at 10MB (configured in log.properties)

Automatic Log Rotation Schedule

If you installed the logrotate configuration:

  • Daily rotation: Logs rotate at 2 AM (default logrotate schedule)
  • Size-based: Also rotates if log exceeds 100MB
  • Retention: Keeps 30 days of rotated logs
  • Compression: Old logs are gzipped to save space

Troubleshooting

Problem: "jsvc not found"

Solution:

sudo apt-get install jsvc

Problem: "Cannot create log directory"

Solution:

sudo mkdir -p /var/log/tqpro
sudo chown $(whoami):$(whoami) /var/log/tqpro

Problem: "Stale PID file found"

Solution:

./tlinq-service.sh stop
./tlinq-service.sh start

Problem: Server won't start

Solution:

# Check stderr log for errors
cat /var/log/tqpro/tlinq-stderr.log

# Check if port is already in use
netstat -tlnp | grep 11080

# Verify classpath
ls -la /home/nino/src/tqpro/config/tqapi.jar
ls -la /home/nino/src/tqpro/config/lib/*.jar

Problem: Logs not appearing after rotation

Solution: This should NOT happen with jsvc! But if it does:

# Check if HUP signal is working
./tlinq-service.sh status  # Get PID
kill -HUP <PID>

# Verify new log files were created
ls -lht /var/log/tqpro/

Cron Job for Automatic Rotation (Alternative to logrotate)

If you prefer manual control without logrotate:

# Edit crontab
crontab -e

# Add this line to rotate logs daily at 2 AM:
0 2 * * * /home/nino/src/tqpro/config/tlinq-service.sh rotate

# Or rotate weekly on Sunday at 3 AM:
0 3 * * 0 /home/nino/src/tqpro/config/tlinq-service.sh rotate

Comparison: Old vs New

Feature Old (nohup + redirect) New (jsvc)
Start server
Stop server Manual kill Clean stop
Log rotation ✗ Requires restart ✓ Without restart
PID management Manual Automatic
Status check Manual ps/grep Built-in
Signal handling Basic Professional
Production-ready No Yes

Next Steps

  1. Test the new service manager
  2. Set up logrotate for automatic rotation
  3. Update any monitoring/deployment scripts to use new commands
  4. Consider setting up a systemd service (optional, for system startup)

Creating a systemd Service (Optional)

For automatic startup on system boot:

# Create systemd service file
sudo nano /etc/systemd/system/tlinq.service

Contents:

[Unit]
Description=TQPro API Server
After=network.target

[Service]
Type=forking
User=nino
WorkingDirectory=/home/nino/src/tqpro/config
ExecStart=/home/nino/src/tqpro/config/tlinq-service.sh start
ExecStop=/home/nino/src/tqpro/config/tlinq-service.sh stop
ExecReload=/home/nino/src/tqpro/config/tlinq-service.sh rotate
PIDFile=/home/nino/src/tqpro/config/tlinq.pid
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl daemon-reload
sudo systemctl enable tlinq
sudo systemctl start tlinq
sudo systemctl status tlinq

Now you can use systemd commands:

sudo systemctl start tlinq
sudo systemctl stop tlinq
sudo systemctl restart tlinq
sudo systemctl reload tlinq  # Rotates logs!