From 78237cbd5cbd1410bbc5dff5eccd3a81c4b0fa2c Mon Sep 17 00:00:00 2001 From: Davide Marcato Date: Thu, 19 Mar 2020 18:03:13 +0100 Subject: [PATCH] Fix code review --- procServUtils/README.md | 31 ++++++++++++++++--------------- procServUtils/manage.py | 16 ++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/procServUtils/README.md b/procServUtils/README.md index eb6460e..c1aada1 100644 --- a/procServUtils/README.md +++ b/procServUtils/README.md @@ -7,11 +7,11 @@ See below for the available commands. ## Installation Python prerequisites: -``` +```bash sudo pip install tabulate termcolor argcomplete ``` Activate global arcomplete completion: -``` +```bash sudo activate-global-python-argcomplete ``` Then proceed to install procServ with the `--with-systemd-utils` configuration @@ -25,9 +25,10 @@ See `manage-procs --help` for all the commands. All the `manage-procs` commands support one option to specify the destination of the service: -- `manage-procs --system` will manage system-wide services. This is the default options +- `manage-procs --system` will manage system-wide services. This is the default options when running as root. -- `manage-procs --user` will manage user-level services. It is the equivalent + +- `manage-procs --user` will manage user-level services. It is the equivalent of `systemctl --user`. This is the default when running as a non-privileged user. **NOTE:** Not all linux distributions support user level systemd (eg: Centos 7). In those cases you should always use `--system`. @@ -35,7 +36,7 @@ of `systemctl --user`. This is the default when running as a non-privileged user ### Add a service Let's add a service: -``` +```bash manage-procs add service_name some_command [command_args...] ``` This will install a new service called `service_name` which will run the specified command @@ -43,32 +44,32 @@ with its args. With the optional arguments one can specify the working directory, the user running the process and also add some environment variables. For example: -``` +```bash manage-procs add -C /path/to/some_folder -U user_name -G user_group -e "FOO=foo" -e "BAR=bar" service_name some_command [command_args...] ``` Alternatively one can write an environment file like: -``` +```bash FOO=foo BAR=bar ``` And run: -``` +```bash manage-procs add -C /path/to/some_folder -U user_name -G user_group -E /path/to/env_file service_name some_command [command_args...] ``` See `manage-procs add -h` for all the options. ### List services -``` +```bash manage-procs status ``` will list all the services installed with `manage-procs add` and their status. -``` +```bash manage-procs list ``` will show the underlying systemd services. ### Start, stop, restart service exection -``` +```bash manage-procs start service_name manage-procs stop service_name manage-procs restart service_name @@ -76,23 +77,23 @@ manage-procs restart service_name ### Remove or rename a service To uninstall a service: -``` +```bash manage-procs remove service_name ``` To rename a service: -``` +```bash manage-procs rename service_name ``` ### Attach to a service `procServ` enables the user to see the output of the inner command and, eventually, interact with it through a telent port or a domain socket. -``` +```bash manage-procs attach service_name ``` This will automatically open the right port for the desired service. ### Open service log files All the output of the service is saved to the systemd log files. To open them run: -``` +```bash manage-procs logs [--follow] service_name ``` diff --git a/procServUtils/manage.py b/procServUtils/manage.py index 64478b5..36d0b40 100644 --- a/procServUtils/manage.py +++ b/procServUtils/manage.py @@ -82,7 +82,7 @@ def status(conf, args, fp=None): table.append(instance) # Print results table - headers = ['PROCESS', 'STATE', 'PORT'] + headers = ['PROCESS', 'STATUS', 'PORT'] fp.write(tabulate(sorted(table), headers=headers, tablefmt="github")+ '\n') def syslist(conf, args): @@ -122,9 +122,9 @@ def showlogs(conf, args): if args.follow: command.append('-f') try: - SP.call(command) + SP.check_call(command) except KeyboardInterrupt: - pass + pass def attachproc(conf, args): check_req(conf, args) @@ -155,7 +155,7 @@ def addproc(conf, args): if args.username: new_conf.set(conf_name, "user", args.username) if args.group: new_conf.set(conf_name, "group", args.group) if args.port: new_conf.set(conf_name, "port", args.port) - if args.environment: + if args.environment: new_conf.set(conf_name, "environment", ' '.join("\"%s\""%e for e in args.environment)) if args.env_file: new_conf.set(conf_name, "env_file", args.env_file) @@ -167,7 +167,7 @@ def addproc(conf, args): run(outdir, user=args.user) # register systemd service - argusersys = '--user' if args.user else '--system' + argusersys = '--user' if args.user else '--system' SP.check_call([systemctl, argusersys, 'enable', @@ -233,7 +233,7 @@ def delproc(conf, args): SP.call([systemctl, '--user' if args.user else '--system', '--quiet', - 'reset-failed', + 'reset-failed', 'procserv-%s.service'%args.name]) _log.info('Triggering systemd reload') @@ -267,8 +267,8 @@ def renameproc(conf, args): # delete previous proc args.force = True delproc(conf, args) - - # generate service files + + # generate service files outdir = getgendir(args.user) run(outdir, user=args.user)