# Startup & Logs

## Startup

All modules can be started manually but it is preferred to use `start_db_modules.py` script. On DroneBridge for Raspberry Pi the startup of modules is done by the `start_db` service. The source code sits inside the root directory of the repository. The service can be updated/registered using:

```bash
sudo cp /home/pi/DroneBridge/start_db /etc/init.d/start_db
sudo update-rc.d -f start_db remove
sudo update-rc.d start_db defaults
```

The status of the DroneBridge modules can be checked using:

```bash
sudo /etc/init.d/start_db [status|start|stop]
```

or:

```bash
service start_db [status|start|stop]
```

## Logs

### Local logs when connected via ssh

Since it is a service, all logs will be written to the journal. The logs can be viewed using one of the following commands:

```bash
journalctl -u start_db.service [-f for real-time]
```

```bash
systemctl | grep start_db | less
```

### Local logs when access via SD-card

All DroneBridge modules log to syslog. In `/DroneBridge/log/db_modules.log` are all relevant log entries.

### Remote real-time logging

Connect via TCP to the Raspberry Pi on port `1605` and you will receive realtime syslog logs. Forward the messages to your favourite log viewer like [Syslog Watcher](https://syslogwatcher.com/). Or use the provided Python 3 script below to output directly to console.

```python
import socket
from time import sleep

UDP_PORT_SYSLOG_SERVER = 1605
# Raspberry Pi IP when connected to GND station via WiFi: 192.168.2.1

if __name__ == '__main__':
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    reconnect = True
    while reconnect:
        try:
            sock.connect(('IP-OF-RPi', UDP_PORT_SYSLOG_SERVER))
            reconnect = False
        except ConnectionRefusedError:
            print("Retrying")
            sleep(1)

    while True:
        try:
            data = sock.recv(1024)
            print(data.decode("utf-8"))
        except KeyboardInterrupt:
            break
    socket.socket.close(sock)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dronebridge.gitbook.io/docs/developer-guide/startup-and-logs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
