其他分享
首页 > 其他分享> > 普通用户配置systemd服务

普通用户配置systemd服务

作者:互联网

systemctl --user enable xxx.service
激活的用户实例(systemd user unit),只有在用户登录会话后,才会运行

如果要让用户实例(systemd user unit) 随系统自动启动,需要再执行命令:

systemctl status user@1000.service
systemctl status systemd-logind
service dbus  status
loginctl enable-linger webapp
#--普通用户家目录
vim ~/.bash_profile

export XDG_RUNTIME_DIR="/run/user/$UID"
export TMOUT=1800

source ~/.bash_profile
# root配置开机自启
vim /etc/rc.d/rc.local
su - webapp -c 'systemctl --user start nacos'

chmod +x /etc/rc.d/rc.local
# 普通用户配置服务文件
vim /webapp/.config/systemd/user/nacos.service

[Unit]
Description=nacos
After=network.target

[Service]
WorkingDirectory=/webapp/nacos
Type=forking
Environment='JAVA_HOME=/opt/jdk1.8.0_311'
# 单机启动方式:
# ExecStart=/bin/sh /webapp/nacos/bin/startup.sh -m standalone
# 集群启动方式:
ExecStart=/bin/sh /webapp/nacos/bin/startup.sh
ExecReload=/bin/sh /webapp/nacos/bin/shutdown.sh
ExecStop=/bin/sh /webapp/nacos/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
# systemctl --user enable nacos
systemctl --user daemon-reload
systemctl --user start nacos
systemctl --user status nacos
systemctl --user stop nacos
journalctl --user -u nacos -fn 200

注:用户级别的后台服务单元 (Systemd user unit) 保存在以下四个位置:

标签:bin,systemd,--,配置,nacos,systemctl,user,普通用户
来源: https://www.cnblogs.com/xjzyy/p/15852750.html