Magellan Linux

Annotation of /mcore-src/trunk/mcore-tools/src/modules/citrix/citrix-cron.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2697 - (hide annotations) (download)
Wed Dec 16 13:50:20 2015 UTC (8 years, 4 months ago) by niro
File size: 2728 byte(s)
-use lock files to prevent race-conditions of the cronjobs
1 niro 2526 #!/bin/bash
2    
3     MCORE_LIBDIR="@@MCORE_LIBDIR@@"
4     source @@SYSCONFDIR@@/mcore/mcore.conf
5     source @@SYSCONFDIR@@/mcore/citrix.conf
6     source @@SYSCONFDIR@@/mcore/citrix-enumerate.conf
7     source @@SYSCONFDIR@@/mcore/control.conf
8     source ${MCORE_LIBDIR}/include/common.global.class
9     source ${MCORE_LIBDIR}/include/daemon.global.class
10     source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class
11    
12     : ${CITRIX_BROWSER=""}
13     : ${CITRIX_USER=""}
14     : ${CITRIX_PASS=""}
15     : ${CITRIX_DOMAIN=""}
16    
17     export IMPORTED_IDS=""
18    
19 niro 2697 LOCKFILE="@@RUNDIR@@/citrix-cron.lock"
20    
21 niro 2526 is_not_an_import_id()
22     {
23     local id="$1"
24     local entry
25    
26     for entry in ${IMPORTED_IDS}
27     do
28     if [[ ${entry} = ${id} ]]
29     then
30     return 1
31     fi
32     done
33    
34     return 0
35     }
36    
37 niro 2697 # the lockfile is not meant to be perfect, it's just in case the
38     # two cron scripts get run close to each other to keep
39     # them from stepping on each other's toes.
40     [[ -f ${LOCKFILE} ]] && exit 0
41    
42     trap "{ rm -f ${LOCKFILE}; exit 0; }" EXIT
43     touch ${LOCKFILE}
44    
45 niro 2526 # get default settings from configs
46     [[ -z ${CITRIX_BROWSER} ]] && export CITRIX_BROWSER="${PNABROWSE_CITRIX_BROWSER}"
47     [[ -z ${CITRIX_USER} ]] && export CITRIX_USER="${MCORE_CITRIX_USER}"
48     [[ -z ${CITRIX_PASS} ]] && export CITRIX_PASS="${MCORE_CITRIX_PASS}"
49     [[ -z ${CITRIX_DOMAIN} ]] && export CITRIX_DOMAIN="${MCORE_CITRIX_DOMAIN}"
50    
51     OPT=""
52     [[ -n ${CITRIX_USER} ]] && OPT+=" -U ${CITRIX_USER}"
53     [[ -n ${CITRIX_PASS} ]] && OPT+=" -P ${CITRIX_PASS}"
54     [[ -n ${CITRIX_DOMAIN} ]] && OPT+=" -D ${CITRIX_DOMAIN}"
55     SESSION_LIST=$(pnabrowse -A ${OPT} ${CITRIX_BROWSER} 2> /dev/null)
56     if [[ $? != 0 ]]
57     then
58     echo "could not retrieve session list"
59     exit 1
60     fi
61    
62     # exclude the desktop session, which is always the first
63     declare -i counter=0
64     while read line
65     do
66     if [[ ${counter} -gt 0 ]]
67     then
68     session=$(echo ${line} | cut -d"'" -f 2)
69     description=""
70    
71     # import or update db entry
72     id=$(mysqldo "select id from values_citrix_session where session='${session}';")
73     if [[ -z ${id} ]]
74     then
75     mysqldo "insert into values_citrix_session (session,description,enabled) values('${session}','${description}','1');"
76     else
77     mysqldo "update values_citrix_session set session='${session}',description='${description}',enabled='1' where id='${id}';"
78     fi
79    
80     # get and save id
81     id=$(mysqldo "select id from values_citrix_session where session='${session}';")
82     export IMPORTED_IDS+=" ${id}"
83     fi
84     (( counter++ ))
85     done << EOF
86     $(echo "${SESSION_LIST}")
87     EOF
88    
89     # now disable all other ids in the database
90     DATABASE_IDS=$(mysqldo "select id from values_citrix_session")
91     for id in ${DATABASE_IDS}
92     do
93     if is_not_an_import_id "${id}"
94     then
95     # disable this one, not imported=not existing on the storefront-server in the moment
96     mysqldo "update values_citrix_session set enabled='0' where id='${id}';"
97     fi
98     done
99 niro 2697
100     exit 0