npm package: @mnmsys/mnmagent
Description: MnM Agent - Cross-platform process manager with CLI interface. Requires administrator/root privileges for service installation.
Author: dev1@hostingcontroller.com
Latest version: 1.0.23

# # MnM Agent - Cross-Platform Process Manager

MnM Agent is a robust cross-platform process manager with CLI interface that works on Windows, Linux, and macOS. It provides a Unix Domain Socket (UDS) server for managing applications and processes, with automatic service installation capabilities.

## Features

- **Cross-Platform Support**: Windows, Linux, and macOS
- **Process Management**: Start, stop, restart, and monitor applications
- **Service Integration**: Automatically installs as a system service
- **CLI Interface**: Easy-to-use command-line tools
- **Configuration Management**: Centralized configuration files
- **User Management**: Create and manage users for applications (Linux/macOS)
- **Logging**: Comprehensive logging for all managed processes

## Installation

### Prerequisites

**Administrator/Root Privileges Required**: MnM Agent automatically installs as a system service, which requires elevated privileges.

### Global Installation

**Linux/macOS:**
```bash
sudo npm install -g @mnmsys/mnmagent
```

**Windows:**
```powershell
# Run PowerShell as Administrator, then:
npm install -g @mnmsys/mnmagent
```

This will:
1. ✅ Install the package globally
2. ✅ Create the `mnm` CLI command  
3. ✅ **Automatically install and start the system service**
4. ✅ Create necessary configuration directories
5. ✅ Set up proper permissions

### Verification

Check if the service is running:

**Linux:**
```bash
sudo systemctl status mnm
```

**Windows:**
```cmd
sc query mnm
```

**macOS:**
```bash
sudo launchctl list | grep com.mnm.agent
```

### Platform-Specific Service Installation

#### Linux (systemd)
- Creates a systemd service file at `/etc/systemd/system/mnm.service`
- Enables and starts the service automatically
- Requires root privileges (`sudo npm install -g mnmagent`)

#### Windows
- Creates a Windows service using the Service Control Manager
- Starts automatically on system boot
- Requires Administrator privileges

#### macOS
- Creates a LaunchDaemon plist file
- Manages the service through launchctl
- Requires root privileges (`sudo npm install -g mnmagent`)

## Configuration

### Environment Variables

Create a `process.env` file or set environment variables:

```bash
TENANTID=your_tenant_id
TENANTTOKEN=your_tenant_token
SOCKETPATH=/tmp/mnm_admin_socket  # Unix/Linux/macOS
# SOCKETPATH=\\\\.\\pipe\\mnm_admin_socket  # Windows (automatic)
```

### Configuration Files

#### Linux/macOS
- Primary config: `/etc/mnm/pm.cnf`
- App config: `/etc/mnm/app.conf`
- Logs: `/var/log/mnm/`

#### Windows
- Primary config: `C:\\ProgramData\\mnm\\pm.cnf`
- App config: `C:\\ProgramData\\mnm\\app.conf`
- Logs: Windows Event Log

## Usage

### CLI Commands

Once installed, use the `mnm` command to interact with the service:

```bash
# List all managed processes
mnm list

# Start an application
mnm start <appName> <appPath> <uid> [args]

# Stop an application
mnm stop <appName>

# Restart an application
mnm restart <appName>

# View application logs
mnm logs <appName>

# Remove an application from management
mnm remove <appName>

# Add a new application to management
mnm add --appName myapp --modulePath /path/to/app --username appuser

# Initialize configuration
mnm init '{"setting": "value"}'
```

### Interactive Mode

Run `mnm` without arguments to enter interactive mode:

```bash
mnm
> list
> start myapp /path/to/app 1000
> logs myapp
> exit
```

## Local Development and Testing

### Testing Locally

1. Clone the repository
2. Install dependencies: `npm install`
3. Build the project: `npm run build`
4. Test locally: `npm run test:local`

### Development Mode

```bash
# Start in development mode with auto-reload
npm run dev

# Build the project
npm run build

# Start the built version
npm start
```

## Troubleshooting

### Service Won't Start

1. Check if another instance is running
2. Verify socket path permissions
3. Check system logs for errors
4. Ensure proper user privileges

### Permission Issues

- Linux/macOS: Run installation with `sudo`
- Windows: Run Command Prompt as Administrator
- Verify file system permissions on config directories

### Socket Connection Issues

- Check if firewall is blocking the socket
- Verify socket path in configuration
- Ensure service is actually running

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Test on multiple platforms
5. Submit a pull request

## License

MIT License - see LICENSE file for details.