Skip to content

Commit 86bc968

Browse files
mauriciovasquezbernalfrisso
authored andcommitted
polycubed: provide systemd integration (#177)
This commit provides an easy way to manage polycubed by using systemd. Signed-off-by: Mauricio Vasquez B <mauriciovasquezbernal@gmail.com>
1 parent dfaa6ae commit 86bc968

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

Documentation/polycubed/polycubed.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ It exposes a configuration mechanism of the different service instances through
1313
It requires root privileges and only an instance can be launched system wide.
1414

1515

16+
Systemd integration
17+
^^^^^^^^^^^^^^^^^^^
18+
19+
``polycubed`` can be managed as a systemd service.
20+
21+
::
22+
23+
# start the service
24+
sudo systemctl start polycubed
25+
26+
# stop the service
27+
sudo systemctl stop polycubed
28+
29+
# restart the service
30+
sudo systemctl reload-or-restart polycubed
31+
32+
# enable the service to be started at boot time
33+
sudo systemctl enable polycubed
34+
35+
# see service status
36+
sudo systemctl status polycubed
37+
38+
# check logs
39+
journalctl -u polycubed // '-f' can be used to see a live version
40+
1641
Usage
1742
^^^^^
1843

@@ -35,7 +60,6 @@ Usage
3560
-h, --help: print this message
3661

3762

38-
3963
Configuration file
4064
^^^^^^^^^^^^^^^^^^
4165

Documentation/quickstart.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ Bare Metal
4646
This is a more elaborated way only recommended for advance users.
4747
Please the :doc:`installation guide <installation>` to get detailed information about how to compile and install ``polycube`` and its dependencies.
4848

49-
Once you have ``polcyube`` installed in your system, you can launch ``polycubed`` (the polycube daemon):
49+
Once you have ``polcyube`` installed in your system, you can start the ``polycubed`` service:
5050

5151
::
5252

53-
# Launch in attached mode (you'll be able to see the log directly in te terminal)
54-
sudo polycubed
55-
# Launch in detached mode (logs will be saved on files)
56-
sudo polycubed -d
53+
# start polycubed service
54+
# (sudo service start polycubed will work in many distros as well)
55+
sudo systemctl start polycubed
5756

57+
# check service status
58+
sudo systemctl status polycubed
5859

5960
Start interacting with the framework by using ``polycubectl``. Refer to :doc:`polycubectl CLI <polycubectl/polycubectl>`.
6061

@@ -63,8 +64,8 @@ Start interacting with the framework by using ``polycubectl``. Refer to :doc:`po
6364
polycubectl --help
6465

6566

66-
In order to stop ``polycubed`` you can press ``Ctrl+C`` on the terminal it is running (if running in attached mode). You can also send the ``SIGTERM`` signal to the process:
67+
To stop the ``polycubed`` service use:
6768

6869
::
6970

70-
sudo pkill -SIGTERM polycubed
71+
sudo systemctl stop polycubed

src/polycubed/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ set(CMAKE_CXX_STANDARD 17)
22
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33

44
add_subdirectory(src)
5+
add_subdirectory(systemdservice)
56

67
set(CMAKE_CXX_STANDARD 11)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2018, Intel Corporation
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a
4+
# copy of this software and associated documentation files (the "Software"),
5+
# to deal in the Software without restriction, including without limitation
6+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
# and/or sell copies of the Software, and to permit persons to whom the
8+
# Software is furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included
11+
# in all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17+
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19+
# OTHER DEALINGS IN THE SOFTWARE.
20+
21+
include(FindPkgConfig)
22+
include(GNUInstallDirs)
23+
24+
pkg_check_modules(SYSTEMD "systemd")
25+
26+
if (SYSTEMD_FOUND AND "${SYSTEMD_SERVICES_INSTALL_DIR}" STREQUAL "")
27+
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
28+
--variable=systemdsystemunitdir systemd
29+
OUTPUT_VARIABLE SYSTEMD_SERVICES_INSTALL_DIR)
30+
string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_SERVICES_INSTALL_DIR
31+
"${SYSTEMD_SERVICES_INSTALL_DIR}")
32+
configure_file(polycubed.service.in
33+
${CMAKE_BINARY_DIR}/polycubed.service
34+
@ONLY)
35+
install(FILES ${CMAKE_BINARY_DIR}/polycubed.service DESTINATION
36+
${SYSTEMD_SERVICES_INSTALL_DIR} COMPONENT cp)
37+
38+
elseif (NOT SYSTEMD_FOUND AND SYSTEMD_SERVICES_INSTALL_DIR)
39+
message (FATAL_ERROR "Variable SYSTEMD_SERVICES_INSTALL_DIR is\
40+
defined, but we can't find systemd using pkg-config")
41+
endif()
42+
43+
if (SYSTEMD_FOUND)
44+
set(WITH_SYSTEMD "ON")
45+
message(STATUS "systemd services install dir: ${SYSTEMD_SERVICES_INSTALL_DIR}")
46+
else()
47+
set(WITH_SYSTEMD "OFF")
48+
endif (SYSTEMD_FOUND)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=polycube service
3+
4+
[Service]
5+
Type=simple
6+
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/polycubed
7+
8+
[Install]
9+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)