Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Change Request : Linux Native Agent - systemctl and log rotation #1259

Closed
Talie5in opened this issue May 17, 2024 · 5 comments
Closed

Comments

@Talie5in
Copy link
Sponsor Contributor

Talie5in commented May 17, 2024

Describe what section of the docs is outdated or otherwise in need of change
Linux Native Hardware

Suggested Changes
Add After "Persistence" or part of "Persistence".
https://meshtastic.org/docs/hardware/devices/linux-native-hardware/#persistence


Run Meshtastic as a service/daemon for manual compile/builds (non .deb package releases)

To Setup the device to start and stop meshtasticd as as service using systemctl you can setup the service unit using the instructions below.

Create the service unit file:

Create a new file in the /etc/systemd/system/ directory with a name like meshtasticd.service.
sudo nano /etc/systemd/system/meshtasticd.service
Add the following content to the file:

[Unit]
Description=Meshtastic Daemon
After=network.target

[Service]
ExecStart=/usr/sbin/meshtasticd
Restart=always
User=root
Group=root
StandardOutput=file:/var/log/meshtasticd.log
StandardError=file:/var/log/meshtasticd.log
Type=simple

[Install]
WantedBy=multi-user.target

Reload systemd to recognize the new service:
sudo systemctl daemon-reload

Enable the service to start on boot:
sudo systemctl enable meshtasticd

Starting and Stopping the Service

Start the service:
sudo systemctl start meshtasticd

Check the status of the service:
sudo systemctl status meshtasticd

Stop the service:
sudo systemctl stop meshtasticd

This will give you a detailed view of the service status and any potential errors.

By following these steps, you set up a systemd service for meshtasticd that will start automatically at boot and restart if it crashes. You can manage it using the standard systemctl commands (start, stop, restart, status, etc.).

Setup Log Rotation

To setup log rotation within the Linux Native Device and do a daily restart of the Meshtastic Daemon you can implement the below.

Create a logrotate configuration file for the meshtasticd log. Create a file named /etc/logrotate.d/meshtasticd:
sudo nano /etc/logrotate.d/meshtasticd

Add the following content to the file:

/var/log/meshtasticd.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 0640 root root
    sharedscripts
    postrotate
        systemctl restart meshtasticd > /dev/null 2>&1 || true
    endscript
}

Test log rotation:

Test the logrotate configuration to ensure it works as expected:
sudo logrotate -d /etc/logrotate.d/meshtasticd

If everything looks good, force a rotation to see it in action:
sudo logrotate -f /etc/logrotate.d/meshtasticd

By following these steps, you will have meshtasticd output directed to a log file with automatic log rotation configured, ensuring that your logs are managed and disk space is conserved.

@lincolnpjames
Copy link

Appears the .deb release already contains the systemd service. Lets revise the above and I'll submit a PR :)

@Talie5in
Copy link
Sponsor Contributor Author

This is more for non .deb installs (eg, manual compile)

@Talie5in
Copy link
Sponsor Contributor Author

Talie5in commented May 19, 2024

Need to add in something about disabling serial login on RaspbeeryPi's :/

create a file called disable_serialconsole.sh

#!/bin/bash

# Path to the file containing the kernel command line parameters
CMDLINE="/boot/firmware/cmdline.txt"

# Function to disable the serial console
disable_serial_console() {
  # Remove any occurrence of 'console=ttyAMA0,<baudrate>' or 'console=serial0,<baudrate>'
  sed -i -e "s/console=ttyAMA0,[0-9]\+ //g" $CMDLINE
  sed -i -e "s/console=serial0,[0-9]\+ //g" $CMDLINE
  # disable and stop the serial console
  systemctl disable serial-getty@ttyS0.service
  systemctl stop serial-getty@ttyS0.service
}

# Execute the function to disable the serial console
disable_serial_console

Set the script as executable and execute the file

chmod +x disable_serialconsole.sh
sudo ./disable_serialconsole.sh

@Talie5in
Copy link
Sponsor Contributor Author

Talie5in commented May 21, 2024

Alternatively, for Raspberry Pi's only... (rPi2-4 and rPi5 compatible)

sudo raspi-config nonint do_serial_hw 0 # Enable Serial Port (enable_uart=1)
sudo raspi-config nonint do_serial_cons 1 # Disable Serial Console

Can take it a step further and configure the rest of the vars..

sudo raspi-config nonint set_config_var dtparam=spi on /boot/firmware/config.txt # Enable SPI
sudo raspi-config nonint set_config_var dtparam=i2c_arm on /boot/firmware/config.txt # Enalbe i2c_arm

# Ensure dtoverlay=spi0-0cs is set in /boot/firmware/config.txt without altering dtoverlay=vc4-kms-v3d or dtparam=uart0
sudo sed -i -e '/^\s*#\?\s*dtoverlay\s*=\s*vc4-kms-v3d/! s/^\s*#\?\s*(dtoverlay|dtparam\s*=\s*uart0)\s*=.*/dtoverlay=spi0-0cs/' /boot/firmware/config.txt

# Insert dtoverlay=spi0-0cs after dtparam=spi=on if not already present
if ! sudo grep -q '^\s*dtoverlay=spi0-0cs' /boot/firmware/config.txt; then
    sudo sed -i '/^\s*dtparam=spi=on/a dtoverlay=spi0-0cs' /boot/firmware/config.txt
fi

Once above is done, need to reboot.

sudo reboot

@Talie5in
Copy link
Sponsor Contributor Author

Talie5in commented Jun 2, 2024

Closing as PR has been merged.

#1267

@Talie5in Talie5in closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants