Skip to content

Commit

Permalink
Fix code review
Browse files Browse the repository at this point in the history
  • Loading branch information
darcato committed Mar 19, 2020
1 parent 3566521 commit b22c3ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
31 changes: 16 additions & 15 deletions procServUtils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,74 +25,75 @@ 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`.

### 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
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
```

### 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
```
28 changes: 13 additions & 15 deletions procServUtils/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -116,15 +116,13 @@ def restartproc(conf, args):
def showlogs(conf, args):
check_req(conf, args)
_log.info("Opening logs of service procserv-%s.service", args.name)
command = [journalctl,
'--user-unit' if args.user else '--unit',
'procserv-%s.service'%args.name]
if args.follow:
command.append('-f')
try:
SP.call(command)
SP.call([journalctl,
'--user-unit' if args.user else '--unit',
'procserv-%s.service'%args.name] +
(['-f'] if args.follow else []))
except KeyboardInterrupt:
pass
pass

def attachproc(conf, args):
check_req(conf, args)
Expand Down Expand Up @@ -155,19 +153,19 @@ 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)

# write conf file
addconf(conf_name, new_conf, args.user, args.force)

# generate service files
# generate service files
outdir = getgendir(args.user)
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',
Expand All @@ -185,7 +183,7 @@ def addproc(conf, args):

def delproc(conf, args):
check_req(conf, args)

for cfile in getconffiles(user=args.user):
_log.debug('delproc processing %s', cfile)

Expand Down Expand Up @@ -233,7 +231,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')
Expand Down Expand Up @@ -267,8 +265,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)

Expand Down

0 comments on commit b22c3ca

Please sign in to comment.