Exemplo n.º 1
0
async def on_ready():
    logger.info('Logged in as')
    logger.info(f'User: {bot.user.name}')
    logger.info(f'ID: {bot.user.id}')
    logger.info('----------------------')
    if args[0].systemd:
        notify(Notification.READY)
Exemplo n.º 2
0
 def stop(self, *args):
     self.logger.info("Stopping...")
     notify(Notification.STOPPING)
     self.is_running = False
     self.object_detection.stop()
     if self.video_file_thread:
         self.video_file_thread.stop(upload=False)
     self.capture.release()
Exemplo n.º 3
0
 def run(self):
     self.running = True
     pidfile = "/tmp/ips-nodefacade.pid"
     with open(pidfile, 'w') as f:
         f.write(str(getpid()))
     self.start()
     daemon.notify(SYSTEMD_READY)
     while self.running:
         self.registry.update_ptp()
         time.sleep(1)
     os.unlink(pidfile)
    def start(self):
        # do something specific to app startup
        sleep(2)

        # tell systemd we're ready
        notify(Notification.READY)
        self.log.info("Ready")

        count = 1
        while True:
            self.log.info("Running... {}".format(count))
            notify(Notification.STATUS, "STATUS=Count is {}".format(count))
            notify(Notification.WATCHDOG)
            count += 1
            sleep(2)
            if count == 10:
                break

        # wait 15s until watchdog kicks in (after 12s of inactivity - set in
        # unit file) and restart this service
        sleep(15)

        # if you'd like to stop properly
        self.stop()
Exemplo n.º 5
0
import sys
import time
import pydbus
from gi.repository import GLib
from cysystemd.daemon import notify, Notification


def update_daemon(value):
    try:
        pydbus.SystemBus().get("us.rbasn.systemd.test").receive_signal(value)
    except GLib.Error:
        print("Failed to connect to signal.")


option = sys.argv[1]

if option == "start":
    counter = 0
    notify(Notification.READY)
    notify(Notification.STATUS, "Starting systemd_test...")
    while True:
        counter += 1
        notify(Notification.STATUS, "Notification #: %6s" % str(counter))
        update_daemon("Count: %+6s" % counter)
        time.sleep(5)

else:
    notify(Notification.STATUS, "Stopping systemd_test.")
    notify(Notification.STOPPING)
    # sys.exit(0)
Exemplo n.º 6
0
def ready():
    if not daemon:
        return
    daemon.notify(daemon.Notification.READY)
Exemplo n.º 7
0
def stopping():
    if not daemon:
        return
    daemon.notify(daemon.Notification.STOPPING)
 def stop(self):
     # tell systemd we're stopping service
     self.log.info('Stopping...')
     notify(Notification.STOPPING)
Exemplo n.º 9
0
async def on_ready():
    await bot.change_presence(activity=Game(name=prefix + "help for usage."))
    notify(Notification.READY)
    print(f" --- Logged in: {bot.user.name} | {bot.user.id} | {version} --- ")
Exemplo n.º 10
0
    def loop(self):
        self.open_video_source()

        self.logger.info("entering loop")
        failure_counter = 0
        active_event = False
        last_motion_counter = 0
        frame_counter = 0
        event_id = 0
        self.is_running = True
        notify(Notification.READY)
        queue_notification(
            func=slack_notification,
            arguments={
                "webhook_url": self.slack_webhook_url,
                "text": "Started"
            },
            logger=self.logger,
        )
        while self.is_running:
            if failure_counter > 10:
                self.open_video_source()

            retval, frame = self.capture.read()
            if not retval:
                self.logger.warn("%s failed to receive image" %
                                 datetime.datetime.now())
                time.sleep(1)
                failure_counter += 1
                continue
            frame_counter += 1
            last_time = time.time()
            now = datetime.datetime.now()
            notify(Notification.WATCHDOG)

            time_str = now.strftime("%Y%m%d/%H%M%S")
            # todo: run motion detection only on every X frame

            if active_event and self.object_detection.is_busy:
                # self.logger.debug("fast forward, skipping motion")
                self.video_file_thread.queue_frame(frame=frame)
                continue
            # else:
            #    self.logger.debug("normal frame")

            motion, mask_frame = self.detect_motion(frame)
            failure_counter = 0

            time_diff = time.time() - last_time

            if motion is not False:
                last_motion_counter = 0
                self.logger.info(
                    "motion %s took %0.3f sec (=%0.1f/s), result %s" %
                    (time_str, time_diff, (1 / time_diff), motion))

            else:
                last_motion_counter += 1

                if last_motion_counter > 10 * self.video_fps and active_event:
                    self.logger.info("no motion for %i frames" %
                                     last_motion_counter)
                    if self.object_detection.is_busy:
                        self.logger.info(
                            "but object detection busy, waiting...")
                    else:
                        self.logger.debug(
                            self.object_detection.output_queue[event_id])
                        object_detection_keys = list(
                            self.object_detection.output_queue[event_id].keys(
                            ))
                        objects_detected = []
                        while len(object_detection_keys) > 0:
                            frame_id = object_detection_keys.pop(0)
                            result = self.object_detection.output_queue[
                                event_id][frame_id]
                            if len(result) == 0:
                                continue
                            # self.logger.info(json.dumps(result, indent=2))
                            for obj in result:
                                # bear (0.456)
                                objects_detected.append("%s (%s)" %
                                                        (obj[0], obj[1]))
                        if len(objects_detected) > 0:
                            self.video_file_thread.stop(
                                upload=True,
                                notification_text="Event ended, detected %s" %
                                ", ".join(objects_detected))
                        else:
                            self.video_file_thread.stop(upload=False)
                            """
                            notification.slack_notification(webhook_url=self.slack_webhook_url,
                                                            text="Event ended without detected object")
                            """

                        self.video_file_thread = None
                        active_event = False
                        del self.object_detection.output_queue[event_id]

                        self.logger.info(
                            "===========================================")
                        continue
                elif not motion and not active_event:
                    continue

            if active_event is False:
                active_event = True
                event_id += 1
                self.video_file_thread = VideoWriterThread(
                    video_file_name="%s" % time_str,
                    fps=self.video_fps,
                    storage_bucket=storage_bucket,
                    slack_webhook_url=self.slack_webhook_url,
                    logger=self.logger)
                self.video_file_thread.start()
                """
                res, mask_bytes = cv2.imencode('.jpg', mask_frame.astype(numpy.uint8))
                image_url = self.storage_bucket.upload_bytes(data_bytes=mask_bytes,
                                                 remote_file_name=f"{time_str}-mask.jpg"
                                                 )
                notification.slack_notification(webhook_url=self.slack_webhook_url,
                                                text=f"Event started\n<{image_url}|open>")
                """
            self.video_file_thread.queue_frame(frame=mask_frame)

            if self.object_detection.is_busy:
                # print("object detection busy")
                pass
            elif motion:
                self.logger.info("running object detection")
                self.object_detection.process_image(event_id=event_id,
                                                    frame_id=frame_counter,
                                                    frame=frame,
                                                    roi=config['roi'])
        self.logger.info("Loop ended")