Commit 64282fe3 authored by Ana Custura's avatar Ana Custura

New upstream version 0.1

parents
build
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
sudo: true
dist: trusty
language: c++
env:
- DEBUG=1
addons:
apt:
sources:
- deadsnakes
- ubuntu-toolchain-r-test
install:
- sudo apt-get update -qq
- sudo do-release-upgrade -p -f DistUpgradeViewNonInteractive
- sudo apt-get --yes install systemd cmake catch libsystemd-dev libncurses5-dev g++ ssh
script:
- mkdir build; cd build; cmake ../; make; sudo make Test
project(chkservice)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if ($ENV{DEBUG})
message(STATUS "DEBUG mode enabled")
set (CMAKE_CXX_FLAGS "-g -Wall")
else()
message(STATUS "DEBUG mode disabled")
set (CMAKE_CXX_FLAGS "-O2")
endif()
if ($ENV{TRAVIS})
message(STATUS "Travis-CI build.")
else()
message(STATUS "Local build")
endif()
include_directories("${PROJECT_SOURCE_DIR}/include")
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD libsystemd REQUIRED)
include_directories(${SYSTEMD_INCLUDE_DIRS})
set(LIBS ${LIBS} ${SYSTEMD_LIBRARIES})
pkg_check_modules(NCURSES ncurses REQUIRED)
include_directories(${NCURSES_INCLUDE_DIRS})
set(LIBS ${LIBS} ${NCURSES_LIBRARIES})
add_subdirectory(${PROJECT_SOURCE_DIR}/src)
if ($ENV{DEBUG})
message(STATUS "Build testing support")
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
endif()
SET(MAJOR_VERSION 0)
SET(MINOR_VERSION 1)
SET(PATCH_VERSION 0)
IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
SET(CPACK_SET_DESTDIR "on")
SET(CPACK_PACKAGING_INSTALL_PREFIX "/tmp")
SET(CPACK_GENERATOR "DEB")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Ncurses based gui for systemd")
SET(CPACK_PACKAGE_VENDOR "Svetlana Linuxenko")
SET(CPACK_PACKAGE_CONTACT "sveta@linuxenko.pro")
SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}")
SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libncurses5 (>=5), libsystemd0 (>= 222)")
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_PACKAGE_SECTION "utils")
SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
SET(CPACK_COMPONENTS_ALL Libraries ApplicationData)
INCLUDE(CPack)
ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
\ No newline at end of file
chkservice is a tool for managing systemd units.
more infomration at https://github.com/linuxenko/chkservice
Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
chkservice program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
chkservice program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
## chkservice
[![Donate](https://img.shields.io/badge/donate-3$-green.svg?style=flat-square)](https://www.linuxenko.pro/donate.html#?amount=3)
[![screenshot](https://raw.githubusercontent.com/linuxenko/linuxenko.github.io/master/media/chkservice/chkservice.png)](https://raw.githubusercontent.com/linuxenko/linuxenko.github.io/master/media/chkservice/chkservice.png)
> chkservice is a tool for managing systemd units in terminal.
### Installation
```
sudo add-apt-repository ppa:linuxenko/chkservice
sudo apt-get update
sudo apt-get install chkservice
```
### Usage
`chkservice` require super user privileges to make changes into unit states or sysv scripts. For user it works read-only.
### Dependencies
Package dependencies:
* libncurses5
* libsystemd0
Build dependencies:
* pkg-config
* libncurses5-dev
* libsystemd-dev
### Build
Build and install debian package.
```
git clone https://github.com/linuxenko/chkservice.git
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ../
cpack
dpkg -i chkservice-x.x.x.deb
```
Build release version.
```
git clone https://github.com/linuxenko/chkservice.git
mkdir build
cd build
cmake ../
make
```
To build debug version, `DEBUG` environment should be set
```
export DEBUG=1
cmake ....
make Test
```
[![Build Status](https://img.shields.io/travis/linuxenko/chkservice.svg?style=flat-square)](https://travis-ci.org/linuxenko/chkservice) until travis run it on `trusty` based containers
### TODO
- [ ] - `.login1` target support (if someone request it)
### License
GNU General Public License
chkservice is a tool for managing systemd units.
more infomration at https://github.com/linuxenko/chkservice
Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
chkservice (0.1.0.2ppa0ubuntu2) xenial; urgency=medium
* Updated launchpad build dependencies
-- Svetlana Linuxenko <svetlana@linuxenko.pro> Wed, 30 Aug 2017 14:38:21 +0300
chkservice (0.1.0.1ppa0ubuntu1) xenial; urgency=medium
* Reupload first try
-- Svetlana Linuxenko <svetlana@linuxenko.pro> Wed, 30 Aug 2017 14:27:35 +0300
chkservice (0.1.0.0ppa0) sveta; urgency=medium
* Initial release. (Closes: #XXXXXX)
-- Svetlana Linuxenko <svetlana@linuxenko.pro> Wed, 30 Aug 2017 13:36:50 +0300
Source: chkservice
Section: devel
Priority: optional
Maintainer: Svetlana Linuxenko <svetlana@linuxenko.pro>
Build-Depends: pkg-config, cmake, build-essential, libncurses5-dev, libsystemd-dev
Homepage: https://github.com/linuxenko/chkservice
Package: chkservice
Architecture: any
Depends: libncurses5, libsystemd0
Description: Ncurses based gui for systemd
chkservice is a tool for managing systemd units.
more infomration at https://github.com/linuxenko/chkservice
Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
chkservice program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
chkservice program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#!/usr/bin/make -f
BUILDDIR = build_dir
# secondly called by launchpad
build:
mkdir $(BUILDDIR);
cd $(BUILDDIR); cmake -DCMAKE_INSTALL_PREFIX=../debian/tmp/usr ..
make -C $(BUILDDIR)
# thirdly called by launchpad
binary: binary-indep binary-arch
binary-indep:
# nothing to be done
binary-arch:
cd $(BUILDDIR); cmake -P cmake_install.cmake
mkdir debian/tmp/DEBIAN
dpkg-gencontrol -pchkservice
dpkg --build debian/tmp ..
# firstly called by launchpad
clean:
rm -f build
rm -rf $(BUILDDIR)
.PHONY: binary binary-arch binary-indep clean
/*
* chkservice is a tool for managing systemd units.
* more infomration at https://github.com/linuxenko/chkservice
*
* Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
*
* chkservice program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* chkservice program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHK_CTL_H
#define _CHK_CTL_H
#include "chk-systemd.h"
typedef struct UnitItem {
std::string id;
std::string target;
std::string description;
int sub;
int state;
} UnitItem;
enum {
UNIT_STATE_DISABLED = 0x01,
UNIT_STATE_ENABLED = 0x02,
UNIT_STATE_STATIC = 0x03,
UNIT_STATE_BAD = 0x04,
UNIT_STATE_MASKED = 0x05,
UNIT_STATE_TMP = 0x06
};
enum {
UNIT_SUBSTATE_RUNNING = 0x1a,
UNIT_SUBSTATE_CONNECTED = 0x2a,
UNIT_SUBSTATE_INVALID = 0x3a,
UNIT_SUBSTATE_TMP = 0x4a
};
class ChkCTL {
public:
ChkCTL();
~ChkCTL();
ChkBus *bus;
std::vector<UnitItem *> getItemsSorted();
std::vector<UnitItem *> getByTarget(const char *target);
std::vector<UnitItem *> getItems();
void toggleUnitState(UnitItem *item);
void toggleUnitSubState(UnitItem *item);
void fetch();
private:
std::vector<UnitItem *> items;
void pushItem(UnitInfo *unit);
void sortByName(std::vector<UnitItem *> *sortable);
};
#endif
/*
* chkservice is a tool for managing systemd units.
* more infomration at https://github.com/linuxenko/chkservice
*
* Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
*
* chkservice program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* chkservice program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHK_SYSTEMD_H
#define _CHK_SYSTEMD_H
#include <iostream>
#include <set>
#include <vector>
#include <systemd/sd-bus.h>
#define ERR_PREFIX "Failed: "
#define SYSV_INSTALL_EXEC "/lib/systemd/systemd-sysv-install"
enum STATE_FLAGS {
STATE_FLAGS_ENABLE,
STATE_FLAGS_DISABLE,
STATE_FLAGS_DISABLE_ISO
};
typedef struct UnitInfo {
const char *id;
const char *description;
const char *loadState;
const char *activeState;
const char *subState;
const char *unitPath;
const char *state;
} UnitInfo;
class ChkBus {
public:
ChkBus();
~ChkBus();
bool connect();
void disconnect();
bool isConnected();
void setErrorMessage(int status);
void setErrorMessage(const char *message);
std::vector<UnitInfo *> getUnits();
std::vector<UnitInfo *> getUnitFiles();
std::vector<UnitInfo *> getAllUnits();
void disableUnit(const char *name);
void enableUnit(const char *name);
void disableUnits(std::set<std::string> *ids);
void enableUnits(std::set<std::string> *ids);
void startUnit(const char *name);
void stopUnit(const char *name);
void startUnits(std::set<std::string> *ids);
void stopUnits(std::set<std::string> *ids);
static void freeUnitInfo(UnitInfo *unit);
void reloadDaemon();
private:
sd_bus* bus = NULL;
std::string errorMessage;
const char* getState(const char *name);
void applyUnitState(const char *method, char **names, int flags);
void applyUnitSub(const char *name, const char *method);
void checkDisabledStatus(char **names);
};
int busParseUnit(sd_bus_message *message, UnitInfo *u);
void applySYSv(const char *state, const char **names);
#endif
/*
* chkservice is a tool for managing systemd units.
* more infomration at https://github.com/linuxenko/chkservice
*
* Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
*
* chkservice program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* chkservice program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHK_UI_H
#define _CHKUI_H
#include <curses.h>
#include "chk-ctl.h"
typedef struct RECTANGLE {
int x;
int y;
int w;
int h;
} RECTANGLE;
class MainWindow {
public:
static void sigwinch(int c);
WINDOW *win;
MainWindow();
~MainWindow();
void createMenu();
private:
RECTANGLE *screenSize = new RECTANGLE();
RECTANGLE *winSize = new RECTANGLE();
RECTANGLE *padding = new RECTANGLE();
ChkCTL *ctl = new ChkCTL;
std::vector<UnitItem *> units;
int selected = 0;
int start = 0;
void resize();
void moveUp();
void moveDown();
void movePageUp();
void movePageDown();
void drawUnits();
void drawItem(UnitItem *unit, int y);
void drawInfo();
void toggleUnitState();
void toggleUnitSubState();
void updateUnits();
void error(char *err);
void reloadAll();
};
void startCurses();
void stopCurses();
void printInMiddle(WINDOW *win, int starty, int startx, int width,
char *string, chtype color, char *sp);
void aboutWindow(RECTANGLE *parent);
#endif
/*
* chkservice is a tool for managing systemd units.
* more infomration at https://github.com/linuxenko/chkservice
*
* Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
*
* chkservice program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* chkservice program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHK_H
#define _CHK_H
#define VERSION "0.1"
#define ABOUT_INFO "\n\
chkservice %s \n\
\n\
Units list information:\n\
\n\
[x] - enabled unit. [ ] - disabled unit \n\
[s] - static unit. -m- - masked unit \n\
\n\
Navigation keys:\n\
\n\
Up/k - move cursor up. Down/j - move cursor down.\n\
PgUp/b - move page up. PgDown/f - move page down.\n\
\n\
Action keys:\n\
\n\
r - reload/update. q - exit.\n\
Space - enable/disable. s - start/stop unit.\n\
\n\
License:\n\
GPLv3 (c) Svetlana Linuxenko <svetlana(at)linuxenko.pro>"
#endif
add_library(CHKSYSTEMD chk-systemd.cpp chk-systemd-utils.cpp)
target_link_libraries(CHKSYSTEMD ${LIBS})
add_library(CHKCTL chk-ctl.cpp)
target_link_libraries(CHKCTL ${LIBS} CHKSYSTEMD)
add_library(CHKUI chk-wmain.cpp chk-wutils.cpp)
target_link_libraries(CHKUI ${LIBS} CHKSYSTEMD CHKCTL)
add_executable(chkservice chkservice.cpp)
target_link_libraries(chkservice ${LIBS} CHKSYSTEMD CHKCTL CHKUI)
install(TARGETS chkservice RUNTIME DESTINATION sbin)
/*
* chkservice is a tool for managing systemd units.
* more infomration at https://github.com/linuxenko/chkservice
*
* Copyright (C) 2017 Svetlana Linuxenko <svetlana(at)linuxenko.pro>
*
* chkservice program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* chkservice program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "chk-ctl.h"
#include "chk-systemd.h"
ChkCTL::ChkCTL() {
bus = new ChkBus();
items.clear();
}
ChkCTL::~ChkCTL() {
delete bus;
items.clear();
}
std::vector<UnitItem *> ChkCTL::getItems() {
sortByName(&items);
return items;
}
std::vector<UnitItem *> ChkCTL::getByTarget(const char *target) {
std::vector<UnitItem *> found;
std::string pattern = target == NULL ? "" : target;
for (UnitItem *item : items) {
if (item->target.find(pattern) == 0) {
found.push_back(item);
}
}
return found;
}
void ChkCTL::fetch() {
std::vector<UnitInfo *> sysUnits;
for (auto item : items) {
delete item;
}
items.clear();
items.shrink_to_fit();
try {
sysUnits = bus->getAllUnits();
} catch (std::string &err) {
throw err;
}
for (auto unit : sysUnits) {
if (unit->id) {
pushItem(unit);
}
delete unit;
}
sysUnits.clear();
sysUnits.shrink_to_fit();
}
void ChkCTL::sortByName(std::vector<UnitItem *> *sortable) {
std::sort(sortable->begin(), sortable->end(), [](const UnitItem *a, const UnitItem *b) {
const char* s1 = a->id.c_str();
const char* s2 = b->id.c_str();
while(true) {
if ( std::toupper(*s1) < std::toupper(*s2) ) return true;
if ( std::toupper(*s1) > std::toupper(*s2) ) return false;
if ( *s1 == 0 && *s2 == 0 ) return false;
if ( *s1 > *s2) return false;
if ( *s1 < *s2) return true;
++s1; ++s2;
}
});
}
void ChkCTL::pushItem(UnitInfo *unit) {
UnitItem *item = new UnitItem();
std::string id(unit->id);
item->id = id;
item->target = id.substr(id.find_last_of('.') + 1, id.length());
item->description = std::string((unit->description == NULL ?
unit->unitPath : unit->description));
if (unit->state != NULL) {
std::string state(unit->state);
std::string sub(unit->subState == NULL ? "" : unit->subState);
if (state.find("enabled") == 0) {
item->state = UNIT_STATE_ENABLED;
} else if (state.find("mask") == 0) {
item->state = UNIT_STATE_MASKED;
} else if (state.find("static") == 0) {
item->state = UNIT_STATE_STATIC;
} else if (state.find("bad") == 0 || state.find("removed") == 0) {
item->state = UNIT_STATE_BAD;
} else {
item->state = UNIT_STATE_DISABLED;
}
if (!sub.empty()) {
if (sub.find("running") == 0) {
item->sub = UNIT_SUBSTATE_RUNNING;
} else {
item->sub = UNIT_SUBSTATE_CONNECTED;
}
} else {
item->sub = UNIT_SUBSTATE_INVALID;
}
} else {
item->state = UNIT_STATE_MASKED;
}
bus->freeUnitInfo(unit);
items.push_back(item);
};
std::vector<UnitItem *> ChkCTL::getItemsSorted() {
std::vector<std::string> orderedTargets;
std::vector<UnitItem *> sunits;
bool alreadyHasTarget = false;
orderedTargets.push_back("service");
orderedTargets.push_back("timer");
orderedTargets.push_back("socket");
for (const auto unit : items) {
alreadyHasTarget = false;
for (auto t : orderedTargets) {
if (t.find(unit->target) == 0) {
alreadyHasTarget = true;
break;
}
}
if (!alreadyHasTarget) {
orderedTargets.push_back(unit->target);
}
}
bool isFirst = false;
for (std::string target : orderedTargets) {
auto targetedUnits = getByTarget(target.c_str());
sortByName(&targetedUnits);