Giter Club home page Giter Club logo

Comments (11)

xinglunxu avatar xinglunxu commented on July 20, 2024

Here is my proposed solution.
In the Vagranfile, under "config.vm.provision section", insert a line of command to run a script file. This script file will use the OSX launchd service to make the system run the "vagrant reload" command every time the system boot.

from ole--vagrant-community.

dogi avatar dogi commented on July 20, 2024

@xinglunxu thanks for the first part which is not as easy as you think ;)
not everybody has a macosx ;)
-> we will solve that in a later step

Anyhow right now I am very much interested in that script which will use OSX launchd
@xinglunxu add more links
and/or a possible solution

from ole--vagrant-community.

xinglunxu avatar xinglunxu commented on July 20, 2024

Here is a link to the official launchd manual.
It is like a system service native in osx.
https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/ScheduledJobs.html
It should be easy to use because it is all about removing and adding file.
For example, there is directory whose files will be run by the system on every boot. We only need to add our script reloading the vagrant machine to this directory. Not exactly but something similar to this. I am still learning.

We can also use crontab to do the same thing and it might be easier. But from what I learned, it seems that crontab is a deprecated service and launchd is a better solution. The difference between crontab and launchd is also stated in the launchd manual given above.

As for the script to reload the vagrant machine, there are some problems.
I like to use "vagrant reload" to reboost the "community" vagrant machine.
This can be achieve in two ways. One require the id or name of the machine and the other require the path of the vagrant machine. I prefer the former one.
I believe that the id of vagrant machine is different for different host so we need to use the name of machine to target it. However, I fail to do that.
For example, vagrant reload community does not work when "community" is the name of the machine.
I am still trying to figure out how to write this script.

from ole--vagrant-community.

xinglunxu avatar xinglunxu commented on July 20, 2024

So after hours of searching and testing, I am now finally able to run a vagrant machine on boot in Mac using launchd service, at lease on my machine. The whole process does not require any GUI operation or any mousing. It uses only terminal commands.

First, let me briefly explain how it work. There is a folder in mac that users can place plist file inside and the system will run all the files inside one by one on boot. The folder path is /Library/LaunchDaemons/ . So we are going to create a plist file to somehow run the command "vagrant reload <id/name>" and place it into this folder. And that's it.

In detail, here is what I did to make it work.

1. Create a plist file in path /Library/LaunchDaemons/ .

As for what is plist file and how to write one, here are some good references:
Official One
Non Official but also good one
And the code for my plist file, com.example.test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.example.test</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Users/username/hw.sh</string>
        </array>
        <key>WorkingDirectory</key>
                <string>/Users/username</string>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

What this plist file mainly does is that it run a script file in path /Users/username/hw.sh.

2. Create a script file in path /Users/username/hw.sh.

The code for the script file:

#!/bin/bash

export PATH=$PATH:/usr/local/bin
sudo -u <username> vagrant reload <id/name>

This script file will run the command to reload the vagrant machine.
The reason that I run this command as another user using sudo is because of the following(Actually I am not positive about this). When the system runs the vagrant command in the script above, it runs as root user. Root user cannot manage the vagrant machine because vagrant machines are created by normal users and only the creator users can manage their machines.
As a result, I tried to run the vagrant command as a log-in user.
Also, we need to set the permissions of the /Users/username/hw.sh file. For simplicity purpose, I run chmod 777 /Users/username/hw.sh so that it can be read and written by anyone.

And that's it. When the system reboot, this plist file will be run and the vagrant machine will be reloaded.
We can test the plist file by running the command
sudo launchctl load /Library/LaunchDaemons/com.example.test.plist

I am not sure that if I miss something. If I do find out I will add more.

from ole--vagrant-community.

EmilyLarkin avatar EmilyLarkin commented on July 20, 2024

@xinglunxu very impressed with this work, looks quite good. I'm a Mac user and I would love to test it out if you have an "installvagrantboot"script that you can send to me via pull request. If you do, I'll test it and get back to you. If anyone else uses a Mac OS, let us know and it would be great to have multiple people test it once the script is done by @xinglunxu.

from ole--vagrant-community.

xinglunxu avatar xinglunxu commented on July 20, 2024

May I ask what you want this "installvagrantboot" script to do?

from ole--vagrant-community.

dogi avatar dogi commented on July 20, 2024

@xinglunxu that script should install all the modifications necessary to get vagrant started on boot ;)

by the way we should also think about an uninstall script ...

from ole--vagrant-community.

dogi avatar dogi commented on July 20, 2024

@xinglunxu #11

from ole--vagrant-community.

EmilyLarkin avatar EmilyLarkin commented on July 20, 2024

@xinglunxu so I tested it and it works well, thanks! We should continue to work on it and clean it up a bit (we should change where the files go and such), but overall, looks good.
Information on how to start is should be included in our code but it's a great start!!

from ole--vagrant-community.

xinglunxu avatar xinglunxu commented on July 20, 2024

@EmilyLarkin Hi, during the hangout, you mentioned that sometimes the vagrantboot script does not work. Can you give me more information here?
Edit: BTW, when you run installvagrantboot.sh, a stde.txt and stdo.txt files are generated on the same path and their purpose is to store debug message. You can look into them if something go wrong.

from ole--vagrant-community.

EmilyLarkin avatar EmilyLarkin commented on July 20, 2024

@xinglunxu absolutely, I do want to play around with it a bit more because I don't really know why or how, but I know that it doesn't always work.

Let me test it out tomorrow and get back to you once I can give you more details.

from ole--vagrant-community.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.