blob: 5f01d447be273256d035d4497d5e99cb2c62b2e0 [file] [log] [blame]
AppaRao Puli00840472018-10-03 19:37:46 +05301/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17#include <ctime>
18#include <chrono>
19#include <string>
20#include <sdbusplus/asio/object_server.hpp>
21#include <phosphor-logging/elog-errors.hpp>
22#include <xyz/openbmc_project/Common/error.hpp>
23#include <experimental/filesystem>
24#include <boost/asio.hpp>
25
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053026static constexpr const char *sysdStartUnit = "StartUnit";
27static constexpr const char *sysdStopUnit = "StopUnit";
28static constexpr const char *sysdRestartUnit = "RestartUnit";
29static constexpr const char *sysdReloadMethod = "Reload";
30static constexpr const char *sysdGetJobMethod = "GetJob";
31static constexpr const char *sysdReplaceMode = "replace";
32static constexpr const char *dBusGetAllMethod = "GetAll";
33static constexpr const char *dBusGetMethod = "Get";
34static constexpr const char *sysdService = "org.freedesktop.systemd1";
35static constexpr const char *sysdObjPath = "/org/freedesktop/systemd1";
36static constexpr const char *sysdMgrIntf = "org.freedesktop.systemd1.Manager";
37static constexpr const char *sysdUnitIntf = "org.freedesktop.systemd1.Unit";
38static constexpr const char *sysdSocketIntf = "org.freedesktop.systemd1.Socket";
39static constexpr const char *dBusPropIntf = "org.freedesktop.DBus.Properties";
40static constexpr const char *stateMasked = "masked";
41static constexpr const char *stateEnabled = "enabled";
42static constexpr const char *stateDisabled = "disabled";
43static constexpr const char *subStateRunning = "running";
44
45static inline std::string addInstanceName(const std::string &instanceName,
46 const std::string &suffix)
47{
48 return (instanceName.empty() ? "" : suffix + instanceName);
49}
AppaRao Puli00840472018-10-03 19:37:46 +053050
51void systemdDaemonReload(
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053052 const std::shared_ptr<sdbusplus::asio::connection> &conn,
53 boost::asio::yield_context yield);
AppaRao Puli00840472018-10-03 19:37:46 +053054
55void systemdUnitAction(const std::shared_ptr<sdbusplus::asio::connection> &conn,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053056 boost::asio::yield_context yield,
AppaRao Puli00840472018-10-03 19:37:46 +053057 const std::string &unitName,
58 const std::string &actionMethod);
59
AppaRao Pulie55cfd62019-02-15 15:35:29 +053060void systemdUnitFilesStateChange(
AppaRao Puli00840472018-10-03 19:37:46 +053061 const std::shared_ptr<sdbusplus::asio::connection> &conn,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053062 boost::asio::yield_context yield, const std::vector<std::string> &unitFiles,
63 const std::string &unitState, bool maskedState, bool enabledState);