Apyc
Apyc

Reputation: 337

Cloud storage directory disappears when restarting instance

I have attached a standard persistent disk to the instance. On that disk I have created a directory 'cloud-storage' (as always mkdir) in which I mount the bucket (Google Cloud Storage). Also I have added to fstab the command to mount it:

bucket_name /mnt/disks/disk1/cloud-storage gcsfuse 
rw,file_mode=0770,dir_mode=0770,uid=33,gid=33,noatime,_netdev,noexec,user,implicit_dirs,allow_other 0 3

To mount it: mount /mnt/disks/disk1/cloud-storage

I access the Google Cloud Storage bucket without problems: it is mounted, unmounted and I access the data. When the bucket is mounted if I manually unmount it the 'cloud-storage' directory does not disappear. (its normal)

Problem: When I restart the instance and access the standard persistent disk the directory 'cloud-storage' does not exist.

Do I have to create a script that creates the 'cloud-storage' directory and then mount the bucket to run after reboot? Where should I call that script from? I must create the directory after mounting the standard disk and before mounting the bucket.

Upvotes: 3

Views: 1192

Answers (1)

Kevin Quinzel
Kevin Quinzel

Reputation: 1428

You are right, whenever you reboot your instance, you must mount your GCS bucket again. I know this can be a bummer, but there is a workaround for this:

Startup scripts let you set scripts that will automatically run each time your GCE instance starts or reboots. What you can do is to add the commands to mount the GCS bucket in this startup script and when the VM is up and ready to serve, you should see your GCS bucket mounted and ready to work. These scripts are written in Bash.

You can add the logic in this script about the directory after the standard disk and before mounting your bucket without going too-manual.

Also, make sure that the flow of your startup script meets your other tech requirements. Not adding a dependence after running the script that uses it or something similar.

I know some of the last scenarios might not suit to yours but I just want to make sure you have a wider insight for possible future implementations.

Hope this is helpful! :)

Upvotes: 2

Related Questions