在Linux上部署程序

2019-12-29  本文已影响0人  土豆吞噬者

nohup &

程序在Linux上运行时,如果关闭session,程序会因为收到SIGHUP信号结束,使用nohup可以免疫该信号。如果使用Ctrl+C,程序会因为收到SIGINT信号结束,使用&可以免疫该信号。

nohup和&常常一起使用,这个时候会同时免疫SIGHUP和SIGINT信号:

nohup command &

systemd

systemd是Linux系统的第一个进程,使用systemd可以创建服务来运行程序,systemctl是systemd的主命令,可以用来管理服务,下面是常见的systemctl命令:

# 启动服务
systemctl start servicename

# 停止服务
systemctl stop servicename

# 重启服务
systemctl restart servicename

# 杀死一个服务的所有子进程
systemctl kill servicename

# 重新加载一个服务的配置文件
systemctl reload servicename

# 开机启动该服务
systemctl enable servicename

# 开机不启动该服务
systemctl disable servicename

# 查看服务当前状态
systemctl status servicename

service配置文件存在以下三个文件夹中,优先级依此降低:

service配置文件通常由3段组成,分别是[Unit],[Unit的类型:Service等],[Install]。

[Unit]常见参数:

[Service]常见参数:

[Install]常见参数:

hello.service:

[Unit]
Description=hello world

[Service]
Type=simple
ExecStart=/bin/hello

[Install]
WantedBy=multi-user.target
上一篇下一篇

猜你喜欢

热点阅读