1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

Merge pull request #223 from jcoeder/patch-2

Create linux-service.md
This commit is contained in:
Massimo Candela
2020-04-29 22:31:23 +02:00
committed by GitHub
3 changed files with 96 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ Read the documentation below for more options.
- [Run from binary](docs/installation.md#running-bgpalerter-from-binaries)
- [Run from source code](docs/installation.md#running-bgpalerter-from-the-source-code)
- [Run in Docker](docs/installation.md#running-bgpalerter-in-docker)
- [Run as a Linux service](docs/installation.md#linux-service)
- [Monitored prefixes list](docs/prefixes.md#prefixes)
- [Generate prefix list](docs/prefixes.md#generate)
- [Prefix attributes description](docs/prefixes.md#prefixes-fields)

View File

@@ -22,6 +22,10 @@ The first time you run it, the auto-configuration will start.
5. Run it: `./bgpalerter-linux-x64`
Or use `nohup ./bgpalerter-linux-x64 &` to leave it running after you close the terminal
##### Linux Service
Additionally, you can configure [BGPalerter to run as a Linux Serivce](docs/linux-service.md)
#### Mac
1. Download the binary [here](https://github.com/nttgin/BGPalerter/releases/latest/download/bgpalerter-macos-x64).

91
docs/linux-service.md Normal file
View File

@@ -0,0 +1,91 @@
## Run BGPAlerter as a Linux Service
If you are interested in running this application as a service on a Linux server here is a basic guide covering how to do that. This process works for RHEL 7 based Linux installations. It will likely work very similiarly on other systemctl enabled installations.
### Create directory for the application to reside
Create a directory to place the application files.
`mkdir /opt/bgpalerter`
If this is a new installation `cd /opt/bgpalerter` before downloading your files and running them for the first time. If this is an existing install simply move the files of your existing install into this directory `mv -t /opt/bgpalerter bgpalerter-linux-x64 bgpalerter.pid config.yml prefixes.yml`
This is the directory where the binary and yaml config files will be stored. The application will also create `logs` and `src` subdirectories here if needed. You do not have to use `/opt/bgpalerter` as your directory of choice, if you choose something else - simply make sure whatever you choose gets updated in the systemd service file below as well.
### Create systemd service file
Next you need to create the systemd service file.
`vi /etc/systemd/system/bgpalerter.service`
The contents of this file should be as follows:
```
[Unit]
Description=BGPAlerter
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/bgpalerter
ExecStart=/opt/bgpalerter/bgpalerter-linux-x64
[Install]
WantedBy=multi-user.target
```
### Reload systemd
Reload systemd to register the new configuration.
`systemctl daemon-reload`
### Enable and start the service
Enable bgpalerter to start at boot and then start the service.
`systemctl enable bgpalerter`
`systemctl start bgpalerter`
### Another helpful trick
Create this file.
`vi /usr/bin/bgpalerter`
The contents of this file should be as follows:
```
#!/bin/bash
for arg in "$@"
do
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]
then
echo "--start Start the Services"
echo "--stop Stop the Services"
echo "--restart Restart the Services"
elif [ "$arg" == "--start" ]
then
echo "Starting BGPAlerter"
systemctl start bgpalerter.service
elif [ "$arg" == "--stop" ]
then
echo "Stopping BGPAlerter"
systemctl stop bgpalerter.service
elif [ "$arg" == "--restart" ]
then
echo "Restarting BGPAlerter"
systemctl restart bgpalerter.service
fi
done
```
Make that file executable.
`chmod +x /usr/bin/bgpalerter`
This file allows you to simply type the following commands if systemctl is too much work for you to remember!
`bgpalerter --help`
`bgpalerter --start`
`bgpalerter --stop`
`bgpalerter --status`