Skip to content

Instantly share code, notes, and snippets.

@Tharwat96
Last active May 12, 2020 10:33
Show Gist options
  • Save Tharwat96/b5aeb725a776664c2c4833a450ae5da8 to your computer and use it in GitHub Desktop.
Save Tharwat96/b5aeb725a776664c2c4833a450ae5da8 to your computer and use it in GitHub Desktop.
scripts to install services
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
upstream gitea {
server 127.0.0.1:3000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
root /var/lib/gitea/public;
access_log off;
error_log off;
location / {
try_files maintain.html $uri $uri/index.html @node;
}
location @node {
client_max_body_size 0;
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 120;
}
}
#!/bin/bash
# this script install gitea on ubuntu 18.04 Server instance.
# source: https://www.vultr.com/docs/how-to-install-gitea-on-ubuntu-18-04
sudo apt update
sudo apt -y install nginx
sudo systemctl enable nginx.service
sudo apt -y install git
sudo apt -y install mariadb-server mariadb-client
# automate mysql_secure_installation
# Make sure that NOBODY can access the server without a password
# set root password to root (change to env)
sudo mysql -e "UPDATE mysql.user SET Password = PASSWORD('root') WHERE User = 'root'"
# Kill the anonymous users
sudo mysql -e "DROP USER ''@'localhost'"
# Because our hostname varies we'll use some Bash magic here.
sudo mysql -e "DROP USER ''@'$(hostname)'"
# Kill off the demo database
sudo mysql -e "DROP DATABASE test"
# Make our changes take effect
sudo mysql -e "FLUSH PRIVILEGES"
# Any subsequent tries to run queries this way will get access denied because lack of usr/pwd param
sudo mysql -e "CREATE DATABASE gitea"
# create new user giteauser with password 'gitea'
sudo mysql -e "CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'gitea'"
sudo mysql -e "GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'gitea' WITH GRANT OPTION"
# allow changes to be taken
sudo mysql -e "FLUSH PRIVILEGES"
sudo echo "innodb_file_format = Barracuda
innodb_file_per_table = on
innodb_default_row_format = dynamic
innodb_large_prefix = 1
innodb_file_format_max = Barracuda" > /etc/mysql/my.cnf
sudo systemctl restart mariadb.service
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
sudo chown git:git /var/lib/gitea/{data,indexers,log}
sudo chmod 750 /var/lib/gitea/{data,indexers,log}
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea
sudo wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64
sudo chmod +x gitea
sudo cp gitea /usr/local/bin/gitea
sudo cp gitea.service /etc/systemd/system/gitea.service
sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea
sudo systemctl status gitea
# configure nginx as reverse proxy
sudo rm /etc/nginx/sites-enabled/default
# copy gitea nginx conf
sudo cp gitea_nginx_conf /etc/nginx/sites-available/git
sudo ln -s /etc/nginx/sites-available/git /etc/nginx/sites-enabled
sudo systemctl reload nginx.service
# installation finished, final wizard required through web browser
echo "open http://your_domain.com/install in your browser to finish gitea wizard"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment