Current section
Files
Jump to
Current section
Files
priv/templates/systemd.service.eex
[Unit]
Description=<%= service_name %> service
After=local-fs.target network.target<%= for target <- unit_after_targets do %> <%= target %><% end %>
<%#
# https://www.freedesktop.org/software/systemd/man/systemd.exec.html
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
# https://github.com/systemd/systemd/blob/master/NEWS
%>
[Service]
Type=<%= service_type %>
User=<%= app_user %>
Group=<%= app_group %>
WorkingDirectory=<%= working_dir %>
<%= for command <- exec_start_pre do %>
ExecStartPre=<%= command %>
<% end %>
ExecStart=<%= "#{exec_start_wrap}#{current_dir}/bin/#{release_name} #{start_command}" %>
ExecStop=<%= "#{current_dir}/bin/#{release_name} stop" %>
Environment=LANG=<%= env_lang %>
Environment=MIX_ENV=<%= mix_env %>
<%= if :runtime in dirs do %>Environment=RUNTIME_DIR=<%= runtime_dir %><% end %>
<%= if :configuration in dirs do %>Environment=CONFIGURATION_DIR=<%= configuration_dir %><% end %>
<%= if :logs in dirs do %>Environment=LOGS_DIR=<%= logs_dir %><% end %>
<%= if :cache in dirs do %>Environment=CACHE_DIR=<%= cache_dir %><% end %>
<%= if :state in dirs do %>Environment=STATE_DIR=<%= state_dir %><% end %>
<%= if :tmp in dirs do %>Environment=TMP_DIR=<%= tmp_dir %><% end %>
<%= for file <- env_files do %>
EnvironmentFile=<%= file %>
<% end %>
<%= for env <- env_vars do %>
Environment=<%= env %>
<% end %>
<%= if service_type == :forking do %>
Environment=PIDFILE=<%= pid_file %>
PIDFile=<%= pid_file %>
<% end %>
LimitNOFILE=<%= limit_nofile %>
UMask=<%= umask %>
SyslogIdentifier=<%= syslog_identifier %>
Restart=<%= restart %>
<%= if restart_sec do %>RestartSec=<%= restart_sec %><% end %>
<%= if timeout_start_sec do %>TimeoutStartSec=<%= timeout_start_sec %><% end %>
<%= if :runtime in dirs do %>
RuntimeDirectory=<%= runtime_directory %>
RuntimeDirectoryMode=<%= runtime_directory_mode %>
<%= if systemd_version >= 235 do %>RuntimeDirectoryPreserve=<%= runtime_directory_preserve %><% end %>
<% end %>
<%= if systemd_version >= 235 do %>
<%= if :configuration in dirs do %>
ConfigurationDirectory=<%= configuration_directory %>
ConfigurationDirectoryMode=<%= configuration_directory_mode %>
<% end %>
<%= if :logs in dirs do %>
LogsDirectory=<%= logs_directory %>
LogsDirectoryMode=<%= logs_directory_mode %>
<% end %>
<%= if :state in dirs do %>
StateDirectory=<%= state_directory %>
StateDirectoryMode=<%= state_directory_mode %>
<% end %>
<%= if :cache in dirs do %>
CacheDirectory=<%= cache_directory %>
CacheDirectoryMode=<%= cache_directory_mode %>
<% end %>
<% end %>
<%= if chroot do %>
RootDirectory=<%= root_directory %>
<%= if length(read_write_paths) > 0 do %>ReadWritePaths=<%= Enum.join(read_write_paths, " ") %><% end %>
<%= if length(read_only_paths) > 0 do %>ReadOnlyPaths=<%= Enum.join(read_only_paths, " ") %><% end %>
<%= if length(inaccessible_paths) > 0 do %>InaccessiblePaths=<%= Enum.join(inaccessible_paths, " ") %><% end %>
<% end %>
<%= if paranoia do %>
NoNewPrivileges=yes
PrivateDevices=yes
PrivateTmp=yes
ProtectSystem=full
ProtectHome=yes
<%= if systemd_version >= 232 do %>
PrivateUsers=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectControlGroups=yes
<% end %>
<%= if systemd_version >= 233 do %>MountAPIVFS=yes<% end %>
<%#
# RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
# SELinuxContext=
# AppArmorProfile=
# SmackProcessLabel=
%>
<% end %>
<%#
# KillMode=process # default control-group
# TimeoutSec=10
# RemainAfterExit=no
# https://elixirforum.com/t/distillery-node-is-not-running-and-non-zero-exit-code/3834
# SuccessExitStatus=143
%>
[Install]
WantedBy=multi-user.target