My Compute Engine vm when deployed run a startup script. Everything seems working well, but there is one command in the startup script which I think it doesn't.
I run the command
apt-get update && apt-get upgrade -y
This should install the newest versions of all packages (right?)
When I do this by hand it works, but it takes a lot of time. If I let the script do it I don't see any output when I connect over ssh so I have to asume it's still running. Is there a way I can see if it is still working and if it has finished or not?
This is the script:
#! /bin/bash
file="/var/www/check.txt"
if [ -e $file ]
then
apt-get update && apt-get upgrade -y
git -C /var/www/html pull https://xxxxxx:[email protected]/xxxxxx/xxxxx.git
else
apt-get update
apt-get install apache2 php libapache2-mod-php php-mcrypt php-mysql mysql-client -y
a2dismod autoindex
service apache2 restart
cat <<EOF > /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.php index.cgi index.pl index.html index.xhtml index.htm
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
rm -rf /var/www/html
git clone https://xxxxxx:[email protected]/xxxxxx/xxxxx.git /var/www/html/
cat <<EOF > /etc/apache2/sites-available/xxxxx.conf
<VirtualHost *:80>
ServerName xxxxxx.com
ServerAlias www.xxxxxx.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/wwwroot
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
cat <<EOF > /etc/apache2/sites-available/020-xxxxx_xxxx.conf
<VirtualHost *:80>
ServerName xxxx.xxxxx.xxx
ServerAlias xxxx
ServerAdmin [email protected]
DocumentRoot /var/www/html/xxxxx
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
cat <<EOF > /var/www/html/wwwroot/.htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
EOF
sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
chmod +x cloud_sql_proxy
mkdir /cloudsql; sudo chmod 777 /cloudsql
./cloud_sql_proxy -dir=/cloudsql &
#rm /var/www/html/wwwroot/xxxxx/xxxxxx.php
#temporary for testing.
cat <<'EOF' > /var/www/html/wwwroot/includes/xxxxx.xxxx
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$username = "xxxxxx";
$password = "xxxxx";
$host = "/cloudsql/snappy-gantry-xxxxx:europe-west1:db1";
$dbname = "xxxxx";
setlocale(LC_ALL, 'nld_nld');
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try {
$db = new PDO("mysql:unix_socket={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $ex) {
die("Failed to connect to the database: " . $ex->getMessage());
}
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
EOF
a2dissite 000-default
a2ensite 010-xxxxx_main
a2ensite 020-xxxx_help
a2enmod rewrite
service apache2 restart
apt-get update && apt-get upgrade -y
sudo cat <<EOF > /var/www/check.txt
aanwezig!
EOF
fi