1 linux 服务注册 service文件 在service文件中设置变量和环境变量
[Unit]
Description= #服务描述
After=syslog.target #服务启动依赖
[Service]
Type=forking #服务启动类型 可选类型有simple forking
Environment="LD_LIBRARY_PATH=path" #设置变量
ExecStart= #启动命令
ExecStop= #停止命令 [Install]
WantedBy=multi-user.target #系统以该形式运行时,服务方可启动
2 将.service 文件拷贝到/usr/lib/systemd/system目录下,chmod 777 .service
3 systemctl命令执行.service文件
systemctl start sshd ##开启指定服务
systemctl restart sshd ##重新启动服务
systemctl enable sshd ##设定指定服务开机开启,可以使用
systemctl disable sshd ##设定指定服务开机关闭,无法使用
例子:
.sh脚本:开启服务以及设置开机自启
.service文件