-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service wont start on boot #9
Comments
Hey @rescaux, I'm sorry to hear that you're having issues with ec2-macos-init. Would you be able to include any error message that was logged by ec2-macos-init? The log file's location is Also, that's strange that the script was only executed after a user logged in... I've tried reproducing the problem with the config you posted and my own test script. However, I wasn't able to see the exact behavior that you're describing. There was an error with the module you included -- it's missing a run type configuration ( My config looked like this:
The contents of
The permissions I have on the script:
The logs from priority level 4 after restarting the instance:
Could you try adding the run type configuration to your module and let me know what happens. Any error logs from that run would also be useful. |
Okay, I've now tried everything so far and it's still behaving weird. As one can see in this video, the script runs only when macos-ec2-init is invoked manually. It is invoked on boot as well, but won't do anything. |
Hi @rescaux, thanks for sharing the logs~
@mattcataws and I are wondering where in the script that this hangs. For example, does the script hang on the Domain Join, or when setting up the VPN connection? From the description provided and logs in your video seems, it like the script might be invoking a command that requires an active user login to complete (maybe a prompt, or initialization of some state by the OS).
|
Hi @jahkeup, I also have a similar issue. I am using mac2.metal and ec2-macos-init version ### Group 6
## Custom services
[[Module]]
Name = "StartGitlabRunner"
PriorityGroup = 6
RunPerBoot = true
[Module.Command]
Cmd = ["/Users/ec2-user/.gitlab-runner/run.sh"]
RunAsUser = "ec2-user" with my script as follows: #!/bin/bash
if pgrep -x gitlab-runner >/dev/null
then
echo "Skipping starting gitlab-runner as process is already running"
else
echo "Starting gitlab-runner process..."
/opt/homebrew/bin/gitlab-runner run &> /Users/ec2-user/.gitlab-runner/runner.log &
echo "Started gitlab-runner process"
fi
echo "process id: $(pgrep -x gitlab-runner)" The logs from the system restart are:
Which suggests that the server is actually starting, but then exits. I've tried adding a
Waiting for the
logs:
|
Thanks for reporting in and posting logs @rj93! We suspect you're up against a separate (but related) issue that comes into play when processes spawn in the context of a Launchd Daemon (and/or Agents). Processes created by Launchd Daemons (directly or indirectly) must not make system calls that would spawn a whole other conceptual "daemon process" according to the "Required Behaviors" section of Launchd documentation. It is likely you'll need a separate Launchd Daemon instance that launches and owns the GitLab CI runner process (set up with your flags and environment as needed). As written, the shared script creates a "background" process (from the @okudajun and I tried alternatives to spawn from executed scripts and still found that they failed to stick around or failed to run at all (the usual trustworthy Our team will need to look at how @rescaux - is there a process spawned in |
Hi @jahkeup, it may be worth me pointing out that this Heres a snippet from my userdata: # install gitlab-runner, etc
# ...
echo "Starting gitlab-runner..."
su - ec2-user -c '/Users/ec2-user/.gitlab-runner/run.sh'
echo "Started gitlab-runner"
# Won't run run as part of this ec2-macos-init process, but if the instance reboots will start the gitlab-runner
EC2_MACOS_INIT_FILE=/usr/local/aws/ec2-macos-init/init.toml
if ! grep -q "StartGitlabRunner" $EC2_MACOS_INIT_FILE
then
echo "Adding group ec2-macos-init..."
cat >> $EC2_MACOS_INIT_FILE <<-EOF
### Group 6
## Custom services
[[Module]]
Name = "StartGitlabRunner"
PriorityGroup = 6
RunPerBoot = true
[Module.Command]
Cmd = ["/Users/ec2-user/.gitlab-runner/run.sh"]
RunAsUser = "ec2-user"
EOF
echo "Added group ec2-macos-init"
else
echo "Skipping adding group to ec2-macos-init"
fi
echo "Finished userdata script"
I was hoping to get away without having to use launchd, but thanks for the feedback I will go down that route instead. Heres the logs from instance launch:
And the process is running:
|
Hi @rj93 - what did you end up doing? I'm trying to do the same thing (setup gitlab-runner to run at boot on a m2.metal instance) and ran into a different set of issues (trying to use
I'm confused about what is being recommended. I created a launch daemon in Thanks! |
Ah, sorry! You're right, yes, we are recommending to create a job - using user data - and then loading it to run under launchd. And yeah, that lack of support seems to me because of the particulars of creating and managing the LaunchDaemon and/or LaunchAgent. (to @sourcedelica , skip to the bottom of this reply then come back here!) For general needs, it could be simple enough to run a LaunchDaemon in the This means that a launchd job, say And, yeah, that means we're going to have to work with launchd jobs. Some relevant links (n.b. in archive docs):
(maybe this works for you @sourcedelica ?) There are some convenience service helpers in Homebrew for formulas to use. This works for formulas that define a service - and this is set Per https://docs.brew.sh/Manpage#services-subcommand something like this should do the trick: #!/usr/bin/env sh
logger -s -t userdata "installing gitlab-runner"
brew install gitlab-runner
logger -s -t userdata "enabling, starting gitlab-runner service"
# re: "sudo" - see https://docs.brew.sh/Manpage#services-subcommand
sudo brew services start gitlab-runner |
I ended up getting the Gitlab runner-installed LaunchAgent working through some hackery. Basically this was:
When the machine reboots (and every boot thereafter) the ec2-user is auto-logged in and now the LaunchAgent associated with ec2-user works. Here are the last few commands in the user-data script:
|
Dear ec2-macos-init contributors,
I've now tried multiple times (directly through launchd and through ec2-macos-init) to run a simple binary on system boot. This aims to join the machine to an Active Directory, etc... What I managed with this config so far was, that the script got executed correctly - but only a few seconds after a (random) user logged in to the machine - not on boot.
The config looks like this:
chmod on the binary is a+x
The text was updated successfully, but these errors were encountered: