Skip to content

Commit

Permalink
Merge pull request #3 from mnellemann/packaging
Browse files Browse the repository at this point in the history
Packaging
  • Loading branch information
mnellemann authored Feb 27, 2024
2 parents 6c88f06 + ebdbdf1 commit 943777a
Show file tree
Hide file tree
Showing 30 changed files with 431 additions and 210 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [1.1.7] - 2024-02-27
- Client: Move configuration options into configuration file - prep. for packaging
- Server: Implement configuration file and move options into configuration file - prep. for packaging
- Create systemd (Linux) or sysv (AIX) init scripts during installation when installing from .deb or .rpm

## [1.1.6] - 2024-01-31
- Allow server to override timestamp from clients
- Update 3rd party dependencies
Expand Down
2 changes: 0 additions & 2 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ This is the client/agent component of sysmon, which you install (together with s

Download *.deb* or *.rpm* packages for sysmon-client *and* sysmon-plugins, and install.

See the [doc/systemd.md](doc/systemd.md) or [doc/sysv-init.md](doc/sysv-init.md) files for further instructions on running as a system service.

## Development

### Build & Test
Expand Down
19 changes: 10 additions & 9 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import org.redline_rpm.header.Os
plugins {
id 'application'

id "net.nemerosa.versioning" version "2.15.1"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.netflix.nebula.ospackage" version "11.5.0"
id "net.nemerosa.versioning" version "${versioningVersion}"
id "com.github.johnrengelman.shadow" version "${shadowVersion}"
id "com.netflix.nebula.ospackage" version "${osPackageVersion}"
}

dependencies {
Expand Down Expand Up @@ -104,15 +104,16 @@ ospackage {

buildDeb {
dependsOn startShadowScripts
installUtils file('scripts/shared.sh')
preUninstall file('scripts/remove.sh')
postInstall file('scripts/install.sh')
}

buildRpm {
dependsOn startShadowScripts
os = Os.LINUX
installUtils file('scripts/shared.sh')
preUninstall file('scripts/remove.sh')
postTrans file('scripts/install.sh')
os Os.LINUX
}

task buildRpmAix(type: Rpm) {
dependsOn startShadowScripts
packageName = "${projectName}-AIX"
os = Os.AIX
}
13 changes: 3 additions & 10 deletions client/doc/readme-aix.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,20 @@ The RPM packages are *"noarch"* Java bytecode, so we can use the **--ignoreos**
rpm -ivh --ignoreos sysmon-client-*.rpm sysmon-plugins-*.rpm
```

### Run automatically at boot
## Configuration

See the [sysv-init.md](sysv-init.md) file for instructions, or run from inittab:

```shell
mkitab "sysmon:2:respawn:env JAVA_HOME=/usr/java8_64 /opt/sysmon/client/bin/client -s http://10.x.y.z:9925/metrics"
init q
```
Edit **/etc/sysmon-client.toml** and modify the server URL.

## Upgrades

To upgrade the packages:

```shell
rpm -Uvh --ignoreos sysmon-*.noarch.rpm
rpm -Uvh --ignoreos sysmon-*.rpm
```

To restart sysmon-client process after upgrade:

```shell
/etc/rc.d/init.d/sysmon-client stop; /etc/rc.d/init.d/sysmon-client start
# or, if running from inittab:
kill -HUP `ps -e -o pid,comm,args | grep sysmon-client | grep java | awk '{print $1}'`
```
43 changes: 43 additions & 0 deletions client/doc/readme-linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Instruction for Linux

Please note that the software versions referenced in this document might have changed and might not be available/working unless updated.

More details are available in the [README.md](../README.md) file.


## Requirements

Java 8 (or later) runtime is required.

## Installation

[Download](https://github.com/mnellemann/sysmon/releases) the latest client and plugins rpm or deb files.

### RedHat Linux

```shell
sudo dnf install java-11-openjdk-headless
sudo rpm -ivh sysmon-client-*.noarch.rpm sysmon-plugins-*.rpm
```

Use *yum* if *dnf* is not available.

### SUSE Linux

```shell
sudo zypper install java-11-openjdk-headless
sudo zypper install sysmon-client-*.noarch.rpm sysmon-plugins-*.rpm
```

### Debian/Ubuntu Linux

```shell
sudo apt install default-jre-headless
sudo dpkg -i sysmon-client-*.deb sysmon-plugins-*.deb
```

## Configuration

Edit **/etc/sysmon-client.toml** and modify the server URL.

Check logs for errors with: ```journalctl -u sysmon-client```
43 changes: 0 additions & 43 deletions client/doc/readme-redhat.md

This file was deleted.

3 changes: 1 addition & 2 deletions client/doc/sysmon-client.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Description=Sysmon Client
#Group=nobody
TimeoutSec=20
Restart=on-failure
ExecStart=/opt/sysmon/client/bin/client -s http://10.20.30.40:9925/metrics
# Note: add '-n hostname' above, if needed
ExecStart=/opt/sysmon/client/bin/client

[Install]
WantedBy=default.target
4 changes: 2 additions & 2 deletions client/doc/sysmon-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

dir="/opt/sysmon/client"
cmd="/opt/sysmon/client/bin/client"
args="-s http://10.20.30.40:9925/metrics" # <- HERE: Specify sysmon-server URL, add '-n hostname' if needed
args=""
user=""

name="sysmon-client"
Expand All @@ -26,7 +26,7 @@ stderr_log="/var/log/$name.err"
#JAVA_HOME=/opt/ibm/ibm-semeru-certified-XX-jre
#JAVA_HOME=/opt/ibm/ibm-semeru-certified-XX-jdk

# Ensure US formatted numbers (dot and not comma)
# Ensure numbers formatted with dot and not comma for thousand-separator
LC_ALL=C


Expand Down
9 changes: 9 additions & 0 deletions client/doc/sysmon-client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
### Example configuration with some default values.
###

# Sysmon Server URL
server = "http://127.0.0.1:9925/metrics"

# Override hostname
#hostname = "cattle1"

# Local path containing plugins
plugins = "/opt/sysmon/plugins"

# Local path for Groovy scripts
scripts = "/opt/sysmon/scripts"

Expand Down
12 changes: 0 additions & 12 deletions client/doc/systemd.md

This file was deleted.

18 changes: 0 additions & 18 deletions client/doc/sysv-init.md

This file was deleted.

49 changes: 49 additions & 0 deletions client/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

install_config() {
test -f "/etc/${service_name}.toml" || cp "${config_source}" "/etc/${service_name}.toml"
}

install_systemd() {
sysctl=$(command -v deb-systemd-invoke || echo systemctl)
test -f "/etc/systemd/system/${service_name}.service" || cp "${systemd_source}" "/etc/systemd/system/${service_name}.service"
$sysctl --system daemon-reload >/dev/null || true
if ! $sysctl is-enabled ${service_name} >/dev/null
then
$sysctl enable ${service_name} >/dev/null || true
$sysctl start ${service_name} >/dev/null || true
else
$sysctl restart ${service_name} >/dev/null || true
fi
}

install_sysv_linux() {
echo "WARN: No support for ${service_name} on SysV Linux"
}

install_sysv_aix() {
test -f "/etc/rc.d/init.d/${service_name}" || cp "${sysv_source}" "/etc/rc.d/init.d/${service_name}"
chmod 0755 "/etc/rc.d/init.d/${service_name}"
ln -sf /etc/rc.d/init.d/sysmon-client /etc/rc.d/rc2.d/Ssysmon-client
ln -sf /etc/rc.d/init.d/sysmon-client /etc/rc.d/rc2.d/Ksysmon-client
}

install_sysv() {
if [ x$(uname | grep AIX) = x"" ]; then
install_sysv_linux
else
install_sysv_aix
fi
}

# Install configuration file
install_config

# Detect if we are running on a systemd based Linux
if [ x$(command -v systemctl) = x"" ]; then
install_sysv
else
install_systemd
fi

exit 0
44 changes: 44 additions & 0 deletions client/scripts/remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

remove_config() {
echo "Leaving /etc/${service_name}.toml for manual deletion."
#test -f "/etc/${service_name}.toml" && mv "/etc/${service_name}.toml" "/etc/${service_name}.bak"
}

remove_systemd() {
sysctl=$(command -v deb-systemd-invoke || echo systemctl)
$sysctl stop ${service_name} >/dev/null || true
$sysctl disable ${service_name} >/dev/null || true
test -f "/etc/systemd/system/${service_name}.service" && rm -f "/etc/systemd/system/${service_name}.service"
$sysctl --system daemon-reload >/dev/null || true
}

remove_sysv_linux() {
echo "WARN: No support for ${service_name} on SysV Linux"
}

remove_sysv_aix() {
/etc/rc.d/init.d/${service_name} stop
rm -f /etc/rc.d/init.d/sysmon-client /etc/rc.d/rc2.d/Ksysmon-client
rm -f /etc/rc.d/rc2.d/Ssysmon-client
}

remove_sysv() {
if [ x$(uname | grep AIX) = x"" ]; then
remove_sysv_linux
else
remove_sysv_aix
fi
}

# Remove configuration file
remove_config

# Detect if we are running on a systemd based Linux
if [ x$(command -v systemctl) = x"" ]; then
remove_sysv
else
remove_systemd
fi

exit 0
7 changes: 7 additions & 0 deletions client/scripts/shared.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

service_name="sysmon-client"
sysv_source="/opt/sysmon/client/doc/sysmon-client.sh"
config_source="/opt/sysmon/client/doc/sysmon-client.toml"
systemd_source="/opt/sysmon/client/doc/sysmon-client.service"

Loading

0 comments on commit 943777a

Please sign in to comment.