Current section
Files
Jump to
Current section
Files
priv/templates/systemd.service.eex
[Unit]
Description=<%= service_name %> service
After=local-fs.target network.target<%= if runtime_environment_wrap do %> <%= runtime_environment_service_after %><% end %><%= if runtime_environment_service do %> <%= service_name %>-runtime-environment.service<% 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
%>
<% start_command = if service_type == :forking, do: "start", else: "foreground" %>
<% wrap_command = if runtime_environment_wrap, do: runtime_environment_wrap_script <> " ", else: "" %>
[Service]
Type=<%= service_type %>
User=<%= app_user %>
Group=<%= app_group %>
WorkingDirectory=<%= deploy_dir %>
<%= for command <- exec_start_pre do %>
ExecStartPre=<%= command %>
<% end %>
ExecStart=<%= "#{wrap_command}#{current_dir}/bin/#{app_name} #{start_command}" %>
ExecStop=<%= "#{current_dir}/bin/#{app_name} stop" %>
Environment=LANG=<%= env_lang %>
Environment=MIX_ENV=<%= mix_env %>
Environment=PORT=<%= env_port %>
Environment=DEPLOY_DIR=<%= deploy_dir %>
Environment=CONFIGURATION_DIR=<%= configuration_dir %>
Environment=RUNTIME_DIR=<%= runtime_dir %>
Environment=RELEASE_MUTABLE_DIR=<%= runtime_dir %>
<%= case cookie_dir do
:home ->
""
:configuration_dir ->
"Environment=DEFAULT_COOKIE_FILE=#{configuration_dir}/#{cookie_file}"
:runtime_dir ->
"Environment=DEFAULT_COOKIE_FILE=#{runtime_dir}/#{cookie_file}"
cookie_dir ->
"Environment=DEFAULT_COOKIE_FILE=#{cookie_dir}/#{cookie_file}"
end
%>
<%= if conform do %>
Environment=CONFORM_CONF_PATH=<%= conform_conf_path %>
<% end %>
<%= for env <- env_vars do %>
Environment=<%= env %>
<% end %>
EnvironmentFile=-<%= current_dir %>/etc/environment
EnvironmentFile=-<%= deploy_dir %>/etc/environment
<%= if :configuration in dirs do %>
EnvironmentFile=-<%= configuration_dir %>/environment
<% end %>
EnvironmentFile=-<%= runtime_dir %>/runtime-environment
<%= if service_type == :forking do %>
Environment=PIDFILE=<%= pid_file %>
PIDFile=<%= pid_file %>
<% end %>
LimitNOFILE=<%= limit_nofile %>
UMask=<%= umask %>
SyslogIdentifier=<%= service_name %>
Restart=always
RestartSec=<%= restart_sec %>
# PermissionsStartOnly=true
<%= 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