大网数据广告活动
服务器运维问答

Debian 9 - rc.local deprecated, how to launch python at startup

· 52CE 我爱测

I am slightly lost, I have a Debian 9 server and a Python Flask script that I am trying to launch at startup. In the past I have used rc.local to launch things at startup but from reading it seems that it is now deprecated. Can a…

问题原文

原帖链接 · fightstarr20 · CC BY-SA 4.0

I am slightly lost, I have a Debian 9 server and a Python Flask script that I am trying to launch at startup.

In the past I have used rc.local to launch things at startup but from reading it seems that it is now deprecated.

Can anyone tell me what is its replacement, what method am I best using now?

已采纳解答

原帖链接 · HBruijn · CC BY-SA 4.0

Debian 9 (like many other current Linux distributions) uses systemd to start and manage your system and services.

You'll be facing a bit of a learning curve compared to adding lines to rc.local but writing unit files (systemd jargon for what is effectively the equivalent of a start and stop script for a service) will be usefull skill to learn.

The Debian specific documentation on systemd is found on https://wiki.debian.org/systemd
The page https://wiki.debian.org/systemd/Services contains detailed step-by-step intructions for what is needed to write your own (minimal) unit file:

  • Create the unit file "myservice.service" in the directory /etc/systemd/system/

    # /etc/systemd/system/myservice.service 
    [Unit]
    Description=My Service
    After=network.target
    
    [Service]
    Type=simple
    Restart=always
    ExecStart=/usr/local/bin/myservice
    
    [Install]
    WantedBy=multi-user.target
    
  • Reload systemd to pick up your changed/new unit files with: systemctl daemon-reload

  • Enable and start the new service

    systemctl enable myservice.service
    systemctl start myservice.service
    

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-01-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。