1查看本机live-server安装目录
root@tzktzk1-Lenovo-Gaming:/media# which live-server
/usr/local/bin/live-server
root@tzktzk1-Lenovo-Gaming:/media# node -v
v20.9.0
root@tzktzk1-Lenovo-Gaming:/media# npm -v
10.7.0
2.创建服务文件
sudo nano /etc/systemd/system/live-server-other.service
内容为:
[Unit]
Description=Live Server for /media/other
[Service]
ExecStart=/usr/local/bin/live-server /media/other --port=5500
WorkingDirectory=/media/other
Restart=always
User=tzktzk1
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
tzktzk1为登录用户的用户名
3.重新加载系统服务、启动服务
sudo systemctl daemon-reload
sudo systemctl start live-server-other
4.设置开机自启
sudo systemctl enable live-server-other
5.检查服务状态
sudo systemctl status live-server-other
6.如果遇到问题,可以查看服务的日志以获取更多信息:
journalctl -u live-server-other.service
网友评论