-
-
Save ray-moncada/f3fa95906bc5d5b483d41ae7132f0906 to your computer and use it in GitHub Desktop.
manage a vagrant host with systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# script to stop vagrant box for use with systemd | |
# place scripts into /usr/lib/systemd/scripts/ | |
# be sure to put the .service file in /lib/systemd/system/ | |
# | |
# -- Geoffrey McClinsey | |
VAGRANTUSR=vagrant # user you want vagrant box to run as | |
VAGRANTBOXPATH= # add path to Vagrantfile | |
cd ${VAGRANTBOXPATH} | |
su -c "/usr/bin/vagrant halt" ${VAGRANTUSR} > /dev/null 2>&1 | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# script to start vagrant box for use with systemd | |
# place scripts into /usr/lib/systemd/scripts | |
# | |
# -- Geoffrey McClinsey | |
VAGRANTUSR=vagrant # user you want vagrant box to run as | |
VAGRANTBOXPATH= # add path to Vagrantfile | |
cd ${VAGRANTBOXPATH} | |
su -c "/usr/bin/vagrant up" ${VAGRANTUSR} > /dev/null 2>&1 | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vagrant service file to start/stop a specific box | |
# be sure to adjust ExecStart and ExecStop to match the name of scripts | |
# located in /usr/lib/systemd/scripts/ | |
# | |
# Once all files are in place use systemctl enable vagrant-hostname.service | |
# and then you can sudo service start/stop | |
# | |
# -- Geoffrey McClinsey | |
[Unit] | |
Description=power-on/off vagrant box | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/lib/systemd/scripts/vagrant-hostname-up.sh | |
ExecStop=/usr/lib/systemd/scripts/vagrant-hostname-down.sh | |
RemainAfterExit=yes | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment