Skip to content

Commit 67484cc

Browse files
committed
Add a protection into master crontab
1 parent 96eeb6e commit 67484cc

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

doc/Documentation SellYourSaas - Master and Deployment Servers - EN.asciidoc

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,19 +690,19 @@ Create directories required to store data, backups and archives:
690690

691691
* Create the directory */mnt/diskbackup/backup*:
692692

693-
If an optional dedicated disk was created for the backup (different than disk for home):
693+
If you have not a dedicated disk for backup:
694694

695695
[source, bash]
696696
---------------
697-
mkdir /mnt/diskbackup/backup
697+
mkdir /mnt/diskhome/backup; chown admin /mnt/diskhome/backup;
698+
ln -fs /mnt/diskhome/backup /mnt/diskbackup
698699
---------------
699700

700-
If you have not a dedicated disk for backup:
701+
And if an optional dedicated disk was created for the backup (different than disk for home):
701702

702703
[source, bash]
703704
---------------
704-
mkdir /mnt/diskhome/backup; chown admin /mnt/diskhome/backup;
705-
ln -fs /mnt/diskhome/backup /mnt/diskbackup
705+
mkdir /mnt/diskbackup/backup
706706
---------------
707707

708708
* Create the other directories on the *Deployment* servers:
@@ -3676,15 +3676,15 @@ You must have inside the cron of user *admin* (You can view the cron with *cront
36763676
---------------
36773677
# m h dom mon dow command
36783678
# cron master admin
3679-
*/10 * * * * /home/admin/wwwroot/dolibarr/scripts/cron/cron_run_jobs.php <securitykeydefinedinscheduledjobsetup> anonymousbatch >> /home/admin/wwwroot/dolibarr_documents/cron_run_jobs.php.log 2>&1
3679+
*/10 * * * * [ "$(hostname -I | awk '{print $1}')" = "ip.of.master.server" ] && /home/admin/wwwroot/dolibarr/scripts/cron/cron_run_jobs.php <securitykeydefinedinscheduledjobsetup> anonymousbatch >> /home/admin/wwwroot/dolibarr_documents/cron_run_jobs.php.log 2>&1
36803680
5 5 * * * /home/admin/wwwroot/dolibarr/htdocs/custom/sellyoursaas/scripts/batch_customers.php updatestatsonly >> /home/admin/logs/batch_customers-updatedatabase.log 2>&1
36813681
7 7 * * * /home/admin/wwwroot/dolibarr/htdocs/custom/sellyoursaas/scripts/git_update_sources.sh /home/admin/wwwroot/dolibarr_documents/sellyoursaas/git >> /home/admin/logs/git_update_sources.log 2>&1
36823682
# cron master and deployment admin
36833683
#7 7 * * * /home/admin/wwwroot/dolibarr/htdocs/custom/sellyoursaas/scripts/git_update_sellyoursaas.sh /home/admin/wwwroot >> /home/admin/logs/git_update_sellyoursaas.log 2>&1
36843684
5 0 * * * /home/admin/wwwroot/dolibarr/htdocs/custom/sellyoursaas/scripts/batch_customers.php backupdelete >> /home/admin/logs/batch_customers-backup.log 2>&1
36853685
---------------
36863686

3687-
Note: *securitykeydefinedinscheduledjobsetup* is the value of the key to decide. And *anonymousbatch* is the user dedicated for batch processing. You will set them
3687+
Note: *ip.of.master.server* is the IP of the server so if you clone the server on another instance with another IP, you are sure the batch won't be executed on the new server without a manual change here, *securitykeydefinedinscheduledjobsetup* is the value of the key to decide. And *anonymousbatch* is the user dedicated for batch processing. You will set them
36883688
later on the Dolibarr master.
36893689

36903690

@@ -3714,6 +3714,19 @@ You must have inside the cron of user *admin* (You can view the cron with *cront
37143714
---------------
37153715

37163716

3717+
==== On master and deployment server
3718+
3719+
Add a protection to disable cron tasks if IP of server has changed so if you clone the server on another instance with another IP, you are sure the batch won't be executed on the new server without a manual change here.
3720+
3721+
Create a link to the service file */etc/systemd/system/sellyoursaas-disable-cron-if-wrong-ip.service*:
3722+
3723+
[source,bash]
3724+
---------------
3725+
cd /etc/systemd/system;
3726+
ln -fs /home/admin/wwwroot/dolibarr/htdocs/custom/sellyoursaas/etc/systemd/system/sellyoursaas-disable-cron-if-wrong-ip.service
3727+
---------------
3728+
3729+
37173730
==== Check that launching of cron is ok
37183731

37193732
Take from */etc/crontab* the commands for testing daily, weekly and monthly crontab launches and test by launching manually. For example, with:
@@ -4792,13 +4805,43 @@ glance image-download --file image-myfile-server1.qcow2 aaab785d-8a34-40f5-bdcd-
47924805
ou openstack image save --file image-myfile-server1.qcow2 aaab785d-8a34-40f5-bdcd-0a3c3c350c5a
47934806
---------------
47944807

4808+
To make image smaller
4809+
4810+
[source,bash]
4811+
---------------
4812+
qemu-img info image-myfile-server1.qcow2
4813+
4814+
modprobe nbd max_part=16
4815+
qemu-nbd -c /dev/nbd0 image-myfile-server1.qcow2
4816+
4817+
fdisk -l /dev/nbd0
4818+
mkdir /mnt/myimg;
4819+
4820+
mount /dev/nbd0p1 /mnt/myimg
4821+
rm -rf /mnt/myimg/tmp/*
4822+
rm -f /mnt/myimg/var/log/*.gz /mnt/myimg/var/log/*.log /mnt/myimg/var/log/journal/*
4823+
umount /mnt/myimg
4824+
4825+
zerofree -v /dev/nbd0p1
4826+
4827+
mount /dev/nbd0p1 /mnt/myimg
4828+
ls /mnt/myimg
4829+
umount /mnt/myimg
4830+
4831+
qemu-nbd -d /dev/nbd0
4832+
qemu-img convert -O qcow2 -c image-myfile-server1.qcow2 image-myfile-server1-compacted.qcow2
4833+
qemu-img info image-myfile-server1.qcow2
4834+
---------------
4835+
4836+
47954837
To push an instance's image on a project:
47964838

47974839
[source,bash]
47984840
---------------
47994841
source openrctarget.sh
48004842
export OS_REGION_NAME=SBG1
48014843
glance image-create --name nom_image_snaphot_new_server --disk-format qcow2 --container-format bare --file mon_fichier_snap_serveur1.qcow2
4844+
ou openstack image create --disk-format qcow2 --container-format bare --file votre_image_compacte.qcow2 --public "Nom de votre image"
48024845
---------------
48034846

48044847
To build a volume image, you need to create it from the detached volume (can't use a snapshot)
@@ -4825,6 +4868,7 @@ To push an image on a project:
48254868

48264869

48274870
- To restore
4871+
48284872
openstack server create --flavor FLAVOR_ID --image BACKUP_IMAGE_ID --nic net-id=NETWORK_ID INSTANCE_NAME
48294873

48304874

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Disable cron if IP is not allowed
3+
After=network-online.target
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/bin/bash -c '
8+
IP=$(hostname -I | awk "{print \$1}");
9+
if [ "$IP" != "1.2.3.4" ]; then
10+
systemctl stop cron;
11+
echo "Cron stopped by service /etc/systemd/system/sellyoursaas-disable-cron-if-wrong-ip.service due to wrong IP: $IP" >> /var/log/cron_disabled.log;
12+
fi
13+
'
14+
15+
[Install]
16+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)