Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

procServUtils autocomplete and new commands #34

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

darcato
Copy link
Contributor

@darcato darcato commented Mar 19, 2020

Hello,
this PR adds some functionalities to the procServUtils scripts:

  1. Bash autocomplete through argcomplete
  2. New commands to restart, rename or open logs of the processes
  3. Print status as a table with color support, to be easier to read
  4. Fix some unhandled exceptions
  5. Documentation for the commands

To enable these functionalities three python dependencies are needed: argcomplete, tabulate and termcolor. Unfortunately the current installation process does not support installing dependencies so one has to install them manually through pip.

Do you think the installation process can be modified to use pip to automatically handle dependencies?

All the changes here are compatible with existing configuration files and do not break compatibility (hopefully).

@ralphlange
Copy link
Owner

@mdavidsaver and @mark0n, do you have opinions on this? Looks good to me.
Are the additional Python packages (argcomplete, termcolor, tabulate) appropriate and reasonable?

@mdavidsaver
Copy link
Contributor

My first benchmark for dependencies is presence in the Debian package repository. All three have been present since at least Debian 8 (10 is stable atm). argcomplete tabulate termcolor

argcomplete and tabulate appear at a glance to be healthy projects with recent releases and links to VCS repos.

termcolor appears to be defunct, with no release since 2011, and no authoritative VCS repository listed.

@mdavidsaver
Copy link
Contributor

mdavidsaver commented Nov 5, 2020

Personally, I would make this three optional dependencies with some try: ... import. As used, termcolor and argcomplete can be trivially stubbed out, with tabulate being only slightly more involved.

```
Activate global arcomplete completion:
```bash
sudo activate-global-python-argcomplete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step should be named as optional, maybe referring to https://pypi.org/project/argcomplete/#activating-global-completion

fyi. It tries to write /etc/bash_completion.d/python-argcomplete.sh by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will list it as an optional step!

@@ -207,11 +222,18 @@ def delproc(conf, args):
stopproc(conf, args)

_log.info("Disabling service procserv-%s.service", args.name)
SP.check_call([systemctl,
SP.call([systemctl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change to the un-checked call? Have you seen this step fail? As a general rule I don't like the idea of ignoring failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember seeing this fail, but I cannot reproduce the problem now (it was months ago), so for the moment I will revert back to the check_call method.

_log.info('Trigger systemd reload')
SP.check_call([systemctl,
argusersys,
'daemon-reload'], shell=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the ordering here, but I think the daemon-reload should come first. As I understand it, a reload is needed after manually editing any systemd config files, eg. before any new units are recognised.

I'm also wondering it an explicit disable is needed for the original service name? Have you verified that the symlinks are being cleaned up? (eg. ls -l /etc/systemd/system/multi-user.target.wants/)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @mdavidsaver, the order should be:

  1. stop and disable old unit (calling disable is required if we don't want to leave any mess behind)
  2. modify unit files
  3. daemon-reload
  4. enable and start new unit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good catch! I copied this logic from the addproc function, so I will fix the order also on that function.

@@ -29,4 +29,5 @@ def run(self):
('lib/systemd/user-generators', ['systemd-procserv-generator-user']),
],
cmdclass = { 'install_data': custom_install_data },
#install_requires=['argcomplete', 'tabulate', 'termcolor'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are to be unconditional dependencies, then install_requires needs to be uncommentated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that the project uses distutils to install the python scripts, which does not support the install_requires directive. Maybe it's possible to use pip, but I'm not sure how to integrate it with the makefiles.

For the moment I will follow your suggestion to make this packages optional using the try: ... import mechanism and defining some fallback behaviors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya... I was a late and reluctant convert to using setuptools. I had hoped that distutils would be cleaned up to include the useful parts. However, the opposite has happened. With so much external tooling with invasive hooks into distutils, it doesn't seem like it can reasonable be changed. At least setuptools availability is ubiquitous now.

Although I don't think this module will ever be usable in eg. a virtualenv, switching to setuptools is probably reasonable. Doing this may necessitate changes to the custom_install_data though.

@darcato
Copy link
Contributor Author

darcato commented Nov 6, 2020

Hello @mdavidsaver,
thanks for your comments. I will try to address all of them in the following days.

@darcato
Copy link
Contributor Author

darcato commented Nov 9, 2020

I made the three packages optional, adding some fallback functions that emulate almost the same behavior as before this PR.
Then I fixed the systemctl calls order and reverted the check_call on systemctl disable. I also added a test function for the rename command and updated the readme.

I redirected the standard error of the systemctl reset-failed command to /dev/null because this fails when there is nothing to reset (which is the most common situation).

I didn't remove the install_requires comment, as this will be useful when the project will move to setuptools. For the moment I did not implement this change.

@darcato
Copy link
Contributor Author

darcato commented Nov 9, 2020

Lastly, since the rename command causes the service to stop, I added a dialog for the user to confirm the operation, and I added a notice to the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants