systemctl以root用户启动不爽吗,为什么还需要普通用户?大家可以敞开的想想…
需要root用户执行
sudo loginctl enable-linger username
将用户的服务长驻
以下是非root用户的操作
创建用户的服务
mkdir ~/.config/systemd/user
cd ~/.config/systemd/user
vim test.service
编辑 test.service
[Unit]
AssertPathExists=/home/ghost/ghost
[Service]
WorkingDirectory=/home/ghost/ghost
Environment=GHOST_NODE_VERSION_CHECK=false
ExecStart=/usr/bin/npm start --production
Restart=always
PrivateTmp=true
NoNewPrivileges=true
[Install]
WantedBy=default.target
启用 test.service
systemctl --user enable test.service
查看 test.service 状态
systemctl --user status test.service
启动 test.service
systemctl --user start test.service
查看日志
journalctl -n -f -u test
-n 表示 返回最新的日志
-f 表示 持续显示最新的日志,类似 tail -f
-u 表示只显示哪个service的日志
参考:
https://www.brendanlong.com/systemd-user-services-are-amazing.html
转载于:需要root用户执行
sudo loginctl enable-linger username
将用户的服务长驻
以下是非root用户的操作
创建用户的服务
mkdir ~/.config/systemd/user
cd ~/.config/systemd/user
vim test.service
编辑 test.service
[Unit]
AssertPathExists=/home/ghost/ghost
[Service]
WorkingDirectory=/home/ghost/ghost
Environment=GHOST_NODE_VERSION_CHECK=false
ExecStart=/usr/bin/npm start --production
Restart=always
PrivateTmp=true
NoNewPrivileges=true
[Install]
WantedBy=default.target
启用 test.service
systemctl --user enable test.service
查看 test.service 状态
systemctl --user status test.service
启动 test.service
systemctl --user start test.service
查看日志
journalctl -n -f -u test
-n 表示 返回最新的日志
-f 表示 持续显示最新的日志,类似 tail -f
-u 表示只显示哪个service的日志
参考:
https://www.brendanlong.com/systemd-user-services-are-amazing.html
转载于:https://www.liaozhiwei.com/p/1541
ps
如果你的服务是docker装的,或者你运行在docker上面回报一个问题D-bus的问题,所谓的D-bus就是那个 权限的问题
本文介绍了如何在Linux系统中,通过systemd让用户无需root权限也能管理自己的服务。用户可以创建并启用个人服务,如test.service,设置工作目录、环境变量和启动命令,并使用systemctl --user进行控制。此外,还提到了D-bus权限问题及其解决方案,确保非root用户能正常运行和监控服务日志。
1万+

被折叠的 条评论
为什么被折叠?



