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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
20df85f
Autocomplete with argcomplete
darcato Nov 14, 2019
26de0a1
Autocomplete instances names
darcato Nov 14, 2019
e3bf0a6
Get user configuration during autocomplete
darcato Nov 15, 2019
25be630
Adding logs and restart commands to manage-procs
darcato Nov 15, 2019
551a76a
Reset a failed procServ instance
giosava94 Jan 28, 2020
bbc7f1a
Insert reset-failed in remove func
giosava94 Jan 29, 2020
eea0111
Merge pull request #1 from giosava94/dev
darcato Jan 29, 2020
61e7586
Improving unit removal, fixing some exceptions
darcato Jan 29, 2020
8f05ae4
Pretty table on manage-procs status
darcato Mar 18, 2020
bd6a6cf
Merge branch 'dev'
darcato Mar 18, 2020
9118005
Renameprocs
darcato Mar 18, 2020
ccdc042
Addproc with new addconf utility
darcato Mar 18, 2020
1de88db
Fix rename on unknown process
darcato Mar 18, 2020
656305c
Check existence of requested proc
darcato Mar 19, 2020
f21c49b
Comment with dependencies
darcato Mar 19, 2020
7bb8b16
Merge branch 'dev'
darcato Mar 19, 2020
a16a1ff
Merge branch 'master' of https://github.com/ralphlange/procServ
darcato Mar 19, 2020
91038e1
Double import
darcato Mar 19, 2020
ece589e
Adding procServUtils docs
darcato Mar 19, 2020
32f904a
Link new readmi
darcato Mar 19, 2020
3566521
Typos
darcato Mar 19, 2020
b22c3ca
Fix code review
darcato Mar 19, 2020
ea360cf
Fix travis
darcato Mar 19, 2020
cb602e7
Slightly different conf file spacing
darcato Mar 19, 2020
3f4bb37
Whitespaces
darcato Mar 19, 2020
78b76b3
Fix manage-procs rename docs
darcato Mar 27, 2020
d44c601
Conditional usage of python packages termcolor, tabulate and argcomplete
darcato Nov 6, 2020
5bb72a5
Fix systemctl call order
darcato Nov 9, 2020
4335401
Revert check call on systemctl disable
darcato Nov 9, 2020
ae2c6d9
Updating procServUtils doc
darcato Nov 9, 2020
b3c6f68
Whitespaces
darcato Nov 9, 2020
65153f2
Fix devnull for python2
darcato Nov 9, 2020
15f3dba
Add test for rename command
darcato Nov 9, 2020
182fd78
Ask before stopping service to rename
darcato Nov 9, 2020
bf8bd0a
Fix test errors
darcato Nov 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
- os: linux
language: python
python: 2.7
install: pip install nose
install: pip install nose argcomplete termcolor tabulate
script: python -m nose procServUtils
- os: linux
language: python
python: 3.6
install: pip install nose
install: pip install nose argcomplete termcolor tabulate
script: python -m nose procServUtils
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ start and stop configured procServ instances,
generate lists of the instances known on the current host
and report their status.

For more details, check the manpage and use the script's `-h` option.
For more details, see its [README](procServUtils/README.md) or check the manpage and use the script's `-h` option.

For older systems using SysV-style rc scripts, you can look at the
[Debian packaging](http://epics.nsls2.bnl.gov/debian/) or
Expand Down
1 change: 1 addition & 0 deletions manage-procs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python3
# PYTHON_ARGCOMPLETE_OK

from procServUtils.manage import getargs, main
main(getargs())
141 changes: 141 additions & 0 deletions procServUtils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# procServUtils

`manage-procs` is a script to run procServ instances as systemd services.
It allows to completely manage the service with its command line interface.
See below for the available commands.

## Installation from source

Python prerequisites:

```bash
sudo pip install tabulate termcolor argcomplete
```

Then proceed to build and install procServ with the `--with-systemd-utils` configuration option. For example:

```bash
cd procserv
make
./configure --disable-doc --with-systemd-utils
make
sudo make install
```

**[OPTIONAL]** If you want to activate bash autocompletion run the following command:

```bash
sudo activate-global-python-argcomplete
```

This will activate global argcomplete completion. See [argcomplete documentation](https://pypi.org/project/argcomplete/#activating-global-completion) for more details.

## Using manage-procs

See `manage-procs --help` for all the commands.

### User or system services

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 when running as root.

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

Note that this command will stop the service if it's running.

### 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
```
21 changes: 20 additions & 1 deletion procServUtils/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
_log = logging.getLogger(__name__)

import os
import os, sys, errno
from functools import reduce
from glob import glob

Expand Down Expand Up @@ -53,6 +53,25 @@ def getconffiles(user=False):
# reduce by concatination into a single list
return reduce(list.__add__, map(glob, files), [])

def addconf(name, conf, user=False, force=False):
outdir = getgendir(user)
cfile = os.path.join(outdir, '%s.conf'%name)

if os.path.exists(cfile) and not force:
_log.error("Instance already exists @ %s", cfile)
sys.exit(1)

try:
os.makedirs(outdir)
except OSError as e:
if e.errno!=errno.EEXIST:
_log.exception('Creating directory "%s"', outdir)
raise

_log.info("Writing: %s", cfile)
with open(cfile, 'w') as F:
conf.write(F)

_defaults = {
'user':'nobody',
'group':'nogroup',
Expand Down
19 changes: 19 additions & 0 deletions procServUtils/fallbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Fallback functions when termcolor or tabulate packes are not available
"""


def colored(s, *args, **kwargs):
return s


def tabulate(table, headers, **kwargs):
s = ""
for header in headers:
s += "%s " % header.strip()
s += "\n"
for line in table:
for elem in line:
s += "%s " % elem.strip()
s += "\n"
return s[:-1]
Loading