sysguard

package
v0.0.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ROOT_MODE_SYSTEMD_SERVICE_PATH = "/lib/systemd/system"
View Source
var ROOT_MODE_SYSVINIT_SCRIPT_PATH = "/etc/init.d"
View Source
var SYSTEMCTL_MODE = ChoseSystemctlMode()
View Source
var SYSTEMD_SERVICE_PATH = ChoseSystemdPathMode()
View Source
var USER_MODE_SYSTEMD_SERVICE_PATH = filepath.Join(system.GetHomeDir(), ".config", "systemd", "user")

systemd service meta config ref: https://unix.stackexchange.com/questions/224992/where-do-i-put-my-systemd-unit-file

Functions

func AutoChoseSetupMode

func AutoChoseSetupMode() (string, error)

根据操作系统自动选择使用systemd还是SysVinit

func ChoseSystemctlMode

func ChoseSystemctlMode() string

func ChoseSystemdPathMode

func ChoseSystemdPathMode() string

func CurrentExecutableFileOwnerInfo added in v0.0.25

func CurrentExecutableFileOwnerInfo() string

获取当前执行程序文件的所属用户

func CurrentShellUserName added in v0.0.26

func CurrentShellUserName() string

获取当前shell登陆的用户

func GenSysVinitServiceScript

func GenSysVinitServiceScript(systemdServiceConfig SystemdServiceConfig) error

生成SysVinit的启动脚本 1. 写入/etc/init.d/xxxxx 2. chmod 755 /etc/init.d/xxxxx

func GenSystemdServiceConfigFile

func GenSystemdServiceConfigFile(systemdServiceConfig SystemdServiceConfig) error

生成systemd配置文件

func PreSetupSystemdService

func PreSetupSystemdService() error

func SetupService

func SetupService(systemdServiceConfig SystemdServiceConfig) error

自动选择使用部署模式

func SetupSysVinitService

func SetupSysVinitService(systemdServiceConfig SystemdServiceConfig) error

SysVinit模式部署 1. 渲染生成SysVinit脚本文件 2. chkconfig --add myservice --- 注册服务 3. chkconfig --level 345 myservice on --- 设置开机启动 4. service myservice start --- 启动服务 5. service myservice status --- 检查服务启动状态

func SetupSystemdService

func SetupSystemdService(systemdServiceConfig SystemdServiceConfig) error

systemd模式部署 1. 渲染生成service文件 2. systemctl --user daemon-reload -- 加载配置 3. systemctl --user enable appName -- 设为开机启动 4. systemctl --user start appName -- 启动服务 5. systemctl --user status appName -- 检查是否启动成功

func UnSetupService

func UnSetupService(systemdServiceConfig SystemdServiceConfig, deleteExporterWorkingDirectory bool) error

自动选择使用卸载模式

func UnSetupSysVinitService

func UnSetupSysVinitService(systemdServiceConfig SystemdServiceConfig, deleteExporterWorkingDirectory bool) error

SysVinit模式卸载 1. service myservice stop --- 停止服务 2. service myservice status --- 检查停止是否成功 3. chkconfig --level 345 myservice off --- 取消开机自启 4. chkconfig --del myservice --- 注销服务 5. rm -rf /etc/init.d/myservice --- 删除服务脚本

func UnSetupSystemService

func UnSetupSystemService(systemdServiceConfig SystemdServiceConfig, deleteExporterWorkingDirectory bool) error

systemd模式卸载清理 1. systemctl --user stop appName -- 停止服务 2. systemctl --user disable appName -- 禁用服务 3. rm ~/.config/systemd/user/appName.service -- 删除服务的systemd配置 4. rm -r WorkingDirectory -- 删除服务文件和配置 【非必须】

Types

type SystemdServiceConfig

type SystemdServiceConfig struct {
	Name             string `json:"name"`
	Description      string `json:"description"`
	WorkingDirectory string `json:"working_directory"`
	ExecStart        string `json:"exec_start"`
}

定义systemd配置所需信息结构体

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL