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
相关推荐
江公望11 小时前
ubuntu kylin(优麒麟)和标准ubuntu的区别浅谈
linux·服务器·ubuntu·kylin
Lynnxiaowen11 小时前
今天我们开始学习python语句和模块
linux·运维·开发语言·python·学习
沐风ya12 小时前
RPC介绍
网络·网络协议·rpc
生态笔记12 小时前
PPT宏代码
linux·服务器·powerpoint
mucheni12 小时前
迅为RK3588开发板Ubuntu 系统开发ubuntu终端密码登录
linux·运维·ubuntu
skywoodsky12 小时前
Ubuntu 24.04环境下的挂起转休眠
linux
OAFD.12 小时前
YOLOv3 详解:核心改进、网络架构与目标检测实践
网络·yolo·目标检测
小云数据库服务专线12 小时前
GaussDB 应用侧报Read timed out解决方法
linux·服务器·gaussdb
放弃幻想_12 小时前
S4和ECC或者不通CLIENT,不通HANA服务器互相取数
服务器·数据库·sap·abap·abap sap
资源补给站12 小时前
服务器高效操作指南:Python 环境退出与 Linux 终端快捷键全解析
linux·服务器·python