"""
Forces the Passenger/WSGI app server to reload by touching passenger_wsgi.py.
Upload to /home/xygbfpsg/phingrazuri/ and run: python restart_app.py
"""
import os, sys

wsgi_path = '/home/xygbfpsg/phingrazuri/passenger_wsgi.py'

if os.path.exists(wsgi_path):
    # Touch the file to update its modification time — Passenger watches this
    os.utime(wsgi_path, None)
    print(f"Touched {wsgi_path} — app will reload on next request")
else:
    print(f"Not found: {wsgi_path}")
    # Try alternative paths
    for path in [
        '/home/xygbfpsg/phingrazuri/wsgi.py',
        '/home/xygbfpsg/phingrazuri/branch_system/wsgi.py',
    ]:
        if os.path.exists(path):
            os.utime(path, None)
            print(f"Touched {path}")
            break

# Also create/touch a restart.txt if using cPanel Python app
restart_paths = [
    '/home/xygbfpsg/phingrazuri/tmp/restart.txt',
    '/home/xygbfpsg/tmp/restart.txt',
]
for rpath in restart_paths:
    try:
        os.makedirs(os.path.dirname(rpath), exist_ok=True)
        with open(rpath, 'w') as f:
            f.write('restart')
        print(f"Created {rpath}")
        break
    except Exception as e:
        pass

print("Done — make a test payment now")
