PowerCycleCaHK

Bases: KPFFunction

Script which will power cycle the Ca HK detector control system and restart the services. Use as a last resort measure after other troubleshooting measures such as resetting the detector and restarting software have already failed.

KTL Keywords Used:

  • kpfpower.OUTLET_J1%
  • kpfpower.OUTLET_J2%
  • kpfpower.OUTLET_J5%

Scripts Called:

-kpf start/stop/status/restart kpfexpose2 -kpf start/stop/status/restart kpf_hk

Source code in kpf/cahk/PowerCycleCaHK.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class PowerCycleCaHK(KPFFunction):
    '''Script which will power cycle the Ca HK detector control system and
    restart the services. Use as a last resort measure after other
    troubleshooting measures such as resetting the detector and restarting
    software have already failed.

    KTL Keywords Used:

    - `kpfpower.OUTLET_J1%`
    - `kpfpower.OUTLET_J2%`
    - `kpfpower.OUTLET_J5%`

    Scripts Called:

    -`kpf start/stop/status/restart kpfexpose2`
    -`kpf start/stop/status/restart kpf_hk`
    '''
    @classmethod
    def pre_condition(cls, args):
        kpfpower = ktl.cache('kpfpower')
        outlets = [('J1', 'Galil RIO (expose2)'),
                   ('J2', 'Galil Output Bank (expose2)'),
                   ('J5', 'Andor Newton (kpf_hk)'),
                   ]
        for outlet_id, outlet_name in outlets:
            name = kpfpower[f'OUTLET_{outlet_id}_NAME'].read()
            if name.find(outlet_name) < 0:
                raise FailedPreCondition(f"Outlet name: {outlet_id} != '{outlet_name}'")

    @classmethod
    def perform(cls, args):
        log.warning('Stopping kpfexpose2 dispatcher')
        cmd = ['kpf', 'stop', 'kpfexpose2']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")
        if result.returncode != 0:
            raise FailedPostCondition(f"The kpf stop kpfexpose2 command appears to have failed")
        time.sleep(2)

        log.warning('Stopping kpf_hk keyword service')
        cmd = ['kpf', 'stop', 'kpf_hk']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")
        if result.returncode != 0:
            raise FailedPostCondition(f"The kpf stop kpf_hk command appears to have failed")
        time.sleep(2)
        # Get status response for log
        cmd = ['kpf', 'status', 'kpf_hk']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")

        log.warning('Power cycling the Ca HK detector system')
        kpfpower = ktl.cache('kpfpower')
        outlets = [('J5', 'Andor Newton PS'),
                   ('J1', 'kpfexpose2 Galil RIO controller'),
                   ('J2', 'kpfexpose2 Galil output bank'),
                   ]
        for outlet_id, outlet_name in outlets:
            log.info(f"Powering off {outlet_id}: {outlet_name}")
            kpfpower[f'OUTLET_{outlet_id}'].write('Off')
        time.sleep(10)
        for outlet_id, outlet_name in outlets:
            log.info(f"Powering on {outlet_id}: {outlet_name}")
            kpfpower[f'OUTLET_{outlet_id}'].write('On')
            time.sleep(10)

        log.warning('Restarting kpf_hk keyword service')
        cmd = ['kpf', 'restart', 'kpf_hk']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")
        if result.returncode != 0:
            raise FailedPostCondition(f"The kpf restart kpf_hk command appears to have failed")
        time.sleep(10)
        # Get status response for log
        cmd = ['kpf', 'status', 'kpf_hk']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")

        log.warning('Restarting kpfexpose2 keyword service')
        cmd = ['kpf', 'restart', 'kpfexpose2']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")
        if result.returncode != 0:
            raise FailedPostCondition(f"The kpf restart kpfexpose2 command appears to have failed")
        time.sleep(10)
        # Get status response for log
        cmd = ['kpf', 'status', 'kpfexpose2']
        result = subprocess.run(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        log.debug(f"  args: {result.args}")
        log.debug(f"  rtncode: {result.returncode}")
        log.debug(f"  STDOUT: {result.stdout.decode()}")
        log.debug(f"  STDERR: {result.stderr.decode()}")

        log.warning('Resetting Ca HK')
        ResetCaHKDetector.execute({})

    @classmethod
    def post_condition(cls, args):
        pass