Testing devel
ogcore-debian-package/pipeline/head There was a failure building this commit
Details
ogcore-debian-package/pipeline/head There was a failure building this commit
Details
parent
935561e399
commit
341f10fc97
|
|
@ -61,6 +61,19 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
stage('Generate Changelog (Devel)') {
|
||||
when {
|
||||
branch 'devel'
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def devName = params.DEV_NAME ? params.DEV_NAME : env.DEFAULT_DEV_NAME
|
||||
def devEmail = params.DEV_EMAIL ? params.DEV_EMAIL : env.DEFAULT_DEV_EMAIL
|
||||
generateDebianChangelog(env.BUILD_DIR, devName, devEmail, "devel")
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
script {
|
||||
|
|
@ -96,6 +109,19 @@ pipeline {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Publish to Debian Repository (Devel)') {
|
||||
when {
|
||||
branch 'devel'
|
||||
}
|
||||
agent { label 'debian-repo' }
|
||||
steps {
|
||||
script {
|
||||
def versionPattern = "-${env.BUILD_NUMBER}~devel"
|
||||
publicarEnAptly('/var/tmp/opengnsys/debian-repo/ogcore', 'devel', versionPattern)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
|
|
@ -108,6 +134,13 @@ pipeline {
|
|||
string(name: 'TRIGGERED_BY', value: "${env.JOB_NAME}-${env.BUILD_NUMBER}")
|
||||
]
|
||||
}
|
||||
if (env.BRANCH_NAME == 'devel') {
|
||||
build job: 'Aptly publish develop repository',
|
||||
wait: false,
|
||||
parameters: [
|
||||
string(name: 'TRIGGERED_BY', value: "${env.JOB_NAME}-${env.BUILD_NUMBER}")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,12 +79,24 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then
|
|||
ln -s /opt/opengnsys/ogcore/etc/nginx/sites-available/mercure.conf /etc/nginx/sites-enabled/mercure.conf
|
||||
ln -s /opt/opengnsys/ogcore/etc/php/8.3/fpm/pool.d/ogcore-fpm.conf /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf
|
||||
ln -s /opt/opengnsys/ogcore/etc/systemd/system/og-mercure.service /etc/systemd/system/og-mercure.service
|
||||
ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service
|
||||
ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path
|
||||
ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service
|
||||
|
||||
echo ">>> Configurando journal-pull"
|
||||
touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh
|
||||
mkdir -p /var/log/journal/remote
|
||||
chown systemd-journal-remote:systemd-journal-remote /var/log/journal/remote
|
||||
|
||||
echo ">>> Configurando permisos de archivos"
|
||||
chown opengnsys:www-data /opt/opengnsys/
|
||||
chown -R opengnsys:www-data /opt/opengnsys/ogcore
|
||||
chown www-data:www-data /opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
chmod 664 /opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
systemctl daemon-reload
|
||||
systemctl enable og-mercure
|
||||
systemctl enable --now journal-pull-sync.path
|
||||
systemctl restart mariadb.service
|
||||
systemctl restart og-mercure
|
||||
systemctl restart nginx
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
# Syncs journal-pull@ systemd instances with /etc/opengnsys/journal-pull-sources.conf.
|
||||
# Triggered by journal-pull-sync.path whenever the config file changes.
|
||||
set -euo pipefail
|
||||
|
||||
CONF=/opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
|
||||
[[ -f "$CONF" ]] || exit 0
|
||||
|
||||
mapfile -t WANTED < <(grep -v '^\s*#' "$CONF" | grep -v '^\s*$' | sort -u)
|
||||
mapfile -t CURRENT < <(
|
||||
systemctl list-units 'journal-pull@*.service' --all --plain --no-legend \
|
||||
| awk '{print $1}' | sed 's/journal-pull@//;s/\.service//' | sort -u
|
||||
)
|
||||
|
||||
for ip in "${WANTED[@]:-}"; do
|
||||
[[ -z "$ip" ]] && continue
|
||||
if ! printf '%s\n' "${CURRENT[@]:-}" | grep -qxF "$ip"; then
|
||||
systemctl enable --now "journal-pull@${ip}.service"
|
||||
echo "journal-pull-sync: enabled journal-pull@${ip}"
|
||||
fi
|
||||
done
|
||||
|
||||
for ip in "${CURRENT[@]:-}"; do
|
||||
[[ -z "$ip" ]] && continue
|
||||
if ! printf '%s\n' "${WANTED[@]:-}" | grep -qxF "$ip"; then
|
||||
systemctl disable --now "journal-pull@${ip}.service"
|
||||
echo "journal-pull-sync: disabled journal-pull@${ip}"
|
||||
fi
|
||||
done
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Watch journal-pull sources config
|
||||
|
||||
[Path]
|
||||
PathModified=/opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
[Unit]
|
||||
Description=Sync journal-pull instances from config
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=Pull OpenGNSYS journal from %i
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
User=systemd-journal-remote
|
||||
Group=systemd-journal-remote
|
||||
ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG --output=/var/log/journal/remote/%i.journal
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
use App\Entity\BootServer;
|
||||
use App\Entity\DhcpServer;
|
||||
use App\Entity\ImageRepository;
|
||||
use App\Service\JournalPullService;
|
||||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use Doctrine\ORM\Event\PostRemoveEventArgs;
|
||||
use Doctrine\ORM\Event\PostUpdateEventArgs;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
|
||||
#[AsDoctrineListener(event: Events::postPersist)]
|
||||
#[AsDoctrineListener(event: Events::postRemove)]
|
||||
#[AsDoctrineListener(event: Events::preUpdate)]
|
||||
#[AsDoctrineListener(event: Events::postUpdate)]
|
||||
class JournalPullSubscriber
|
||||
{
|
||||
/** @var array<int, array{old: string, new: string}> */
|
||||
private array $pendingIpChanges = [];
|
||||
|
||||
public function __construct(private readonly JournalPullService $journalPullService) {}
|
||||
|
||||
private function supports(object $entity): bool
|
||||
{
|
||||
return $entity instanceof BootServer
|
||||
|| $entity instanceof DhcpServer
|
||||
|| $entity instanceof ImageRepository;
|
||||
}
|
||||
|
||||
public function postPersist(PostPersistEventArgs $args): void
|
||||
{
|
||||
$entity = $args->getObject();
|
||||
if (!$this->supports($entity)) {
|
||||
return;
|
||||
}
|
||||
$this->journalPullService->add($entity->getIp());
|
||||
}
|
||||
|
||||
public function postRemove(PostRemoveEventArgs $args): void
|
||||
{
|
||||
$entity = $args->getObject();
|
||||
if (!$this->supports($entity)) {
|
||||
return;
|
||||
}
|
||||
$this->journalPullService->remove($entity->getIp());
|
||||
}
|
||||
|
||||
public function preUpdate(PreUpdateEventArgs $args): void
|
||||
{
|
||||
$entity = $args->getObject();
|
||||
if (!$this->supports($entity) || !$args->hasChangedField('ip')) {
|
||||
return;
|
||||
}
|
||||
$this->pendingIpChanges[spl_object_id($entity)] = [
|
||||
'old' => $args->getOldValue('ip'),
|
||||
'new' => $args->getNewValue('ip'),
|
||||
];
|
||||
}
|
||||
|
||||
public function postUpdate(PostUpdateEventArgs $args): void
|
||||
{
|
||||
$entity = $args->getObject();
|
||||
if (!$this->supports($entity)) {
|
||||
return;
|
||||
}
|
||||
$oid = spl_object_id($entity);
|
||||
if (!isset($this->pendingIpChanges[$oid])) {
|
||||
return;
|
||||
}
|
||||
['old' => $oldIp, 'new' => $newIp] = $this->pendingIpChanges[$oid];
|
||||
unset($this->pendingIpChanges[$oid]);
|
||||
|
||||
$this->journalPullService->remove($oldIp);
|
||||
$this->journalPullService->add($newIp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class JournalPullService
|
||||
{
|
||||
private const CONFIG_FILE = '/opt/opengnsys/ogcore/etc/journal-pull-sources.conf';
|
||||
|
||||
public function __construct(private readonly LoggerInterface $logger) {}
|
||||
|
||||
public function add(string $ip): void
|
||||
{
|
||||
$ips = $this->readIps();
|
||||
if (in_array($ip, $ips, true)) {
|
||||
return;
|
||||
}
|
||||
$ips[] = $ip;
|
||||
$this->writeIps($ips);
|
||||
$this->logger->info('journal-pull: added {ip}', ['ip' => $ip]);
|
||||
}
|
||||
|
||||
public function remove(string $ip): void
|
||||
{
|
||||
$ips = $this->readIps();
|
||||
$filtered = array_values(array_filter($ips, fn($i) => $i !== $ip));
|
||||
if (count($filtered) === count($ips)) {
|
||||
return;
|
||||
}
|
||||
$this->writeIps($filtered);
|
||||
$this->logger->info('journal-pull: removed {ip}', ['ip' => $ip]);
|
||||
}
|
||||
|
||||
private function readIps(): array
|
||||
{
|
||||
if (!file_exists(self::CONFIG_FILE)) {
|
||||
return [];
|
||||
}
|
||||
$lines = file(self::CONFIG_FILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
return array_values(array_filter($lines, fn($l) => !str_starts_with(trim($l), '#')));
|
||||
}
|
||||
|
||||
private function writeIps(array $ips): void
|
||||
{
|
||||
$dir = dirname(self::CONFIG_FILE);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
file_put_contents(
|
||||
self::CONFIG_FILE,
|
||||
$ips ? implode("\n", $ips) . "\n" : '',
|
||||
LOCK_EX
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue