是否有可能在计算引擎中看到输出启动脚本

我的计算引擎虚拟机部署时运行一个启动脚本。 一切似乎运作良好,但有启动脚本中的一个命令,我认为它没有。

我运行命令

apt-get update && apt-get upgrade -y 

这应该安装所有软件包的最新版本(对吧?)

当我手工做这个工作,但它需要很多时间。 如果我让脚本做到这一点,我没有看到任何输出,当我通过SSH连接,所以我必须认为它仍然在运行。 有没有办法,我可以看到,如果它仍然工作,如果它已经完成或没有?

这是脚本:

 #! /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 

根据实例的Linux发行版,Google Cloud Compute Engine实例的启动脚本输出被写入以下日志文件之一:

  • CentOS和RHEL:/ var / log / messages
  • Debian:/var/log/daemon.log
  • Ubuntu 14.04,16.04和16.10:/ var / log / syslog
  • SLES 11和12:/ var / log / messages

如果由于某种原因,您希望存储脚本的更新,则可以考虑将输出redirect到一个文件并将ID上传到Google Storage。 例如:

  ... $ command >> output $ command >> output $ gsutil cp output gs://yourbucketname/output $ command >> output ... $ command >> output $ gsutil cp output gs://yourbucketname/output $ ... 

请注意,您可能会考虑将“ 2>> ”的标准错误redirect到文件并上传。

编辑:我忘了回答你的问题之一。 是的,你可以检查命令是否仍在运行; 因为从操作系统的angular度来看,这些命令是正常的进程,因此您可以检查它们是否正常运行:

 $ ps -aux 

例如,我得到这个输出sleep作为启动脚本

 root 691 0.0 0.0 5840 696 ? S 14:45 0:00 sleep 30