Install mega-cmd from official website https://mega.io/cmd#download. For Raspberry Pi use Linux > Raspbian.
To create background service:
# Create the service file (copy content)
# WARNING: UPDATE LINE 7 "User=root" if you want to run it as different user
sudo nano /etc/systemd/system/mega.service
# Set proper permissions
sudo chmod 644 /etc/systemd/system/mega.service
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable the service to start on boot
sudo systemctl enable mega
# Start the service
sudo systemctl start mega
# Check status
sudo systemctl status myservice
# Stop service
sudo systemctl stop myservice
# Restart service
sudo systemctl restart myservice
# View logs
journalctl -u myservice