Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nir0s/serv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.2.0
Choose a base ref
...
head repository: nir0s/serv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 52 files changed
  • 2 contributors

Commits on Apr 26, 2016

  1. Update README.md

    nir0s committed Apr 26, 2016
    Copy the full SHA
    db9f537 View commit details

Commits on May 20, 2016

  1. Added appveyor shield

    nir0s committed May 20, 2016
    Copy the full SHA
    9db3135 View commit details

Commits on Nov 1, 2016

  1. v0.3.0

    nir0s committed Nov 1, 2016
    Copy the full SHA
    4d75af9 View commit details
  2. Merge pull request #18 from nir0s/rearrange-code

    v0.3.0
    nir0s authored Nov 1, 2016
    Copy the full SHA
    1c502dc View commit details

Commits on Nov 22, 2016

  1. Prepare for v0.3.0 release

    nir0s committed Nov 22, 2016
    Copy the full SHA
    9bd8352 View commit details

Commits on Nov 23, 2016

  1. Increase code health

    nir0s committed Nov 23, 2016
    Copy the full SHA
    1f76277 View commit details
  2. Fix exception formatting

    nir0s committed Nov 23, 2016
    Copy the full SHA
    6d525e8 View commit details
  3. Fix ordering of skipping tests since some skips require testing only …

    …linux enabled stuff
    nir0s committed Nov 23, 2016
    Copy the full SHA
    abcd6e2 View commit details
  4. Merge pull request #19 from nir0s/fix-skipping-windows-tests

    Fix ordering of skipping tests since some skips require testing only …
    nir0s authored Nov 23, 2016
    Copy the full SHA
    7af724e View commit details
Showing with 1,113 additions and 2,579 deletions.
  1. +0 −3 .coveragerc
  2. +13 −0 .travis.yml
  3. +0 −77 CHANGELOG
  4. +18 −0 CHANGES.txt
  5. +46 −11 Makefile
  6. +30 −22 README.md
  7. +9 −0 codecov.yml
  8. +3 −5 dev-requirements.txt
  9. +30 −42 serv/constants.py
  10. +0 −546 serv/dictconfig.py
  11. +2 −0 serv/exceptions.py
  12. +0 −4 serv/init/__init__.py
  13. +47 −68 serv/init/base.py
  14. +20 −17 serv/init/nssm.py
  15. +29 −40 serv/init/systemd.py
  16. +18 −56 serv/init/sysv.py
  17. 0 serv/init/templates/{nssm_default.bat → nssm.bat}
  18. 0 serv/init/templates/{systemd_default → systemd}
  19. 0 serv/init/templates/{systemd_default.service → systemd.service}
  20. 0 serv/init/templates/{sysv_default → sysv}
  21. 0 serv/init/templates/{sysv_default.defaults → sysv.defaults}
  22. +0 −168 serv/init/templates/sysv_lsb-3.1
  23. 0 serv/init/templates/{upstart_1.5.conf → upstart.conf}
  24. +0 −45 serv/init/templates/upstart_default.conf
  25. +22 −55 serv/init/upstart.py
  26. +0 −73 serv/logger.py
  27. +281 −291 serv/serv.py
  28. +0 −729 serv/six.py
  29. +0 −1 serv/tests/resources/SuSE-release
  30. 0 serv/tests/resources/arch-release
  31. +0 −1 serv/tests/resources/centos-release
  32. +0 −1 serv/tests/resources/centos5-release
  33. +0 −1 serv/tests/resources/debian_version
  34. 0 serv/tests/resources/exherbo-release
  35. +0 −14 serv/tests/resources/fedora-os-release
  36. +0 −1 serv/tests/resources/fedora-release
  37. +0 −5 serv/tests/resources/lsb-release
  38. +0 −1 serv/tests/resources/oracle-release
  39. +0 −15 serv/tests/resources/redhat-os-release
  40. +0 −1 serv/tests/resources/redhat-release
  41. +0 −1 serv/tests/resources/redhat6-release
  42. +0 −1 serv/tests/resources/slackware-version
  43. +0 −10 serv/tests/resources/suse-os-release
  44. +0 −9 serv/tests/resources/ubuntu-os-release
  45. +0 −250 serv/tests/test_serv.py
  46. +5 −0 setup.cfg
  47. +27 −11 setup.py
  48. 0 {serv → }/tests/__init__.py
  49. +69 −0 tests/mock_system.py
  50. +93 −0 tests/test_deploy.py
  51. +327 −0 tests/test_serv.py
  52. +24 −4 tox.ini
3 changes: 0 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[run]
omit = serv/six.py
serv/dictconfig.py
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# sudo is required here since you must have elevated privileges to create the services during testing
sudo: required
language: python
python:
- "2.7"
matrix:
include:
- python: 3.5
env:
- TOX_ENV=py35
- python: 3.4
env:
- TOX_ENV=py34
env:
- TOX_ENV=flake8
- TOX_ENV=py27
- TOX_ENV=py26
install:
- pip install tox
- sudo pip install tox
- pip install codecov
- coverage combine
script:
- tox -e $TOX_ENV
- sudo tox -e deploy
after_success:
- codecov
77 changes: 0 additions & 77 deletions CHANGELOG

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
**0.3.0 (2016-11-22)**

* Add support for Python 3
* Remove support for different versions of different init systems. This seems like a redundant feature considering the the only difference is between Upstart versions (1 vs. 1.5 etc..) and that becomes irrelevant soon.
* Fix niceness limits check (never performed the check at all)
* Fix bug where if no environment variables are provided using the API, Serv would crash.
* Fix a bug where, in some situations, Serv will fail if it couldn't identify a supported init system.
* Fix a bug where serv will not fallback to auto-detection if it couldn't find a supported distribution in the static map.
* Show tracebacks if using Serv directly from Python (as opposed to when using the CLI).
* Replaced auto-detection of supported init system implementations with a static one to simplify things. There's really no need for such a complex mechanism.
* Updated to distro v1.0.1
* Updated click to v6.6
* Use pytest for tests instead of nose
* Add codecov.io coverage reports
* Add requires.io requirements monitoring
* Add landscape.io code health monitoring
* Added classifiers to setup.py
* Added setup.cfg for wheel release
57 changes: 46 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,62 @@
.PHONY: release install files test docs prepare publish
# Copyright 2015,2016 Nir Cohen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

all:
@echo "make release - prepares a release and publishes it"
@echo "make dev - prepares a development environment (includes tests)"
@echo "make instdev - prepares a development environment (no tests)"
@echo "make install - install on local system"
@echo "make test - run tox"
@echo "make publish - upload to pypi"
# Name of this package
PACKAGENAME = ghost

.PHONY: help
help:
@echo 'Please use "make <target>" where <target> is one of'
@echo " release - build a release and publish it"
@echo " dev - prepare a development environment (includes tests)"
@echo " instdev - prepare a development environment (no tests)"
@echo " install - install into current Python environment"
@echo " test - test from this directory using tox, including test coverage"
@echo " publish - upload to PyPI"
@echo " clean - remove any temporary build products"

.PHONY: release
release: publish
@echo "$@ done."

.PHONY: dev
dev: instdev test
@echo "$@ done."

.PHONY: instdev
instdev:
pip install -rdev-requirements.txt
pip install -r dev-requirements.txt
python setup.py develop
@echo "$@ done."

.PHONY: install
install:
python setup.py install
@echo "$@ done."

.PHONY: test
test:
pip install tox==1.7.1
sudo pip install 'tox>=1.7.2'
tox
@echo "$@ done."

.PHONY: publish
publish:
python setup.py sdist upload
python setup.py sdist upload
@echo "$@ done; uploaded the package to PyPI."

.PHONY: clean
clean:
rm -rf build $(PACKAGENAME).egg-info
@echo "$@ done."
52 changes: 30 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Serv
====

[![Build Status](https://travis-ci.org/nir0s/serv.svg?branch=master)](https://travis-ci.org/nir0s/serv)
[![PyPI](http://img.shields.io/pypi/dm/serv.svg)](http://img.shields.io/pypi/dm/serv.svg)
[![PypI](http://img.shields.io/pypi/v/serv.svg)](http://img.shields.io/pypi/v/serv.svg)
[![Travis Build Status](https://travis-ci.org/nir0s/serv.svg?branch=master)](https://travis-ci.org/nir0s/serv)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/v9uj7uwxq80d9u5n/branch/master?svg=true)](https://ci.appveyor.com/project/nir0s/serv/branch/master)
[![PyPI Version](http://img.shields.io/pypi/v/serv.svg)](http://img.shields.io/pypi/v/serv.svg)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/serv.svg)](https://img.shields.io/pypi/pyversions/serv.svg)
[![Requirements Status](https://requires.io/github/nir0s/serv/requirements.svg?branch=master)](https://requires.io/github/nir0s/serv/requirements/?branch=master)
[![Code Coverage](https://codecov.io/github/nir0s/serv/coverage.svg?branch=master)](https://codecov.io/github/nir0s/serv?branch=master)
[![Code Quality](https://landscape.io/github/nir0s/serv/master/landscape.svg?style=flat)](https://landscape.io/github/nir0s/serv)
[![Is Wheel](https://img.shields.io/pypi/wheel/ghost.svg?style=flat)](https://pypi.python.org/pypi/ghost)


Serv creates, removes and manages services on multiple init systems (process managers? service managers? can someone come up with a normal name for this? jeez.)

@@ -18,6 +24,7 @@ The question that Serv tries to answer is: "Why the hell do I have to know init
* Allows to start, stop, restart and remove services.
* Provides both an API and CLI for those purposes.
* Provides an API for retrieving service related information.
* Controls services not generated by Serv.

NOTE: Serv requires sudo/Administrator privileges! (you can't write to /etc/init.d, /lib/systemd/system and the others without root can ya?)

@@ -32,12 +39,11 @@ I intend to add:
* supervisord
* Whichever other system that's giving you (or me) a headache.

Note: On Linux, Serv uses [ld](http://github.com/nir0s/ld) to identify the distribution.
Note: On Linux, Serv uses [distro](http://github.com/nir0s/distro) to identify the distribution.

## Compatibility

Currently, tested on Python 2.6.x and 2.7.x
Will be adding Python 3.x support soon enough.
Currently, tested on Python 2.6, 2.7, 3.4 and 3.5

## Installation

@@ -101,17 +107,18 @@ If name is omitted, the name of the service (and therefore, the names of the fil

#### Generating only

If the `--deploy` flag isn't provided, files for the service will be generated and saved under a temp folder for you to use. This is useful when generating service files for use elsewhere.
If the `--deploy` flag isn't provided, files for the service will be generated and saved under a temp folder for you to use. This is useful when generating service files for using elsewhere.

### Controlling a service

NOTE: Existing services which were not created by Serv can also be controlled.
NOTE: Existing services which were not created by Serv can also be controlled as long as they've served by an init system supported by serv and are in serv-controlled folders.

```shell
$ sudo serv stop MySimpleHTTPServer
INFO - Stopping service: MySimpleHTTPServer...
$ ss -lntp | grep 8000
...

$ sudo serv start MySimpleHTTPServer
INFO - Starting service: MySimpleHTTPServer...
$ ss -lntp | grep 8000
@@ -127,9 +134,7 @@ LISTEN 0 5 *:8000 *:*

### Retrieving a service's status

IMPORTANT NOTE: serv status is current very buggy. Except it to break and please submit issues.

NOTE: Existing services which were not created by Serv can also be controlled this way.
IMPORTANT NOTE: serv status is current very buggy. Expect it to break and please submit issues.


```shell
@@ -162,8 +167,6 @@ $ sudo serv status

### Removing a service

NOTE: Existing services which were not created by Serv can also be controlled this way.

```shell
$ sudo serv remove MySimpleHTTPServer
...
@@ -180,7 +183,6 @@ $ ss -lntp | grep 8000
Windows support is provided via the Non-Sucking Service Manager (nssm).

There are some differences between Windows and Linux support. While the API is practically the same, it still requires the user to be a bit more cautious.

For instance, when providing the `--args` flag, single quotes won't do (e.g. '-m SimpleHTTPServer') but rather doubles must be used and cmd must be loaded as Administrator to be able to install the service as it requires elevated privileges.

It's important to note that deploying a Windows service also deploys nssm itself and will not clean it up if a service is removed as it might be used by other services.
@@ -203,14 +205,14 @@ Since Serv is aware of the init system being used, it also knows which files it

## Caveats and limitations

* Init system identification is not robust. It relies on some assumptions (and as we all know, assumption is the mother of all fuckups). Some OS distributions have multiple init systems (Ubuntu 14.04 has Upstart, SysV and half (HALF!?) of systemd).
* Init system identification is not robust. It relies on some assumptions (and as we all know, assumption is the mother of all fuckups). Some OS distributions have multiple init systems (Ubuntu 14.04 has Upstart, SysV and half (HALF!?) of systemd). Thus, the implementation is based on best effort where static mapping takes precedence over auto-detection. This doesn't mean that auto-detection will not work most of the time.
* Stupidly enough, I have yet to standardize the status JSON returned and it is different for each init system.
* If anything fails during service creation, cleanup is not performed. This will be added in future versions.
* Currently, all errors exit with the same error level. This will be changed soon.

### Missing directories

In some situations, directories related to the specific init system do not exist and should be created. For instance, even if systemd (`systemctl`) is available, `/etc/sysconfig` might not exist. IT IS UP TO THE USER to create those directories if they don't exist as Serv should not change the system on that level. The exception to the rule is with `nssm`, which will create the required dir (`c:\nssm`) for it to operate.
In some situations, directories related to the specific init system do not exist and should be created. For instance, even if systemd (`systemctl`) is available, `/etc/sysconfig` might not exist. IT IS UP TO THE USER to create those directories if they don't exist as Serv should not modify the system on such level. The exception to the rule is with `nssm`, which will create the required dir (`c:\nssm`) for it to operate.

The user will be notified of which directory is missing.

@@ -236,21 +238,27 @@ The directory (`c:\nssm`) will be created for the user in case it doesn't exist.

## Testing

Important note! While you can queitly run unittests on your laptop, running the deploy (integration) tests on your machine requires sudo privileges and may alter your machine.
The `deploy` tests are not meant to run on your laptop but rather in a clear CI environment.

That being said, if you do decide to run them locally, a service will be created according to the init system available on your machine (assuming it's supported) and will be removed when the test is done. For that sole purpose, tox must be run using `sudo` as seen below.

```shell
git clone git@github.com:nir0s/serv.git
cd ld
cd serv
pip install tox
tox
tox -e py26,py27,py34,py35,flake8
sudo tox -e deploy
```

## Contributions..

Pull requests are always welcome to deal with specific distributions or just for general merriment.
Pull requests are always welcome to deal with specific distributions or for general merriment.

### Adding support for additional init-systems.

* Under serv/init, add a file named <init_system_name>.py (e.g. runit.py).
* Implement a class named <init_system_name> (e.g. Runit). See [systemd](https://github.com/nir0s/serv/blob/master/serv/init/systemd.py) as a reference implementation.
* Pass the `Base` class which contains some basic parameter declarations and provides a method for generating files from templates to your class (e.g. `from serv.init.base import Base`).
* Add the relevant template files to `serv/init/templates`. The file names should be formatted as: `<init_system_name>_<init_system_version>.*` (e.g. runit_default).
* In `serv/init/__init__.py`, import the class you implemented (e.g. `from serv.init.runit import Runit`).
* Pass the `Base` class which contains some basic parameter declarations and provides a method for generating files from templates to your class (e.g. `from .base import Base`).
* Add the relevant template files to `serv/init/templates`. The file names should be formatted as: `<init_system_name>.*` (e.g. runit.conf).
* In `serv.py`, import your implementation and add a name mapping to the `INIT_SYSTEM_MAPPING` global with the relevant class.
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
comment: false
coverage:
status:
patch:
default:
target: '90'
project:
default:
target: '90'
8 changes: 3 additions & 5 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
coverage==3.7.1
nose
nose-cov
testfixtures
testtools
pytest
pytest-cov
mock==2.0.0
Loading