-

CommentStreams:F49f1f7f3dd261f981feebe135656a2c

From Geekworm Wiki
Jump to navigation Jump to search

- The installation process should create a systemctl service to start/stop the process instead of using crontab.

I did the following:

Copied /home/pi/x728/x728v2-asd.py to /usr/local/bin: sudo cp /home/pi/x728/x728v2-asd.py /usr/local/bin

Then created a systemctl service file to start the script:

sudo vi /lib/systemd/system/x728-shutdown.service

Contents of the file:

[Unit] Description=Geekworm x728 Shutdown Service After=network.target

[Service] Type=simple StandardOutput=null WorkingDirectory=/usr/local/bin User=root Restart=always RestartSec=3 ExecStart=/usr/bin/python3 /usr/local/bin/x728v2-asd.py ExecReload=/bin/kill -2 $MAINPID KillMode=process

[Install] WantedBy=multi-user.target

Then I reloaded systemctl to read the new service file:

sudo systemctl daemon-reload

Enable the service:

sudo systemctl enable x728-shutdown.service

Started the service:

sudo systemctl start x728-shutdown.service

Display the status:

sudo systemctl status x728-shutdown.service

● x728-shutdown.service - Geekworm x728 Shutdown Service

    Loaded: loaded (/lib/systemd/system/x728-shutdown.service; enabled; vendor preset: enabled)
    Active: active (running) since Thu 2022-02-24 18:30:59 EST; 3min 55s ago
  Main PID: 1632 (python3)
     Tasks: 1 (limit: 1597)
       CPU: 113ms
    CGroup: /system.slice/x728-shutdown.service
            └─1632 /usr/bin/python3 /usr/local/bin/x728v2-asd.py

Feb 24 18:30:59 raspberrypi systemd[1]: Started Geekworm x728 Shutdown Service.

MUCH better than adding to crontab!