Skip to content
Snippets Groups Projects
Commit 1a5e9218 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
#!/bin/env php
<?php
require("inc_vars.php");
require("inc_functions.php");
$INFILE="$selfdir/src/amcli.php";
$INCFILE="$selfdir/src/include_checks.php";
$TMPFILE="$selfdir/src/amcli.php.tmp";
echo "
B U I L D E R
";
_chdir($selfdir);
if(!is_dir($dirBuild)){
mkdir($dirBuild, 0755, true);
}
$OUTFILE="$selfdir/$dirBuild/".str_replace('.php', '', basename($INFILE));
_h1("Prepare source");
$in=file_get_contents($INFILE);
$inccode=file_get_contents($INCFILE);
$inccode=str_replace("<?php", "", $inccode);
$tempcode=preg_replace("#\/\/ ---MARK---INCLUDE-CHECKS---START---(.*)END#s", "$inccode", $in);
if(file_put_contents($TMPFILE, $tempcode)){
echo "✅ OK $TMPFILE was written\n";
}
_h1("Compile");
_chdir("$selfdir/$dirExternal/bin");
_exec("./spc micro:combine '$TMPFILE' -O '$OUTFILE'");
if(unlink($TMPFILE)){
echo "Cleanup: $TMPFILE was deleted\n";
}
_h1("Test generated binary");
_exec("file '$OUTFILE'");
_exec("'$OUTFILE' test=123");
_h1("Done");
<?php
// ----------------------------------------------------------------------
// SHARED FUNCTIONS FOR INSTALLER AND BUILDER
// ----------------------------------------------------------------------
function _h1($s){
echo "\n>>>>>>>>>> $s\n";
}
function _abort($sMessage, $iExitcode=1){
echo "❌ $sMessage.\n";
exit($iExitcode);
}
function _chdir($sDir){
if (!is_dir($sDir)){
_abort("Directory '$sDir' not found.");
}
chdir($sDir);
echo "dir # " . getcwd() . "\n";
}
/**
* Execute shell command and abort if it fails
* @param mixed $cmd
* @return void
*/
function _exec($cmd){
echo "cmd > $cmd\n";
exec("$cmd 2>&1", $aOut, $rc);
echo implode("\n", $aOut)."\n";
if($rc != 0){
echo "rc=$rc ";
_abort("Error: Command failed. Aborting.", $rc);
}
echo "✅ OK\n\n";
}
<?php
$php_version="8.3";
$php_libs="zlib";
$myos=strtolower(PHP_OS);
$myarchitecture="x86_64";
$selfdir=dirname(__FILE__);
$dirExternal="external";
$dirBuild="built_packages";
#!/bin/env php
<?php
/*
I N S T A L L E R
*/
require("inc_vars.php");
require("inc_functions.php");
$gitAppmonitor="https://github.com/iml-it/appmonitor.git";
$spcUrl="https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-$myos-$myarchitecture";
$doneBuild="__done_build-micro__".md5($php_version.$php_libs).".txt";
/*
Filename Last Modified Size Download Count
spc-linux-aarch64 2025-02-15 17:30:46 3.4M 451
spc-linux-aarch64.tar.gz 2025-02-15 17:30:46 3.3M 54
spc-linux-x86_64 2025-02-15 17:30:46 3.5M 937
spc-linux-x86_64.tar.gz 2025-02-15 17:30:46 3.3M 282
spc-macos-aarch64 2025-02-15 17:31:40 7.8M 669
spc-macos-aarch64.tar.gz 2025-02-15 17:31:38 3.8M 211
spc-macos-x86_64 2025-02-15 17:31:46 7.8M 463
spc-macos-x86_64.tar.gz 2025-02-15 17:31:45 3.9M 89
spc-windows-x64.exe 2025-02-15 17:30:46 3.9M 551
*/
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
echo "
I N S T A L L E R
- gets appmonitor sources
- gets spc binary
- spc downloads PHP and libs
- spc builds micro (1..2 min)
";
_chdir($selfdir);
// ----------------------------------------------------------------------
_h1("External data dir");
if(!is_dir($dirExternal)){
mkdir($dirExternal, 0755, true);
}
if(!is_dir("$dirExternal/bin")){
mkdir("$dirExternal/bin", 0755, true);
}
_chdir("$selfdir/$dirExternal");
// ----------------------------------------------------------------------
_h1("Get / update Appmonitor repo");
if(!is_dir("appmonitor")){
_exec("git clone $gitAppmonitor");
} else {
_chdir("$selfdir/$dirExternal/appmonitor");
_exec("git pull -f $gitAppmonitor");
}
// ----------------------------------------------------------------------
_h1("Generate include file with all available checks...");
$incfile="$selfdir/src/include_checks.php";
_chdir("$selfdir/$dirExternal");
$out="<?php
// This file was generated by
// ".__FILE__."
// at ".(date("Y-m-d H:i:s"))."
// ----- appmonitor client classes
require_once('../$dirExternal/appmonitor/public_html/client/classes/appmonitor-checks.class.php');
require_once('../$dirExternal/appmonitor/public_html/client/classes/appmonitor-client.class.php');
// ----- appmonitor checks
";
foreach(glob("appmonitor/public_html/client/plugins/checks/*php") as $sFile){
$out.="require_once('../$dirExternal/$sFile');\n";
}
if(file_put_contents($incfile, $out)){
echo "✅ OK $incfile was written\n";
}
// ----------------------------------------------------------------------
_h1("Get / update spc");
_chdir("$selfdir/$dirExternal/bin");
if(!file_exists("spc")){
_exec("wget -O spc '$spcUrl'");
}
if (PHP_OS == "Linux") {
_exec("chmod +x spc");
}
// ----------------------------------------------------------------------
_h1("Spc - prepare environment");
if(!file_exists("$doneBuild")){
_exec("./spc --no-interaction doctor");
_exec("./spc download --no-interaction --with-php=$php_version --for-extensions '$php_libs'");
echo "Hint: this can take 2 minutes ...\n";
_exec("./spc build --no-interaction --build-micro '$php_libs'");
touch("$doneBuild");
} else {
echo "Micro already built - php $php_version - extensions '$php_libs'\n";
}
_h1("Done.");
# POC Appmonitor client cli
💡 **Idea**: For non PHP systems we prepare a compiled binary containing all written PHP checks. Then those non PHP systems do not need to implement the checks again.
## Requirements
* wget
* git
* PHP 8 cli (no webserver needed)
## Installation
How to bring up this project to live:
- clone this repository
- run the `./installer.php` to download spc and prepare the micro build
## Update
Run the installer again.
if you want to install a newer version of spc: remove the external/bin/ directory and run the installer again.
## Start over
Remove the dirs
- build_packages
- external
Then start `./installer.php` and `./build.php`
## Compile
To compile `src/amcli.php`to `built_packages/amcli` start the `./build.php`
#!/usr/bin/env php
<?php
chdir(__DIR__);
// ---MARK---INCLUDE-CHECKS---START---
if(! file_exists("include_checks.php")){
echo "ERROR: File 'include_checks.php' does not exisr yet..\n";
echo "Run the ../installer.php first!\n";
exit(1);
}
if(!include "include_checks.php"){
echo "ERROR: Include of generated 'include_checks.php' failed.\n";
echo "Check its generation by installer or run the installer again.\n";
exit(2);
}
// ---MARK---INCLUDE-CHECKS---END
if($argc>1)
parse_str(implode('&',array_slice($argv, 1)), $_GET);
echo "PARAMS: ";
print_r($_GET);
<?php
// This file was generated by
// /home/axel/data/opensource/php-class/amc-cli/installer.php
// at 2025-02-26 16:19:10
// ----- appmonitor client classes
require_once('../external/appmonitor/public_html/client/classes/appmonitor-checks.class.php');
require_once('../external/appmonitor/public_html/client/classes/appmonitor-client.class.php');
// ----- appmonitor checks
require_once('../external/appmonitor/public_html/client/plugins/checks/apacheprocesses.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/cert.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/diskfree.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/exec.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/file.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/hello.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/httpcontent.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/loadmeter.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/mysqlconnect.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/pdoconnect.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/phpmodules.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/ping.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/porttcp.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/simple.php');
require_once('../external/appmonitor/public_html/client/plugins/checks/sqliteconnect.php');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment