# golang


05/02/2023, 9:13 AM
Hello! I want to run two commands in a remote server. The first checks if a service is active. I want to run the second only if the service is active, but I don’t know how to get the status from the first command.
Copy code
import (

func InstallRke2(ctx *pulumi.Context, connection *remote.ConnectionArgs) {

    res1, _ := remote.NewCommand(ctx, "is-rke2-server-active", &remote.CommandArgs{
        Connection: connection,
        Create:     pulumi.String("systemctl is-active rke2-server.service"),

    // How do I get the result of the `systemctl` command at this point?
    // Do I use `ApplyT` on `res1.Stdout`?

    // The command below should run only if the service is `active`
    res2, _ := remote.NewCommand(ctx, "get-registration-token", &remote.CommandArgs{
        Connection: connection,
        Create:     pulumi.String("cat /var/lib/rancher/rke2/server/node-token"),
        Triggers:   pulumi.All(res1.Create, res1.Stdin),
    }, pulumi.DependsOn([]pulumi.Resource{res1}))

I could get the status with
. But since it’s like a promise, should I use channels and waitgroups to get it out? I have a feeling this isn’t the way to go.
Copy code
result := res1.Stdout.ApplyT(func(status string) string {
        log.Println(status) // active
        return status

log.Println(result) // {0xc0002de070}
I’ve read the command package docs and looked through all the examples but couldn’t find a solution. How should I go about this?