-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
001b670
commit 7e48b80
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__="0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=[ | ||
], | ||
) |