From 537827bf373bde122828ccdfd11c4402e572100e Mon Sep 17 00:00:00 2001 From: sinseman44 Date: Sun, 15 Nov 2020 08:52:46 +0000 Subject: [PATCH] add post-install script to launch piplotter as systemd service --- install_scripts/create_service.sh | 7 +++++++ install_scripts/piplotter.service | 12 ++++++++++++ setup.py | 14 +++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 install_scripts/create_service.sh create mode 100644 install_scripts/piplotter.service diff --git a/install_scripts/create_service.sh b/install_scripts/create_service.sh new file mode 100755 index 0000000..86922b2 --- /dev/null +++ b/install_scripts/create_service.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cp -a "install_scripts/piplotter.service" /etc/systemd/system +chown root:root /etc/systemd/system/piplotter.service + +systemctl daemon-reload +systemctl enable piplotter.service diff --git a/install_scripts/piplotter.service b/install_scripts/piplotter.service new file mode 100644 index 0000000..9b10597 --- /dev/null +++ b/install_scripts/piplotter.service @@ -0,0 +1,12 @@ +[Unit] +Description=piplot2D Display Menu and Control + +[Service] +Type=simple +User=root +Group=root +ExecStart=/usr/local/bin/piplotter +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/setup.py b/setup.py index 64d87d6..b80199f 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,15 @@ from setuptools import setup, find_packages +from setuptools.command.install import install +import subprocess +import os + +class CustomInstallCommand(install): + def run(self): + install.run(self) + current_dir_path = os.path.dirname(os.path.realpath(__file__)) + create_service_script_path = os.path.join(current_dir_path, 'install_scripts', 'create_service.sh') + subprocess.check_output([create_service_script_path]) + with open("README.md", "r") as fh: long_description = fh.read() @@ -28,5 +39,6 @@ setup( "https://github.com/sinseman44/PyCNC/archive/v2.0.0.zip#egg=pycnc-2.0.0", ], python_requires='>=3.6', - scripts=['piplotter'] + scripts=['piplotter'], + cmdclass={'install': CustomInstallCommand} )