Opsbeacon
Running ob-agent as a service
We are offering two methods for running ob-agent as a service: PM2 and Systemd configurations. These configurations will help you maintain an active agent connection.
The following installation steps are provided for reference on Amazon Linux 2. Please adjust these instructions to suit your specific operating system as needed.
PM2 Configuration
Install NPM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
. ~/.nvm/nvm.sh
nvm install 16
Install Node
sudo yum install https://rpm.nodesource.com/pub_16.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
sudo yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
Install PM2
sudo npm install pm2@latest -g
Start PM2 as EC2-user
pm2 start /home/ec2-user/ob-agent --name ob-agent
pm2 save
pm2 startup
Saving environment variables to /home/ec2-user/.env
OB_AGENT_TOKEN=<token>
OB_SERVER_URL=wss://<your_opsbeacon_server>/ws
OB_DEFAULT_DIR=/
Export $(cat /home/ec2-user/.env | xargs)
pm2 start /home/ec2-user/ob-agent --name ob-agent
pm2 save
pm2 startup
Systemd Configuration
You need to create a systemd service unit file for your Go binary. Open a terminal and create the service unit file using a text editor like nano:
sudo nano /etc/systemd/system/ob-agent.service
Add the following content to the ob-agent.service file:
[Unit]
Description=OB Agent
After=network.target
[Service]
Type=simple
ExecStart=/path/to/your/ob-agent
WorkingDirectory=/path/to/workingDir
EnvironmentFile=/path/to/your/env_path
Restart=always
[Install]
WantedBy=multi-user.target
Save and exit the text editor (in Nano, you can do this by pressing Ctrl+O, Enter, and then Ctrl+X).
After creating the service unit file, you need to reload systemd to recognize the new service. You can do this by running:
sudo systemctl daemon-reload
sudo systemctl enable ob-agent.service
sudo systemctl start ob-agent.service
You can check the status of your service to ensure it's running correctly:
sudo systemctl status ob-agent.service
You can view the logs for your service using the journalctl command. Replace ob-agent.service with the actual name of your service:
sudo journalctl -u ob-agent.service