Skip to content

Commit

Permalink
If the /var/run (aka /run) folder doesn't exist for the PID file, cre…
Browse files Browse the repository at this point in the history
…ate it

CentOS 7 and many other recent Linuxes have switched to a non-persistent (tmpfs) /run folder, with /var/run being a symbolic link to the tmpfs /run mount.  The RPM creates the correct folder in /var/run for the PID file, but on reboot, that file is gone.  There are many ways to fix it.  This way will work on older systemd versions.
  • Loading branch information
ekuns committed Jun 24, 2015
1 parent 3ee00d2 commit 9c74f70
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ ExecStart=${{chdir}}/bin/${{exec}}
Restart=always
RestartSec=${{retryTimeout}}
User=${{daemon_user}}
ExecStartPre=/bin/mkdir -p /run/${{app_name}}
ExecStartPre=/bin/chown ${{daemon_user}}:${{daemon_group}} /run/${{app_name}}
ExecStartPre=/bin/chmod 755 /run/${{app_name}}
PermissionsStartOnly=true

[Install]
WantedBy=multi-user.target

3 comments on commit 9c74f70

@LeifW
Copy link

@LeifW LeifW commented on 9c74f70 Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the PID file for if you're using systemd?

@muuki88
Copy link
Contributor

@muuki88 muuki88 commented on 9c74f70 Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't add a PID file, but a directory /var/run/{appName} that can be used for PID files.

The play framework by default creates a PID file, no matter what systemloader is in use.

This is not necessary for systemd, but provides a default infrastructure for an application that requires it.

@ekuns
Copy link
Contributor Author

@ekuns ekuns commented on 9c74f70 Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the play framework creates the PID file no matter what, as muuki88 said, if the folder containing the PID-file-to-be doesn't exist, the service will fail to start. While systemd doesn't require PID files, they are sometimes useful for scripts, so it's a double bonus to make sure PID files can be created.

Please sign in to comment.