Ok so recently I ran into a hiccup with an issue that effects how my jetstream and daemons run on my #friendica instance, as I am still working on the what I created a workaround that makes sure that they run as they should, I am sharing my little script for those who may have issues where their daemon and jetstream keep getting killed, I offer no promise nor support, but for me it is working nicely;
#!/bin/bash
# --- CONFIGURATION (Users change these) ---
# The absolute path to your application root
SITE_ROOT="/path/to/your/app"
# The path to the PHP binary (usually 'php' or a specific version)
PHP_CLI="/usr/bin/php"
# Name of the console executable
CONSOLE_APP="bin/console.php"
# Where to save the logs
LOG_FILE="./guard_log.txt"
# List of services to monitor
SERVICES=("daemon" "jetstream")
# --- CORE LOGIC (Do not edit below) ---
CONSOLE_PHP="$SITE_ROOT/$CONSOLE_APP"
echo "$(date): Persistent Guard started for services: ${SERVICES}" >> "$LOG_FILE"
while true; do
for SERVICE in "${SERVICES[@]}"; do
# Check status
STATUS=$($PHP_CLI $CONSOLE_PHP $SERVICE status 2>&1)
if [[ "$STATUS" != *"is running"* ]]; then
echo "$(date): $SERVICE is DOWN. Attempting start..." >> "$LOG_FILE"
$PHP_CLI $CONSOLE_PHP $SERVICE start >> "$LOG_FILE" 2>&1
fi
done
sleep 60
done
README
Persistent Service Guard
A robust, lightweight Bash-based watchdog script designed to monitor and automatically restart background services (such as Friendica daemons or Jetstream workers) for PHP-based applications.
⚠️ Maintenance Notice
This project is provided "as-is" for educational and personal use.
It will not be maintained or updated.
No support or bug fixes will be provided.
Use at your own risk.
🚀 What It Does
The Service Guard addresses the common issue where background processes or daemons on shared or private hosting may crash or be killed by the system.
Active Monitoring: It loops indefinitely, checking the status of defined services every 60 seconds.
Automatic Recovery: If a service is reported as "not running," the script immediately attempts to restart it.
Logging: Every check, failure, and restart attempt is timestamped and recorded for auditing.
🛠 Setup & Usage
1. Configuration
Before running, ensure the following variables in guard.sh match your environment:
SITE_ROOT: The absolute path to your application root.
PHP_CLI: The path to the PHP binary (e.g., /usr/bin/php).
SERVICES: The names of the services to monitor (e.g., "daemon" "jetstream").
2. Permissions
Grant execution rights to the script:
Bash
chmod +x guard.sh
3. Execution
Run the script in the background to ensure it persists after your session ends:
Bash
nohup ./guard.sh > /dev/null 2>&1 &
📊 Managing Logs
The script appends data to guard_log.txt. To prevent this file from consuming excessive disk space, use one of the following methods:
Manual Truncation
Clear the log without stopping the script:
Bash
> guard_log.txt
Automatic Log Rotation (Improvement Example)
To automate log management, add this logic inside the while loop of the script:
Bash
# Improvement: Simple Log Rotation
MAX_SIZE=1048576 # 1MB in bytes
FILE_SIZE=$(stat -c%s "$LOG_FILE")
if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
echo "$(date): Log rotated (size limit reached)" > "$LOG_FILE"
fi
📈 Potential Improvements
Users wishing to extend the script's functionality can implement the following:
1. Auto-Discovery
Replace the hardcoded PHP_CLI path with dynamic discovery:
Bash
PHP_CLI=$(which php)
2. Failure Notifications
Integrate curl to send alerts to Discord or Telegram when a service fails:
Bash
# Discord Notification Example
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"⚠️ Alert: $SERVICE has crashed. Restarting...\"}" YOUR_WEBHOOK_URL
3. Dependency Validation
Add a check to verify the application exists before the loop starts:
Bash
if [ ! -f "$CONSOLE_PHP" ]; then
echo "Error: Console application not found at $CONSOLE_PHP"
exit 1
fi
⚖️ License (MIT)
Copyright (c) 2026 pasjrwoctx👽 (Philip A. Swiderski Jr.)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@Friendica Support @Friendica Developers @Friendica Admins
You can encourage my continued useless ideas, and by doing so your helping to feed, house and clothe a #disabled man living in #poverty, $5-10-15 It All Helps, via #cashapp at $woctxphotog or via #paypal at https://www.paypal.com/donate?campaign_id=5BN5MB5BVQL22
#!/bin/bash
# --- CONFIGURATION (Users change these) ---
# The absolute path to your application root
SITE_ROOT="/path/to/your/app"
# The path to the PHP binary (usually 'php' or a specific version)
PHP_CLI="/usr/bin/php"
# Name of the console executable
CONSOLE_APP="bin/console.php"
# Where to save the logs
LOG_FILE="./guard_log.txt"
# List of services to monitor
SERVICES=("daemon" "jetstream")
# --- CORE LOGIC (Do not edit below) ---
CONSOLE_PHP="$SITE_ROOT/$CONSOLE_APP"
echo "$(date): Persistent Guard started for services: ${SERVICES}" >> "$LOG_FILE"
while true; do
for SERVICE in "${SERVICES[@]}"; do
# Check status
STATUS=$($PHP_CLI $CONSOLE_PHP $SERVICE status 2>&1)
if [[ "$STATUS" != *"is running"* ]]; then
echo "$(date): $SERVICE is DOWN. Attempting start..." >> "$LOG_FILE"
$PHP_CLI $CONSOLE_PHP $SERVICE start >> "$LOG_FILE" 2>&1
fi
done
sleep 60
done
README
Persistent Service Guard
A robust, lightweight Bash-based watchdog script designed to monitor and automatically restart background services (such as Friendica daemons or Jetstream workers) for PHP-based applications.
⚠️ Maintenance Notice
This project is provided "as-is" for educational and personal use.
It will not be maintained or updated.
No support or bug fixes will be provided.
Use at your own risk.
🚀 What It Does
The Service Guard addresses the common issue where background processes or daemons on shared or private hosting may crash or be killed by the system.
Active Monitoring: It loops indefinitely, checking the status of defined services every 60 seconds.
Automatic Recovery: If a service is reported as "not running," the script immediately attempts to restart it.
Logging: Every check, failure, and restart attempt is timestamped and recorded for auditing.
🛠 Setup & Usage
1. Configuration
Before running, ensure the following variables in guard.sh match your environment:
SITE_ROOT: The absolute path to your application root.
PHP_CLI: The path to the PHP binary (e.g., /usr/bin/php).
SERVICES: The names of the services to monitor (e.g., "daemon" "jetstream").
2. Permissions
Grant execution rights to the script:
Bash
chmod +x guard.sh
3. Execution
Run the script in the background to ensure it persists after your session ends:
Bash
nohup ./guard.sh > /dev/null 2>&1 &
📊 Managing Logs
The script appends data to guard_log.txt. To prevent this file from consuming excessive disk space, use one of the following methods:
Manual Truncation
Clear the log without stopping the script:
Bash
> guard_log.txt
Automatic Log Rotation (Improvement Example)
To automate log management, add this logic inside the while loop of the script:
Bash
# Improvement: Simple Log Rotation
MAX_SIZE=1048576 # 1MB in bytes
FILE_SIZE=$(stat -c%s "$LOG_FILE")
if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
echo "$(date): Log rotated (size limit reached)" > "$LOG_FILE"
fi
📈 Potential Improvements
Users wishing to extend the script's functionality can implement the following:
1. Auto-Discovery
Replace the hardcoded PHP_CLI path with dynamic discovery:
Bash
PHP_CLI=$(which php)
2. Failure Notifications
Integrate curl to send alerts to Discord or Telegram when a service fails:
Bash
# Discord Notification Example
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"⚠️ Alert: $SERVICE has crashed. Restarting...\"}" YOUR_WEBHOOK_URL
3. Dependency Validation
Add a check to verify the application exists before the loop starts:
Bash
if [ ! -f "$CONSOLE_PHP" ]; then
echo "Error: Console application not found at $CONSOLE_PHP"
exit 1
fi
⚖️ License (MIT)
Copyright (c) 2026 pasjrwoctx👽 (Philip A. Swiderski Jr.)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@Friendica Support @Friendica Developers @Friendica Admins
You can encourage my continued useless ideas, and by doing so your helping to feed, house and clothe a #disabled man living in #poverty, $5-10-15 It All Helps, via #cashapp at $woctxphotog or via #paypal at https://www.paypal.com/donate?campaign_id=5BN5MB5BVQL22
Roland Häder🇩🇪
•codetag?