Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rglaserIoT committed Nov 27, 2023
1 parent 001b670 commit 7e48b80
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
9 changes: 9 additions & 0 deletions etc/systemd/system/execute_start_scripts.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=gateway customer start script executor

[Service]
Type=oneshot
ExecStart=python -m strtscrptexec --directory=/data/p1/etc/rc.start.d

[Install]
WantedBy=multi-user.target
Empty file.
39 changes: 39 additions & 0 deletions execute_start_scripts/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
execute_start_scripts - IoTmaxx Gateway Hardware Abstraction Layer
Copyright (C) 2023 IoTmaxx GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from .executeStartScripts import executeStartScripts
import logging

log = logging.getLogger()
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(asctime)s %(levelname)-6s %(name)-20s: %(message)s')
formatter.converter = time.gmtime
# add formatter to ch
ch.setFormatter(formatter)

log.addHandler(ch)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Start script executor.")
parser.add_argument('--directory', default='/data/p1/etc/rc.start.d')
args = parser.parse_args()

executeStartScripts(args.directory)
45 changes: 45 additions & 0 deletions execute_start_scripts/executeStartScripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
execute_start_scripts - IoTmaxx Gateway Hardware Abstraction Layer
Copyright (C) 2023 IoTmaxx GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import argparse
import logging
import time
import os
import subprocess

log = logging.getLogger(__name__)

def executeStartScripts(scriptPath):
if not os.path.isdir(scriptPath):
log.info(f"Script path {scriptPath} does not exist.")
return
for entry in os.scandir(scriptPath):
if not entry.is_file():
log.debug(f"Ignoring {entry.path}, not a file.")
continue
if not os.access(entry, os.X_OK):
log.debug(f"Ignoring {entry.path}, not executable.")
continue
log.info(f"Executing {entry.path}.")
try:
result = subprocess.run([entry.path])
except Exception as e:
log.error(f"Execution of {entry.path} failed with error {e}.")
else:
log.info(f"{entry.path} exited with result code {result.returncode}.")


1 change: 1 addition & 0 deletions execute_start_scripts/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__="0.1.0"
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
execute_start_scripts - IoTmaxx Gateway Hardware Abstraction Layer
Copyright (C) 2023 IoTmaxx GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from setuptools import setup, find_packages

version = {}
with open("execute_start_scripts/version.py") as fp:
exec(fp.read(), version)

setup(
name='strtscrptexec',
version=version['__version__'],
url='https://github.com/iotmaxx/execute-start-scripts',
author='Ralf Glaser',
author_email='glaser@iotmaxx.de',
description='gateway customer start script executor',
packages=find_packages(),
install_requires=[
],
)

0 comments on commit 7e48b80

Please sign in to comment.