mirror of
https://github.com/mayanayza/netvisor.git
synced 2025-12-10 08:24:08 -06:00
feat: add systemd service support for daemon
This commit is contained in:
37
README.md
37
README.md
@@ -583,6 +583,43 @@ The `CONCURRENT_SCANS` setting controls how many hosts the daemon scans in paral
|
||||
|
||||
If set too high, the daemon may exhaust system resources and fail with an error. Monitor daemon logs and adjust as needed for your hardware.
|
||||
|
||||
#### Running as a System Service (Linux)
|
||||
|
||||
After installing the binary, you can run the daemon as a systemd service:
|
||||
|
||||
1. Create the service file:
|
||||
```bash
|
||||
sudo curl -o /etc/systemd/system/netvisor-daemon.service \
|
||||
https://raw.githubusercontent.com/mayanayza/netvisor/main/netvisor-daemon.service
|
||||
```
|
||||
|
||||
2. Edit the service file to add your configuration:
|
||||
```bash
|
||||
sudo nano /etc/systemd/system/netvisor-daemon.service
|
||||
```
|
||||
|
||||
Add your daemon arguments to the `ExecStart` line:
|
||||
```ini
|
||||
ExecStart=/usr/local/bin/netvisor-daemon --server-target YOUR_SERVER_IP_OR_HOSTNAME --server-port YOUR_SERVER_PORT --network-id YOUR_NETWORK_ID --daemon-api-key YOUR_API_KEY
|
||||
```
|
||||
|
||||
3. Enable and start the service:
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable netvisor-daemon
|
||||
sudo systemctl start netvisor-daemon
|
||||
```
|
||||
|
||||
4. Check status:
|
||||
```bash
|
||||
sudo systemctl status netvisor-daemon
|
||||
```
|
||||
|
||||
5. View logs:
|
||||
```bash
|
||||
sudo journalctl -u netvisor-daemon -f
|
||||
```
|
||||
|
||||
### Server Configuration
|
||||
|
||||
The server supports the following configuration options:
|
||||
|
||||
60
install.sh
60
install.sh
@@ -64,6 +64,64 @@ fi
|
||||
echo ""
|
||||
echo "✓ NetVisor daemon installed successfully!"
|
||||
echo ""
|
||||
echo "To run daemon: netvisor-daemon --server-target YOUR_SERVER_IP --server-port 60072"
|
||||
|
||||
# Ask about systemd service installation (Linux only)
|
||||
if [ "$PLATFORM" = "linux" ] && command -v systemctl &> /dev/null; then
|
||||
echo "Would you like to install NetVisor daemon as a systemd service?"
|
||||
echo "This will allow the daemon to:"
|
||||
echo " - Start automatically on boot"
|
||||
echo " - Run in the background"
|
||||
echo " - Restart automatically if it crashes"
|
||||
echo ""
|
||||
read -p "Install as systemd service? [y/N]: " -n 1 -r
|
||||
echo
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo ""
|
||||
echo "Installing systemd service..."
|
||||
|
||||
# Download service file
|
||||
SERVICE_URL="https://raw.githubusercontent.com/${REPO}/main/netvisor-daemon.service"
|
||||
|
||||
if ! curl -fL "$SERVICE_URL" -o netvisor-daemon.service; then
|
||||
echo "Warning: Failed to download service file from $SERVICE_URL"
|
||||
echo "You can manually install the service later."
|
||||
else
|
||||
# Install service file
|
||||
sudo mv netvisor-daemon.service /etc/systemd/system/ || {
|
||||
echo "Error: Failed to install service file."
|
||||
rm -f netvisor-daemon.service
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "✓ Systemd service file installed!"
|
||||
echo ""
|
||||
echo "⚠️ IMPORTANT: You must edit the service file with your daemon configuration:"
|
||||
echo ""
|
||||
echo " sudo nano /etc/systemd/system/netvisor-daemon.service"
|
||||
echo ""
|
||||
echo "Add your daemon arguments to the ExecStart line:"
|
||||
echo " ExecStart=/usr/local/bin/netvisor-daemon --server-target http://YOUR_SERVER --server-port 60072 --network-id YOUR_NETWORK_ID --daemon-api-key YOUR_API_KEY"
|
||||
echo ""
|
||||
echo "Then enable and start the service:"
|
||||
echo " sudo systemctl daemon-reload"
|
||||
echo " sudo systemctl enable netvisor-daemon"
|
||||
echo " sudo systemctl start netvisor-daemon"
|
||||
echo ""
|
||||
echo "Check status:"
|
||||
echo " sudo systemctl status netvisor-daemon"
|
||||
echo ""
|
||||
echo "View logs:"
|
||||
echo " sudo journalctl -u netvisor-daemon -f"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Show manual run instructions
|
||||
echo ""
|
||||
echo "To run daemon manually:"
|
||||
echo " netvisor-daemon --server-target YOUR_SERVER_IP --server-port 60072"
|
||||
echo ""
|
||||
echo "Need help? Visit: https://github.com/${REPO}#readme"
|
||||
16
netvisor-daemon.service
Normal file
16
netvisor-daemon.service
Normal file
@@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=NetVisor Network Discovery Daemon
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/netvisor-daemon
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
User=root
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user