22

On Raspberry Pi with Arch Linux there is a service active called serial-getty@AMA0.

The unit file is: /usr/lib/systemd/system/serial-getty@.service

As root I can invoke

systemctl stop serial-getty@ttyAMA0
systemctl disable serial-getty@ttyAMA0

But after reboot the service is enabled and running again.

Why is the service enabled after disabling it? How can I disable it permanent?

UPDATE

systemd uses generators at /usr/lib/systemd/system-generators/ is a binary called systemd-getty-generator. This binary runs at system start and adds the symlink serial-getty@ttyAMA0.service to /run/systemd/generator/getty.target.wants.

I eventually found a dirty solution. I commented out all actions in /usr/lib/systemd/system/serial-getty@.service. The service did appear to start anyway, but without blocking ttyAMA0.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lojoe
  • 521
  • 1
  • 3
  • 13

2 Answers2

42

The correct way to stop a service ever being enabled again is to use:

systemctl mask serial-getty@ttyAMA0.service

(using ttyAMA0 as the example in this case). This will add a link to null to the entry for that service.

David Guyon
  • 2,759
  • 1
  • 28
  • 40
Rob Meades
  • 436
  • 5
  • 3
  • Could suffix "`.service`" [be omitted](https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units)? – Peter Mortensen Apr 15 '18 at 22:25
-5

Try this code:

system("systemctl stop serial-getty@ttyAMA0.service");
system("systemctl disable serial-getty@ttyAMA0.service");

I use it, and it works well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
m-tech
  • 338
  • 2
  • 14
  • 1
    What is the context? From a Bash script? A Python script? A Perl script? A C program? Something else? – Peter Mortensen Apr 15 '18 at 16:20
  • yes , you can use system(); in c++ in linux .for example you can use system(" data") ,system(" dir") ,system(" ls") in c++ .it run bash script (system script in linux) – m-tech Apr 24 '18 at 21:29
  • I've logged in for the first time in a long time to leave this comment. Please don't use C's `system` function. It has well known security issues. It's especially bad in this case, because manipulating systemd often requires root privileges. edit: I'll add this for context https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152177 – Woodrow Douglass Sep 01 '20 at 15:45