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):¶
3. Optional: Create a symlink for easy access¶
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¶
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¶
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!)¶
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¶
Restarting the Server¶
Migration from Old Startup Script¶
Old script (start-tlinq.sh):¶
New script (tlinq-service.sh):¶
Migration Steps:¶
-
Stop the old server:
-
Start with new script:
-
Verify it's working:
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 rotateor 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:
Problem: "Cannot create log directory"¶
Solution:
Problem: "Stale PID file found"¶
Solution:
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¶
- Test the new service manager
- Set up logrotate for automatic rotation
- Update any monitoring/deployment scripts to use new commands
- Consider setting up a systemd service (optional, for system startup)
Creating a systemd Service (Optional)¶
For automatic startup on system boot:
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: