Questions tagged [systemd]

Systemd is a system management daemon designed for Linux. Use this tag for *programming questions* using systemd or its libraries. Questions about *configuring the daemon* (including writing unit files) are better directed to Unix & Linux: https://unix.stackexchange.com.

Systemd is a system management daemon designed for Linux and programmed exclusively for the Linux API. For systems using it, it is the first process which is executed in user space during the Linux startup process. Therefore, systemd serves as the root of the user space's process tree.

2384 questions
69
votes
1 answer

How to set up a systemd service to retry 5 times on a cycle of 30 seconds

I want systemd to start a script and retry a maximum of 5 times, 30s apart. Reading the systemd.service manual and searching the Internet didn't produce any obvious answers.
jross
  • 1,847
  • 2
  • 10
  • 6
57
votes
8 answers

systemd apparently not finding .service file

I've put together a foo.service file for our foo service that runs as a daemon. The service runs fine when I run systemctl start foo (and stop) but systemtcl enable foo results in Failed to issue method call: Invalid argument. The unit file is…
user3255510
  • 837
  • 2
  • 8
  • 12
47
votes
8 answers

python import of local module failing when run as systemd/systemctl service

I have a python application that I'm tring to run as a system service. The application runs fine when I run it manually. When I run it as a service it fails to find a local module that was installed with pip install -e my_module. The main of the…
user1753106
  • 1,176
  • 2
  • 10
  • 16
45
votes
1 answer

How can I install a systemd service using Ansible?

I want to install a systemd service from a Jinja2 template. How do I do this? Do I have to use copy module to copy the file to /lib/systemd/system and then use systemd module to enable it? Is there a better way?
ATOzTOA
  • 34,814
  • 22
  • 96
  • 117
43
votes
3 answers

tmux open terminal failed: not a terminal

I have a shell script that is enabled as service to start multiple shell scripts e.g. service started script -> script1, script2 ,script3 script1 should open a program in a tmux window, and it does work just fine if I manually start the script via…
STiGYFishh
  • 708
  • 3
  • 8
  • 16
42
votes
3 answers

How to restart a service if its dependent service is restarted

A service (say bar.service) is dependent on another service (say foo.service), like below bar's service file: [Unit] After=foo.service Requires=foo.service ... If foo.service is restarted (either manually or due to a bug), how can bar.service be…
iobelix
  • 1,143
  • 1
  • 10
  • 16
40
votes
3 answers

When should the option RemainAfterExit needs to be set true when creating new systemd services?

I am trying to write a few services. Some of them have 'type' option set to oneshot. But i am still confused when the option 'RemainAfterExit' needs to be set true. (not just that service needs to be active even after exiting).
Aditya Vardhan
  • 531
  • 1
  • 4
  • 7
39
votes
2 answers

systemd: "Environment" directive to set PATH

What is the right way to set PATH variable in a systemd unit file? After seeing a few examples, I tried to use the format below, but the variable doesn't seem to expand. Environment="PATH=/local/bin:$PATH" I am trying this on CoreOS with the below…
ϹοδεMεδιϲ
  • 2,790
  • 3
  • 33
  • 54
38
votes
4 answers

How to log to journald (systemd) via Python?

I would like logging.info() to go to journald (systemd). Up to now I only found python modules which read journald (not what I want) or modules which work like this: journal.send('Hello world')
guettli
  • 25,042
  • 81
  • 346
  • 663
37
votes
2 answers

How to Pipe Output to a File When Running as a Systemd Service?

I'm having trouble piping the STDOUT & STDERR to a file when running a program as a systemd service. I've tried adding the following to the .service file: ExecStart=/apppath/appname > /filepath/filename 2>&1 But this doesn't work. The output is…
MichaelB76
  • 640
  • 1
  • 6
  • 15
35
votes
2 answers

Using setup.py to install python project as a systemd service

I have a python project and I want to be able to install it using something like python setup.py install so that the installation automatically creates a systemd service. I'm having some trouble, most probably setting the paths or imports…
newlog
  • 1,050
  • 1
  • 11
  • 23
33
votes
6 answers

docker change cgroup driver to systemd

I want Docker to start with systemd cgroup driver. For some reason it is using only cgroupfs on my CentOS 7 server. Here is startup config file. # systemctl cat docker # /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application…
sfgroups
  • 18,151
  • 28
  • 132
  • 204
33
votes
3 answers

What benefit do I get from JSVC over just using systemd?

The Tomcat documentation describes the process of compiling and installing JSVC which can be used to run Tomcat as a daemon. As per my understanding, JSVC has two benefits: It launches as root allowing for the use of a privileged port (like 80 or…
user636044
31
votes
2 answers

systemctl status shows inactive dead

I am trying to write my own (simple) systemd service which does something simple.( Like writing numbers 1 to 10 to a file, using the shell script). My service file looks like…
nandanator
  • 421
  • 1
  • 4
  • 5
31
votes
3 answers

Systemd script does ExecStop right after ExecStart

Here's my Systemd script: [Unit] Description=RDS Services [Service] WorkingDirectory=/home/rdsdb2/script_rds/ Type=oneshot ExecStart=/bin/bash start_services.sh ExecStop=/bin/bash…
Alby11
  • 607
  • 1
  • 7
  • 15