Running the script doesn't seem to work

I recently started using Google Compute for some of my projects, the problem is that my script run doesn't seem to work, for some reason my script just doesn't work, the VM has a run - metadata script, and it works fine when I I launch it manually using

sudo google_metadata_script_runner --script-type startup

Here is what I am trying to run at startup:

#!/bin/bash
sudo apt-get update
sudo rm -f Eve.jar
sudo rm -f GameServerStatus.jar
wget <URL>/Eve.jar
wget <URL>/GameServerStatus.jar
sudo chmod 7777 Eve.jar
sudo chmod 7777 GameServerStatus.jar
screen -dmS Eve sh Eve.sh
screen -dmS PWISS sh GameServerStatus.sh

There are no errors in the log, it just stops at the chmod or screen commands. Any ideas?

Thank!

+4
source share
4 answers
  • Go to the VM instances page.
  • Click on the instance for which you want to add a launch script.
  • Click the "Edit" button at the top of the page.
  • " " " ".
  • script :

startup- script: script . startup- script -URL: URL- Google script .

. , GCE Startup Script

script :

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

Ubuntu 12.04, SLES 11 12, , v20160606:

sudo /usr/share/google/run-startup-scripts
+2

, . startup-script :

touch a
ls -al > test.txt

sudo google_metadata_script_runner --script-type startup, , , , . ,

...
Jul  3 04:30:37 kbot-6 ntpd[1514]: Listen normally on 5 eth0 fe80::4001:aff:fe8c:7 UDP 123
Jul  3 04:30:37 kbot-6 ntpd[1514]: peers refreshed
Jul  3 04:30:37 kbot-6 ntpd[1514]: Listening on routing socket on fd #22 for interface updates
Jul  3 04:30:38 kbot-6 startup-script: INFO Starting startup scripts.
Jul  3 04:30:38 kbot-6 startup-script: INFO Found startup-script in metadata.
Jul  3 04:30:38 kbot-6 startup-script: INFO startup-script: Return code 0.
Jul  3 04:30:38 kbot-6 startup-script: INFO Finished running startup scripts.

. . , . :

pwd > /tmp/pwd.txt
whoami > /tmp/whoami.txt

:

myuserid@kbot-6:/tmp$ cat pwd.txt whoami.txt
/
root

. / diectory root. , sudo -u myuserid bash -c... .

0

, sudo, chmod 7777 777

cd (, , pwd) .

... , , .

0

To add an answer to Kanbu:

Checking logs in a container-optimized OS

sudo journalctl -u google-startup-scripts.service

showed that the script cannot find the user. After a long debugging time, I finally added a delay before sudo, and now it works. It seems the user is not registered when the script is launched.

#! /bin/bash

sleep 10  # wait...
cut -d: -f1 /etc/passwd > /home/user/users.txt  # make sure the user exists
cd /home/user/eventmatch/deploy  # cd does not work after sudo, do it before
sudo -u user bash -c '\
source /home/user/.bashrc &&
<your-task> && \
date > /home/user/startup.log'
0
source

Source: https://habr.com/ru/post/1677599/


All Articles