Skip to content

Commit 8f1b858

Browse files
committed
Daemon - remove .bat file usage from Windows boot process
On some Windows clusters security policies have been set which precludes users from using CMD on Windows. This means that cmd.exe isn't available and also that .bat files cannot be run. In v4 Sonic Pi switched from basic Erlang to Elixir releases which are managed by .bat files. This has caused booting errors on those systems. This patch removes the need to use .bat files in the booting process on Windows. * ENV vars are set in the daemon rather than the tau boot script (for all platforms) * tau boot script is no longer used on Windows for prod mode - instead the path and arguments to erl.exe are hard coded A similar approach to other platforms for avoiding using the tau boot script in prod mode should be tested and possibly committed in the future. Addresses #3207
1 parent 09217b2 commit 8f1b858

File tree

5 files changed

+92
-95
lines changed

5 files changed

+92
-95
lines changed

app/server/beam/tau/boot-lin.sh

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ cd "${SCRIPT_DIR}"
55

66
echo "Booting Tau on Linux..."
77

8-
export TAU_CUES_ON=$1
9-
export TAU_OSC_IN_UDP_LOOPBACK_RESTRICTED=$2
10-
export TAU_MIDI_ON=$3
11-
export TAU_LINK_ON=$4
12-
export TAU_OSC_IN_UDP_PORT=$5
13-
export TAU_API_PORT=$6
14-
export TAU_SPIDER_PORT=$7
15-
export TAU_DAEMON_PORT=$8
16-
export TAU_LOG_PATH=${9}
17-
export TAU_MIDI_ENABLED=${10}
18-
export TAU_LINK_ENABLED=${11}
19-
export TAU_PHX_PORT=${12}
20-
export SECRET_KEY_BASE=${13}
21-
export TAU_DAEMON_TOKEN=${14}
22-
export TAU_ENV=${15}
23-
export MIX_ENV=$TAU_ENV
24-
258
if [ $TAU_ENV = "prod" ]
269
then
2710
_build/prod/rel/tau/bin/tau start > /dev/null 2>&1

app/server/beam/tau/boot-mac.sh

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ cd "${SCRIPT_DIR}"
55

66
echo "Booting Tau on macOS..."
77

8-
export TAU_CUES_ON=$1
9-
export TAU_OSC_IN_UDP_LOOPBACK_RESTRICTED=$2
10-
export TAU_MIDI_ON=$3
11-
export TAU_LINK_ON=$4
12-
export TAU_OSC_IN_UDP_PORT=$5
13-
export TAU_API_PORT=$6
14-
export TAU_SPIDER_PORT=$7
15-
export TAU_DAEMON_PORT=$8
16-
export TAU_LOG_PATH=${9}
17-
export TAU_MIDI_ENABLED=${10}
18-
export TAU_LINK_ENABLED=${11}
19-
export TAU_PHX_PORT=${12}
20-
export SECRET_KEY_BASE=${13}
21-
export TAU_DAEMON_TOKEN=${14}
22-
export TAU_ENV=${15}
23-
export MIX_ENV=$TAU_ENV
24-
258
if [ $TAU_ENV = "prod" ]
269
then
2710
_build/prod/rel/tau/bin/tau start > /dev/null 2>&1

app/server/beam/tau/boot-win.bat

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ rem mix release
55

66
@echo Booting Tau on Windows...
77

8-
set TAU_CUES_ON=%1%
9-
set TAU_OSC_IN_UDP_LOOPBACK_RESTRICTED=%2%
10-
set TAU_MIDI_ON=%3%
11-
set TAU_LINK_ON=%4%
12-
set TAU_OSC_IN_UDP_PORT=%5%
13-
set TAU_API_PORT=%6%
14-
set TAU_SPIDER_PORT=%7%
15-
set TAU_DAEMON_PORT=%8%
16-
set TAU_LOG_PATH=%9%
17-
shift
18-
set TAU_MIDI_ENABLED=%9%
19-
shift
20-
set TAU_LINK_ENABLED=%9%
21-
shift
22-
set TAU_PHX_PORT=%9%
23-
shift
24-
set SECRET_KEY_BASE=%9%
25-
shift
26-
set TAU_DAEMON_TOKEN=%9%
27-
shift
28-
set TAU_ENV=%9%
29-
30-
set MIX_ENV=%TAU_ENV%
31-
328
IF "%TAU_ENV%" == "prod" (
339
_build\prod\rel\tau\bin\tau start > NUL 2>&1
3410
)

app/server/ruby/bin/daemon.rb

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -934,48 +934,51 @@ def initialize(ports, kill_switch, token)
934934
unified_opts = {}
935935
end
936936

937-
cues_on = true
938-
osc_in_udp_loopback_restricted = false
939-
midi_on = true
940-
link_on = true
941-
osc_in_udp_port = ports["osc-cues"]
942-
api_port = ports["tau"]
943-
spider_port = ports["spider-listen-to-tau"]
944-
daemon_port = ports["daemon"]
945-
midi_enabled = true
946-
link_enabled = true
947-
phx_secret_key_base = SecureRandom.base64(64)
948-
env = ENV["SONIC_PI_ENV"] || unified_opts[:env] || "prod"
949-
@phx_port = unified_opts[:phx_port] || ports["phx"]
950-
951-
Util.log "Daemon listening to info from Tau on port #{daemon_port}"
952-
953-
args = [
954-
cues_on,
955-
osc_in_udp_loopback_restricted,
956-
midi_on,
957-
link_on,
958-
osc_in_udp_port,
959-
api_port,
960-
spider_port,
961-
daemon_port,
962-
Paths.tau_log_path,
963-
midi_enabled,
964-
link_enabled,
965-
phx_port,
966-
phx_secret_key_base,
967-
token,
968-
env
969-
]
937+
@phx_port = unified_opts[:phx_port] || ports["phx"]
938+
939+
Util.log "Daemon listening to info from Tau on port #{ports["daemon"]}"
940+
941+
ENV["TAU_CUES_ON"] = "true"
942+
ENV["TAU_OSC_IN_UDP_LOOPBACK_RESTRICTED"] = "false"
943+
ENV["TAU_MIDI_ON"] = "true"
944+
ENV["TAU_LINK_ON"] = "true"
945+
ENV["TAU_OSC_IN_UDP_PORT"] = "#{ports["osc-cues"]}"
946+
ENV["TAU_API_PORT"] = "#{ports["tau"]}"
947+
ENV["TAU_SPIDER_PORT"] = "#{ports["spider-listen-to-tau"]}"
948+
ENV["TAU_DAEMON_PORT"] = "#{ports["daemon"]}"
949+
ENV["TAU_MIDI_ENABLED"] = "true"
950+
ENV["TAU_LINK_ENABLED"] = "true"
951+
ENV["SECRET_KEY_BASE"] = "#{SecureRandom.base64(64)}"
952+
ENV["TAU_DAEMON_TOKEN"] = "#{token}"
953+
ENV["TAU_ENV"] = "#{ENV["SONIC_PI_ENV"] || unified_opts[:env] || "prod"}"
954+
ENV["MIX_ENV"] = ENV["TAU_ENV"]
955+
ENV["TAU_PHX_PORT"] = "#{@phx_port}"
956+
ENV["TAU_LOG_PATH"] = "#{Paths.tau_log_path}"
970957

971958
if Util.os == :windows
972-
cmd = Paths.mix_release_boot_path
959+
if ENV["TAU_ENV"] == "prod"
960+
ENV["RELEASE_SYS_CONFIG"] = "#{Paths.tau_release_sys_config_path}"
961+
ENV["RELEASE_ROOT"] = "#{Paths.tau_release_root}"
962+
963+
cmd = "#{Paths.tau_release_erl_bin_path}".gsub('/', '\\')
964+
args = ["-config", "#{Paths.tau_release_sys_path}".gsub('/', "\\"),
965+
"-boot", "#{Paths.tau_release_start_path}".gsub('/', "\\"),
966+
"-boot_var", "RELEASE_LIB", "#{Paths.tau_release_lib_path}".gsub('/', "\\"),
967+
"-args_file", "#{Paths.tau_release_vm_args_path}".gsub('/', "\\"),
968+
"-noshell",
969+
"-s", "elixir", "start_cli",
970+
"-mode", "embedded",
971+
"-extra", "--no-halt"]
972+
else
973+
cmd = Paths.mix_release_boot_path
974+
args = []
975+
end
973976
else
974977
cmd = "sh"
975-
args = [Paths.mix_release_boot_path] + args
978+
args = [Paths.mix_release_boot_path]
976979
end
977980

978-
super(cmd, args, nil)
981+
super(cmd, args, Paths.tau_boot_log_path)
979982
end
980983

981984
def restart!

app/server/ruby/paths.rb

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ def self.tau_log_path
167167
File.absolute_path("#{log_path}/tau.log")
168168
end
169169

170+
def self.tau_boot_log_path
171+
File.absolute_path("#{log_path}/tau_boot.log")
172+
end
173+
170174
def self.jackd_log_path
171175
File.absolute_path("#{log_path}/jackd.log")
172176
end
@@ -215,8 +219,56 @@ def self.mix_release_boot_path
215219
end
216220
end
217221

222+
def self.tau_base_path
223+
File.absolute_path("#{server_path}/beam/tau")
224+
end
225+
226+
def self.tau_release_path
227+
File.absolute_path("#{tau_base_path}/_build/prod/rel/tau/releases/0.1.0")
228+
end
229+
230+
def self.tau_release_root
231+
File.absolute_path("#{tau_base_path}/_build/prod/rel/tau")
232+
end
233+
234+
def self.tau_release_erl_bin_path
235+
case os
236+
when :windows
237+
base = File.absolute_path("#{tau_base_path}/_build/prod/rel/tau")
238+
erts_dir = Dir["#{base}/erts-*"][0]
239+
path = File.absolute_path("#{erts_dir}/bin/erl.exe")
240+
241+
raise "Unable to find erl.exe. Did the Elixir build release work correctly? I looked here: #{path.inspect}" unless File.exist?(path)
242+
path
243+
when :macos
244+
245+
else
246+
247+
end
248+
end
249+
250+
def self.tau_release_sys_config_path
251+
File.absolute_path("#{tau_release_path}/sys")
252+
end
253+
254+
def self.tau_release_sys_path
255+
File.absolute_path("#{tau_release_path}/sys")
256+
end
257+
258+
def self.tau_release_start_path
259+
File.absolute_path("#{tau_release_path}/start")
260+
end
261+
262+
def self.tau_release_vm_args_path
263+
File.absolute_path("#{tau_release_path}/vm.args")
264+
end
265+
266+
def self.tau_release_lib_path
267+
File.absolute_path("#{tau_base_path}/_build/prod/rel/tau/lib")
268+
end
269+
218270
def self.tau_app_path
219-
File.absolute_path("#{server_path}/beam/tau/ebin")
271+
File.absolute_path("#{tau_base_path}/ebin")
220272
end
221273

222274
def self.user_audio_settings_path

0 commit comments

Comments
 (0)