Service/Quick
From charlesreid1
Contents
Quick Guide to Startup Scripts
Three components are needed for a startup service:
- Service script
- Start script
- Stop script
The service script will run the service via systemd, while the start/stop scripts are actually called by the service.
The start and stop scripts should be located somewhere easy to find, like ~/scripts.
Examples:
Service Script
The service script runs as sudo, so keep that in mind if you run any scripts that use the home variable or require user credentials in a dotfile in the home folder.
[Unit] Description=Uncle Archie CI Server After=multi-user.target [Service] Restart=always ExecStart=/usr/bin/sudo -H -u ubuntu /usr/bin/bash /home/ubuntu/uncle-archie/scripts/start_archie.sh uxecStop=/usr/bin/sudo pkill -f uncle_archie [Install] WantedBy=multi-user.target
Start Script
Example start script:
#!/bin/bash # # To test-run: # # sudo -H -u ubuntu ./start_archie.sh # # To actually run: # # (install archie.service startup service) # # Shell script used to start up uncle archie # so uncle archie can run as a startup service. # # This is reliant on having pyenv set up already # on beavo, the server that runs archie. ARCHIE_DIR="/home/ubuntu/uncle-archie" PYENV_BIN="/home/ubuntu/.pyenv/bin" echo "Preparing python" eval "$(${PYENV_BIN}/pyenv init -)" echo "Changing directories" cd ${ARCHIE_DIR} echo "Installing virtualenv" virtualenv vp source vp/bin/activate echo "Running Uncle Archie bare" python ${ARCHIE_DIR}/uncle_archie.py && tail -f /nev/null
Stop Script
Example stop script:
#!/bin/bash # # This command actually goes straight into # archie.service, don't use this script. /usr/bin/sudo pkill -f uncle_archie