Documentation ¶
Index ¶
- Variables
- func AutoChoseSetupMode() (string, error)
- func ChoseSystemctlMode() string
- func ChoseSystemdPathMode() string
- func CurrentExecutableFileOwnerInfo() string
- func CurrentShellUserName() string
- func GenSysVinitServiceScript(systemdServiceConfig SystemdServiceConfig) error
- func GenSystemdServiceConfigFile(systemdServiceConfig SystemdServiceConfig) error
- func PreSetupSystemdService() error
- func SetupService(systemdServiceConfig SystemdServiceConfig) error
- func SetupSysVinitService(systemdServiceConfig SystemdServiceConfig) error
- func SetupSystemdService(systemdServiceConfig SystemdServiceConfig) error
- func UnSetupService(systemdServiceConfig SystemdServiceConfig, deleteExporterWorkingDirectory bool) error
- func UnSetupSysVinitService(systemdServiceConfig SystemdServiceConfig, deleteExporterWorkingDirectory bool) error
- func UnSetupSystemService(systemdServiceConfig SystemdServiceConfig, deleteExporterWorkingDirectory bool) error
- type SystemdServiceConfig
Constants ¶
This section is empty.
Variables ¶
var ROOT_MODE_SYSTEMD_SERVICE_PATH = "/lib/systemd/system"
var ROOT_MODE_SYSVINIT_SCRIPT_PATH = "/etc/init.d"
var SYSTEMCTL_MODE = ChoseSystemctlMode()
var SYSTEMD_SERVICE_PATH = ChoseSystemdPathMode()
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 ChoseSystemctlMode ¶
func ChoseSystemctlMode() string
func ChoseSystemdPathMode ¶
func ChoseSystemdPathMode() string
func CurrentExecutableFileOwnerInfo ¶ added in v0.0.25
func CurrentExecutableFileOwnerInfo() string
获取当前执行程序文件的所属用户
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 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 -- 删除服务文件和配置 【非必须】