linux 进程开机自启

linux 进程开机自启

在Linux系统中,要让一个进程在开机时自动启动,可以使用systemd服务。

以下是创建自启动服务的步骤和示例代码:

创建一个新的systemd服务单元文件。

文件通常位于/etc/systemd/system/目录下,以.service作为文件扩展名。例如,创建一个名为my_service.service的文件:

sudo nano /etc/systemd/system/my_service.service

在该文件中添加以下内容:

**[Unit]
Description=My Custom Service
After=network.target

Service

Type=simple
ExecStart=/path/to/your/application

Install

WantedBy=multi-user.target**

将/path/to/your/application替换为你的应用程序的完整路径。

重新加载systemd管理器配置。sudo systemctl daemon-reload

启用服务以在开机时自动启动。sudo systemctl enable my_service.service

(可选)立即启动服务而不需要重启。sudo systemctl start my_service.service

确保你的应用程序具有执行权限。如果没有,使用chmod命令添加执行权限:

sudo chmod +x /path/to/your/application

现在,每次系统启动时,my_service.service服务都会自动运行指定的应用程序。

bash 复制代码
:~/Documents/IsstaGao/pwr_mngr$
:~/Documents/IsstaGao/pwr_mngr$ vim /etc/systemd/system/my_service.service
:~/Documents/IsstaGao/pwr_mngr$ sudo vim /etc/systemd/system/issta_service.service
[sudo] password for mogo:
:~/Documents/IsstaGao/pwr_mngr$ sudo vim /etc/systemd/system/issta_service.service
:~/Documents/IsstaGao/pwr_mngr$ pwd
/data/mogo/Documents/IsstaGao/pwr_mngr
:~/Documents/IsstaGao/pwr_mngr$ sudo vim /etc/systemd/system/issta_service.service
:~/Documents/IsstaGao/pwr_mngr$ sudo systemctl daemon-reload
:~/Documents/IsstaGao/pwr_mngr$ sudo systemctl enable issta_service.service
Created symlink /etc/systemd/system/multi-user.target.wants/issta_service.service → /etc/systemd/system/issta_service.service.
:~/Documents/IsstaGao/pwr_mngr$ sudo systemctl start issta_service.service
:~/Documents/IsstaGao/pwr_mngr$ ps -aux | grep client
root        8843  0.0  0.0  10432   540 ?        Ssl  16:15   0:00 /data/mogo/Documents/IsstaGao/pwr_mngr/client -s 192.168.1.102 -p 9039
mogo        8857  0.0  0.0   8572   652 pts/0    S+   16:16   0:00 grep --color=auto client
相关推荐
超级土豆粉3 分钟前
从0到1写一个适用于Node.js的User Agent生成库
linux·ubuntu·node.js
PH_modest8 分钟前
【Linux跬步积累】—— 网络编程套接字(二)
linux·运维·网络
起床学FPGA14 分钟前
导出pcap文件中的特定数据包
网络
Huathy-雨落江南,浮生若梦16 分钟前
k8s入门教程(集群部署、使用,镜像拉取失败网络问题排查)
网络·容器·kubernetes
itachi-uchiha22 分钟前
使用vsftpd搭建FTP服务器(TLS/SSL显式加密)
运维·服务器·ssl
CIb0la23 分钟前
Ubuntu 25.10 将默认使用 sudo-rs
linux·程序人生·生活
成工小白35 分钟前
【Linux】文件操作
linux·运维·服务器
风早君1 小时前
jenkins集成gitlab发布到远程服务器
服务器·gitlab·jenkins
程序员打怪兽1 小时前
基于V4L2摄像头智能识别拍照(人脸和手掌)
linux·嵌入式
家庭云计算专家1 小时前
ONLYOFFICE协作空间3.1.1 企业版 介绍及部署说明:家庭云计算专家
运维·服务器·云计算·onlyoffice·协作空间