Script:
#!/bin/bash
## SCron - When normal cron just isnt working ##
#
# Written by L.C. and R.P.
#
## This section builds all of scrons directories and scron.
echo "Generating directories for scron.. "
mkdir /usr/local/scron ;
chmod 700 /usr/local/scron ;
mkdir /usr/local/scron/jobs ;
chmod 700 /usr/local/scron/jobs ;
echo "Building Scron.. "
cat > /usr/local/scron/scron.sh <<\EOF
#!/bin/bash
#Scron - The 5 minute man
while [ 1 -eq 1 ]; do
for a in /usr/local/scron/jobs/*.sh; do
$a
done
sleep 300
done
EOF
chmod 700 /usr/local/scron/scron.sh ;
chattr +a +i /usr/local/scron/scron.sh ;
echo "Creating custom rc.local.. "
cat > /etc/rc.local <
# Scron custom RC.Local
screen -dmS loop /usr/local/scron/scron.sh
exit 0
EOF
## This section is for jobs optionally created upon install.
echo "Generating jobs that will run split_q and fail_restart... "
cat > /usr/local/scron/jobs/split_q.sh <
# Script to run split_q.php
php /usr/local/sendstudio/split_q.php
EOF
chmod 700 /usr/local/scron/jobs/split_q.sh
cat > /usr/local/scron/jobs/failed_restart.sh <
# Script to run fail_restart.php
php /usr/local/sendstudio/cron/fail_restart.php
EOF
chmod 700 /usr/local/scron/jobs/failed_restart.sh ;
## Patch fail_restart.sh so it will run cli send regardless of
## screen sessions.
cat > /usr/local/sendstudio/cron/fail_restart.sh <<\EOF
#!/bin/bash
screen -ls |grep send > /dev/null
if [[ $? == 0 ]]; then
screen -S send -d -m php /usr/local/sendstudio/clisend.php
fi
EOF
## since we have some custom cron jobs initially installed with
## our production installer we remove them.
echo "copying the maint script.. "
cp /usr/local/sendstudio/maint.sh /usr/local/scron/jobs/
echo "removing old cron.. "
rm -rf /etc/cron.d/obey
## Reboot at the end - optionally you could just run the same
## command in rc.local.
echo "Going down for a reboot"
init 6 ;
No comments:
Post a Comment