centos后台运行程序

dandan3年前程序开发4841

通过远程shell工具连上服务器,运行程序后,如果关闭工具,进程也会被结束。所以采用systemctl方式运行


1、创建运行用户

adduser newUserName


2、编辑service脚本,比如myapp.service(可以给程序新建一个目录,比如放到/opt/app)

[Unit]
Description=myApp Service
After=network.target

[Service]
ExecStart=/opt/app/myApp
WorkingDirectory=/opt/app
User=newUserName
Group=newUserName
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=myApp

[Install]
WantedBy=multi-user.target


3、将该文件移动到系统服务目录

cp myapp.service /etc/systemd/system/


4、重载配置

systemctl daemon-reload


5、启动

systemctl start myapp


其他命令:

systemctl start servicename:启动服务。
systemctl stop servicename:停止服务。
systemctl restart servicename:重启服务。
systemctl enable servicename:设置服务为开机自启动。
systemctl disable servicename:取消设置服务为开机自启动。
systemctl status servicename:查看服务的状态。
journalctl -u servicename:查看服务的日志。


相关文章

使用ngrok进行内网穿透

1、在官网注册账号:https://ngrok.com/ 2、左侧导航Setup & Installtion,下载当前电脑的应用3、左侧导航Your Authtoken,获取token配置命令...

golang环境安装(mac m1)

1、进官网https://www.gomirrors.org/下载tar格式的报,选arm64的2、在电脑新建一个目录,专门用于放go的项目3、将下载的包放到目录里,使用终端,进入该目录后,并进行解压...

Docker安装篇(CentOS7.6)

7.6环境自带gcc和gcc-c++,不用再装安装yum-utilsyum install -y yum-utils设置阿里云镜像仓库yum-config-manager...

通过frp进行内网穿透

因为ngrok会定义刷新域名,有点限制,如果没有服务器域名,用他合适,如果有自己的服务器、域名,则用frp:按照https://blog.csdn.net/mirage003/article/deta...

mac m1 中go使用kafka

当前docker-comose:version: '3' services:   Etcd:     con...

wsl2安装docker+dify+xinference

1、wsl2安装ubuntu,这里指定版本安装一个新环境 wsl --install -d Ubuntu-22.042、安装完的ubuntu是在c盘的,放到其他...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。