====== Reserves automàtiques per l'estona de manteniment (de 2013-10 a 2022-03) ====== Els scripts i les tasques periòdiques programades (''cron'', ''crontab'') que creaven les reserves setmanals varen estar en funcionament des de finals de 2013 fins principis de març de 2022. Llavors vàrem canviar la freqüència de les recàrregues dels imants i els scripts es varen haver d'adaptar. La informació sobre els nous scripts i tasques periòdiques programades es troba a la pàgina [[sermn_wiki:userpages:marta:reserves_automatiques_manteniment_2022 | Reserves automàtiques per l'estona de manteniment (des de 2022-08)]] Després de veure que les [[sermn_wiki:userpages:marta:reserves_automatiques_rutina | reserves automàtiques per la cua de rutina]] funcionaven correctament, amb la finalitat d'assolir una millor gestió del temps disponible als espectròmetres, m'he decidit a canviar també la forma en què es reserven les estones de manteniment al programa de reserves: * fins ara les estones de manteniment estaven programades als horaris dels espectròmetres i eren fixes; * a partir d'aquest canvi les reserves passen a ser dinàmiques com qualsevol altre reserva. És a dir, si cal, es podran modificar les reserves de les estones de manteniment. Per exemple: * si es canvia el dia de manteniment, sigui perquè el dimecres es festa o per qualsevol altre motiu, es pot editar la reserva i canviar-la de data, i deixar lliure el dimecres al matí; * si la recàrrega de nitrogen líquid finalitza força abans que l'estona reservada, es pot editar la reserva i alliberar l'excés de temps reservat; * si algú vol reservar un espectròmetre el dia de manteniment i l'estona reservada s'ha de facturar, es pot modificar la reserva per manteniment i afegir una reserva a nom del projecte on es carregarà la reserva. **IMPORTANT:** Les reserves per les estones de manteniment es crearan automàticament amb vuit setmanes d'antelació, per tal que, si s'escau, hi hagi prou temps per modificar-les. ===== maintenance_bookings.sh ===== Aquest es el programet que crea les reserves per l'estona de manteniment. S'executa tots els diumenges a les 3 de la matinada, i crea les reserves amb dues setmanes d'antelació per tal que es puguin modificar si s'escau. El programet també envia un correu electrònic indicant si ha pogut fer les reserves. #!/bin/bash # # maintenance_bookings.sh # # (c) 2013, Miquel Cabanas, SeRMN, UAB # # Started writing: 2013/10/28 # Last updated: 2013/10/28 # # This script runs the MySql commands needed to automatically create the # bookings for the spectrometers maintenance tasks, mainly liquid nitrogen # refills. # # To run this script every Sunday 2am append an entry like, # # FIXME 0 3 * * Sun /opt/bmbee-114-1/bin/maintenance_nmr_bookings.sh # # to crontab. This entry means, at minute 0, hour 2, on every (*) day of # the month and on every (*) month of the year, if that day happens to be # a Sunday (day 0), execute the commands in the script file # 'maintenance_nmr_bookings.sh' (this file). # VARIABLES --------------------------------------------------------------- # programs # date=`which date` mail=`which mail` mysql=`which mysql` # email recipients and subject to_address="miquel.cabanas@uab.cat" # cc_address="miriam.perez@uab.cat,pau.nolis@uab.cat,eva.monteagudo@uab.cat" cc_address="miquel.cabanas@gmail.com,miquel.cabanas@uab.es" subject="SeRMN Booking System - Weekly maintenance reservations" # date related variables. This script runs on Sunday, and bookings are made # eight weeks in advance (56 days) on Wednesday from 09:00 to 13:00. Hence, # we need to find those dates so that we can use them later when booking time-slots. # # NOTE: these date variables are not currently used for booking commands, # only for the reporting email messages. today_date=`$date --date='Today' +'%Y/%m/%d'` # 2013/10/28 mon_date_mail=`$date --date='8 week 3 day' +'%a %Y/%m/%d'` # Thu 2013/12/06 mon_weekno=`$date --date='8 week 3 day' +'%V/%Y'` # 52/2013 # Bumblebee booking system database where everything gets stored myuser='*****' mypass='*****' mydb='*****' # INSERT BOOKING ENTRIES IN THE DATABAE ----------------------------------------- $mysql --database=$mydb --user=$myuser --password=$mypass << EOF /* begin transaction */ BEGIN; /* Insert bookings for weekly maintenance tasks in all vertical magnets. */ /* By default, book Wednesday morning from 09:00 to 13:00, 8 weeks in advance */ /* (i.e. 59 days) */ /* Avance DPX-250-QNP (250-AUTO) - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 12, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Avance DPX-250-BACS (250-ROBOT) - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 15, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Avance DPX-360 - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 1, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* AvanceIII 400SB - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 6, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* AvanceII 400WB - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 9, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Avance DRX-500 - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 2, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* AvanceII+ 600 - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 7, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Hypersense DNP - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add( date_add( current_date(), interval 59 day), interval 9 hour), '04:00:00', 17, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* commit transaction */ COMMIT; EOF # MAIL THE SYSTEM AND INSTRUMENT ADMINISTRATORS - ----------------------- # # Report to the system and instrument administrators whether Routine NMR # bookings have been created. # status=$? if [ $status -ne 0 ]; then # mysql command failed. Send an email reporting the failure # $mail -s "$subject" -c $cc_address $to_address << EOM AUTOMATED EMAIL MESSAGE. DO NOT REPLY SeRMN - Universitat Autonoma de Barcelona Failed to allocate time slots for weekly maintenance tasks week $mon_weekno starting: $mon_date_mail. Please, report this issue to the system administrator. EOM else # mysql command suceeded. Send an email reporting that routine # bookings have been created # $mail -s "$subject" -c $cc_address $to_address << EOM AUTOMATED EMAIL MESSAGE. DO NOT REPLY SeRMN - Universitat Autonoma de Barcelona Time slots have been allocated for weekly maintenance tasks on all SeRMN spectrometers for week $mon_weekno starting: $mon_date_mail. EOM fi exit El programet envia el següent correu electrònic si ha aconseguit fer les reserves, -------- Original Message -------- Subject: SeRMN Booking System - Weekly maintenance reservations Date: Sun, 27 Oct 2013 16:54:46 +0300 From: root To: Miquel.Cabanas@uab.cat AUTOMATED EMAIL MESSAGE. DO NOT REPLY SeRMN - Universitat Autonoma de Barcelona Time slots have been allocated for weekly maintenance tasks on all SeRMN spectrometers for week 52/2013 starting: Mon 2013/12/23. i aquest altre missatge en cas contrari, -------- Original Message -------- Subject: SeRMN Booking System - NMR Routine reservations Date: Sun, 27 Oct 2013 16:54:46 +0300 From: root To: Miquel.Cabanas@uab.cat AUTOMATED EMAIL MESSAGE. DO NOT REPLY SeRMN - Universitat Autonoma de Barcelona Failed to allocate time slots for weekly maintenance tasks week 52/2013 starting: Mon 2013/12/23. Please, report this issue to the system administrator. ===== Entrada al registre crontab ===== Aquesta és l'entrada creada al programa ''crontab'' per executar automàticament el programet que crear les reserves (crontab -u root -l): # Bumblebee 1.1.4 - Automated bookings for weekly maintenance tasks. It runs # on Sunday at 03:00. # 0 3 * * Sun /opt/bmbee-114-1/bin/maintenance_bookings.sh ===== Seguretat ===== Per motius de seguretat (el programet conté el nom d'usuari i clau de pas de la base de dades de reserves) la carpeta ''/opt/bmbee-114-1/bin/'' està protegida i té l'accés restringit, * permisos carpeta ''bin'': 700 * permisos fitxer ''maintenance_bookings.sh'': 700 * propietari (user:group): root:root A més, per impedir el seu accés a través del servidor web, la carpeta ''bin'' conté un fitxer ''.htaccess'' amb el següent contingut: order deny,allow deny from all ===== Recreació de les reserves antigues ===== Aquest canvi a l'horari comporta que tots els matins dels dimecres de les setmanes anteriors apareixen ara sense reservar. Com que això podria distorsionar les dades d'ocupació, creo unes reserves automàtiques per substituir els blocs de temps assignats a les tasques de manteniment #!/bin/bash # # create_past_maintenance_bookings.sh # # (c) 2013, Miquel Cabanas, SeRMN, UAB # # Started writing: 2013/10/29 # Last updated: 2013/10/29 # # This script runs the MySql commands needed to create the maintenance # bookings needed to replace the past maintenance periods that were set # in the spectrometer schedules and have been replaced now by real bookings. # # programs date=`which date` mail=`which mail` mysql=`which mysql` # Bumblebee booking system database where everything gets stored myuser='*****' mypass='*****' mydb='*****' # First Wednesday on a particular year firstwed=`$date +%F -d "2013-01-02"` echo "First wednesday (included): $firstwed" # Last Wednesday on a particular year lastwed=`$date +%F -d "2013-10-23 + 1 week"` echo "Last wednesday (excluded): $lastwed" # insert booking entries in the database wed=$firstwed while [[ "$wed" < "$lastwed" ]] ; do echo "Creating booking for date: $wed" $mysql --database=$mydb --user=$myuser --password=$mypass << EOF /* begin transaction */ BEGIN; /* Insert bookings for weekly maintenance tasks in all vertical magnets. */ /* By default, book Wednesday morning from 09:00 to 13:00, 8 weeks in advance */ /* Avance DPX-250-QNP (250-AUTO) - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 12, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Avance DPX-250-BACS (250-ROBOT) - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 15, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Avance DPX-360 - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 1, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* AvanceIII 400SB - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 6, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* AvanceII 400WB - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 9, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Avance DRX-500 - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 2, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* AvanceII+ 600 - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 7, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* Hypersense DNP - Wednesday from 09:00 to 13:00 -> 4 hours */ INSERT INTO bookings(bookwhen, duration, instrument, bookedby, userid, projectid, discount, ip, comments, log, deleted) VALUES (date_add('$wed', interval 9 hour), '04:00:00', 17, 7, 7, 1, 0, '192.168.2.2', 'Weekly maintenance tasks', 'Weekly maintenance tasks', 0); /* commit transaction */ COMMIT; EOF wed=`$date +%F -d "$wed + 1 week"` done exit