blob: e4a31bb0eb48e866b98e6a135916c2936bb758dc [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
AppaRao Puli00840472018-10-03 19:37:46 +053017#include <boost/asio.hpp>
AppaRao Puliee853eb2020-05-29 00:53:20 +053018#include <phosphor-logging/elog-errors.hpp>
19#include <sdbusplus/asio/object_server.hpp>
20#include <xyz/openbmc_project/Common/error.hpp>
AppaRao Puli00840472018-10-03 19:37:46 +053021
AppaRao Puliee853eb2020-05-29 00:53:20 +053022#include <chrono>
23#include <ctime>
Tom Joseph82e95572020-05-07 20:28:05 +053024#include <filesystem>
AppaRao Puliee853eb2020-05-29 00:53:20 +053025#include <string>
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053026
AppaRao Puliee853eb2020-05-29 00:53:20 +053027static constexpr const char* sysdStartUnit = "StartUnit";
28static constexpr const char* sysdStopUnit = "StopUnit";
29static constexpr const char* sysdRestartUnit = "RestartUnit";
30static constexpr const char* sysdReloadMethod = "Reload";
31static constexpr const char* sysdGetJobMethod = "GetJob";
32static constexpr const char* sysdReplaceMode = "replace";
33static constexpr const char* dBusGetAllMethod = "GetAll";
34static constexpr const char* dBusGetMethod = "Get";
35static constexpr const char* sysdService = "org.freedesktop.systemd1";
36static constexpr const char* sysdObjPath = "/org/freedesktop/systemd1";
37static constexpr const char* sysdMgrIntf = "org.freedesktop.systemd1.Manager";
38static constexpr const char* sysdUnitIntf = "org.freedesktop.systemd1.Unit";
39static constexpr const char* sysdSocketIntf = "org.freedesktop.systemd1.Socket";
40static constexpr const char* dBusPropIntf = "org.freedesktop.DBus.Properties";
41static constexpr const char* stateMasked = "masked";
42static constexpr const char* stateEnabled = "enabled";
43static constexpr const char* stateDisabled = "disabled";
44static constexpr const char* subStateRunning = "running";
45
46static inline std::string addInstanceName(const std::string& instanceName,
47 const std::string& suffix)
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053048{
49 return (instanceName.empty() ? "" : suffix + instanceName);
50}
AppaRao Puli00840472018-10-03 19:37:46 +053051
52void systemdDaemonReload(
AppaRao Puliee853eb2020-05-29 00:53:20 +053053 const std::shared_ptr<sdbusplus::asio::connection>& conn,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053054 boost::asio::yield_context yield);
AppaRao Puli00840472018-10-03 19:37:46 +053055
AppaRao Puliee853eb2020-05-29 00:53:20 +053056void systemdUnitAction(const std::shared_ptr<sdbusplus::asio::connection>& conn,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053057 boost::asio::yield_context yield,
AppaRao Puliee853eb2020-05-29 00:53:20 +053058 const std::string& unitName,
59 const std::string& actionMethod);
AppaRao Puli00840472018-10-03 19:37:46 +053060
AppaRao Pulie55cfd62019-02-15 15:35:29 +053061void systemdUnitFilesStateChange(
AppaRao Puliee853eb2020-05-29 00:53:20 +053062 const std::shared_ptr<sdbusplus::asio::connection>& conn,
63 boost::asio::yield_context yield, const std::vector<std::string>& unitFiles,
64 const std::string& unitState, bool maskedState, bool enabledState);