Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
aa84b99f
Unverified
Commit
aa84b99f
authored
May 10, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 10, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #73101 from oz123/kubeadm_openrc_support
Add initial support for OpenRC
parents
21bec91e
2a40ef47
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
initsystem.go
pkg/util/initsystem/initsystem.go
+66
-0
No files found.
pkg/util/initsystem/initsystem.go
View file @
aa84b99f
...
...
@@ -23,6 +23,9 @@ import (
)
type
InitSystem
interface
{
// return a string describing how to enable a service
EnableCommand
(
service
string
)
string
// ServiceStart tries to start a specific service
ServiceStart
(
service
string
)
error
...
...
@@ -42,8 +45,63 @@ type InitSystem interface {
ServiceIsActive
(
service
string
)
bool
}
type
OpenRCInitSystem
struct
{}
func
(
openrc
OpenRCInitSystem
)
ServiceStart
(
service
string
)
error
{
args
:=
[]
string
{
service
,
"start"
}
return
exec
.
Command
(
"rc-service"
,
args
...
)
.
Run
()
}
func
(
openrc
OpenRCInitSystem
)
ServiceStop
(
service
string
)
error
{
args
:=
[]
string
{
service
,
"stop"
}
return
exec
.
Command
(
"rc-service"
,
args
...
)
.
Run
()
}
func
(
openrc
OpenRCInitSystem
)
ServiceRestart
(
service
string
)
error
{
args
:=
[]
string
{
service
,
"restart"
}
return
exec
.
Command
(
"rc-service"
,
args
...
)
.
Run
()
}
// openrc writes to stderr if a service is not found or not enabled
// this is in contrast to systemd which only writes to stdout.
// Hence, we use the Combinedoutput, and ignore the error.
func
(
openrc
OpenRCInitSystem
)
ServiceExists
(
service
string
)
bool
{
args
:=
[]
string
{
service
,
"status"
}
outBytes
,
_
:=
exec
.
Command
(
"rc-service"
,
args
...
)
.
CombinedOutput
()
if
strings
.
Contains
(
string
(
outBytes
),
"does not exist"
)
{
return
false
}
return
true
}
func
(
openrc
OpenRCInitSystem
)
ServiceIsEnabled
(
service
string
)
bool
{
args
:=
[]
string
{
"show"
,
"default"
}
outBytes
,
_
:=
exec
.
Command
(
"rc-update"
,
args
...
)
.
Output
()
if
strings
.
Contains
(
string
(
outBytes
),
service
)
{
return
true
}
return
false
}
func
(
openrc
OpenRCInitSystem
)
ServiceIsActive
(
service
string
)
bool
{
args
:=
[]
string
{
service
,
"status"
}
outBytes
,
_
:=
exec
.
Command
(
"rc-service"
,
args
...
)
.
Output
()
if
strings
.
Contains
(
string
(
outBytes
),
"stopped"
)
{
return
false
}
return
true
}
func
(
openrc
OpenRCInitSystem
)
EnableCommand
(
service
string
)
string
{
return
fmt
.
Sprintf
(
"rc-update add %s default"
,
service
)
}
type
SystemdInitSystem
struct
{}
func
(
sysd
SystemdInitSystem
)
EnableCommand
(
service
string
)
string
{
return
fmt
.
Sprintf
(
"systemctl enable %s.service"
,
service
)
}
func
(
sysd
SystemdInitSystem
)
reloadSystemd
()
error
{
if
err
:=
exec
.
Command
(
"systemctl"
,
"daemon-reload"
)
.
Run
();
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to reload systemd: %v"
,
err
)
...
...
@@ -110,6 +168,10 @@ func (sysd SystemdInitSystem) ServiceIsActive(service string) bool {
// WindowsInitSystem is the windows implementation of InitSystem
type
WindowsInitSystem
struct
{}
func
(
sysd
WindowsInitSystem
)
EnableCommand
(
service
string
)
string
{
return
fmt
.
Sprintf
(
"Set-Service '%s' -StartupType Automatic"
,
service
)
}
func
(
sysd
WindowsInitSystem
)
ServiceStart
(
service
string
)
error
{
args
:=
[]
string
{
"Start-Service"
,
service
}
err
:=
exec
.
Command
(
"powershell"
,
args
...
)
.
Run
()
...
...
@@ -171,6 +233,10 @@ func GetInitSystem() (InitSystem, error) {
if
err
==
nil
{
return
&
SystemdInitSystem
{},
nil
}
_
,
err
=
exec
.
LookPath
(
"openrc"
)
if
err
==
nil
{
return
&
OpenRCInitSystem
{},
nil
}
_
,
err
=
exec
.
LookPath
(
"wininit.exe"
)
if
err
==
nil
{
return
&
WindowsInitSystem
{},
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment