1

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?

fightstarr20
  • 207
  • 1
  • 4
  • 12

3 Answers3

4

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
    
HBruijn
  • 72,524
  • 21
  • 127
  • 192
2

You launch it using a systemd unit, like every other service.

There are numerous tutorials out on the Internet about how to set this up. Or you can just start with a skeleton unit something like:

[Unit]
Description=uWSGI instance to serve my project
After=network.target

[Service]
User=you
Group=www-data
WorkingDirectory=/home/you/project
Environment="PATH=/home/you/project/venv/bin"
ExecStart=/home/you/project/venv/bin/uwsgi --ini uwsgi.ini

[Install]
WantedBy=multi-user.target
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
-1

There is no single answer, but you can use something like Supervisord:

Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

Halfgaar
  • 7,921
  • 5
  • 42
  • 81