Question

How to restore droplet with R pulmber API running?

I have created a Rstudio droplet with a plumber API under the user ‘rtest’ at location ‘/home/test/api.R’. I have taken a snapshot of this droplet. Now I am trying to restore the droplet using digital ocean API and run the command to start the plumber API. The following steps need to be done to run the API:

  1. Restore the droplet
  2. LogIn as “rtest” with credentials
  3. Change directory to "/home/rtest/
  4. Execute command “Rscript api.R”

How can I accomplish this? Or I need to do something else?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello,

You could use the following request to generate your new Droplet:

curl -X POST -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer $TOKEN' -d \
    '{"name":"example.com","region":"nyc3","size":"512mb","image": 12345}' \
    "https://api.digitalocean.com/v2/droplets" 

You need to change the details so that they match your requirements, and also you need to change the image ID with your snapshot ID as well.

In case that you need to get your image ID, you can do it with this request:

  1. curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/images?page=1&per_page=1&private=true"

For more information, you can take a look at the official documentation here:

https://www.digitalocean.com/community/questions/how-to-create-a-droplet-using-snapshot-with-digitalocean-api

In case that you wanted to run some specific commands, you could also pass user data to your API request like this:

curl -X POST "https://api.digitalocean.com/v2/droplets" \
      -d'{"name":"metadata.example.com","region":"nyc3","size":"s-1vcpu-1gb","vpc_uuid":"c33931f2-a26a-4e61-b85c-4e95a2ec431b","image":"ubuntu-20-04-x64","user_data":
"#!/bin/bash

apt-get -y update
apt-get -y install nginx
export HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)
export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
echo Droplet: $HOSTNAME, IP Address: $PUBLIC_IPV4 > /usr/share/nginx/html/index.html",
      "ssh_keys":[ < SSH KEY IDs > ]}' \
      -H "Authorization: Bearer $TOKEN" \
      -H "Content-Type: application/json"

For more information on user data you can take a look at the following documentation:

https://www.digitalocean.com/docs/droplets/how-to/provide-user-data/

Hope that this helps! Regards, Bobby