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
"#{current_dir}/bin/#{app_name} start"
else
"#{current_dir}/bin/#{app_name} foreground"
end
%>
[Service]
Type=<%= service_type %>
User=<%= app_user %>
Group=<%= app_group %>
WorkingDirectory=<%= current_dir %>
<%= for command <- exec_start_pre do %>
<%= if String.starts_with?(command, "/") do %>
ExecStartPre=<%= command %>
<% else %>
ExecStartPre=<%= scripts_dir %>/<%= command %>
<% end %>
<% end %>
<%= if runtime_environment_wrap do %>
<%= if String.starts_with?(runtime_environment_wrap_script, "/") do %>
ExecStart=<%= runtime_environment_wrap_script %> <%= start_command %>
<% else %>
ExecStart=<%= scripts_dir %>/<%= runtime_environment_wrap_script %> <%= start_command %>
<% end %>
<% else %>
ExecStart=<%= start_command %>
<% end %>
ExecStop=<%= current_dir %>/bin/<%= app_name %> stop
Environment=LANG=<%= env_lang %>
Environment=HOME=<%= home_dir %>
Environment=MIX_ENV=<%= mix_env %>
Environment=RELEASE_MUTABLE_DIR=<%= runtime_dir %>
Environment=DEFAULT_COOKIE_FILE=<%= configuration_dir %>/erlang.cookie
Environment=PORT=<%= env_port %>
<%= 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