Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29253

Linux init.d service does not see environment variables

$
0
0

I am using an RPM package with Spring Boot java application. Netflix Gradle nebula.ospackage plugin is used to build up an rpm package.

task packRpm(type: Rpm) {
    description = 'Creates .rpm package.'
    os = LINUX
    arch = X86_64
    type = BINARY
    version = version
    release = 1

    into '/opt/myapp'

    from(jar.outputs.files) {
        into 'lib'
        fileMode 0500
    }

    from('${buildDir}/resources/main/myapp.conf') {
        into 'conf'
        fileMode 0400
        user 'root'
        permissionGroup 'root'
    }

    // symlinks jar to init.d
    link('/etc/init.d/myapp', '/opt/myapp/lib/' + jar.archiveName) // DO NOT CHANGE jar.archiveName
    link('/opt/myapp/lib/myapp-' + project.version + '.conf', '/opt/myapp/conf/myapp.conf')
    postInstall 'sudo chkconfig myapp on; sudo service myapp start'
    preUninstall 'sudo myapp stop'
}

then I install it on my Linux machine on AWS EC2 (AMI Amazon Linux 2):

sudo yum install myapp.rpm -y

then I configured system environment variables on my ec2 machine /etc/default/myapp

CLOUD_STACK="staging"
EC2_REGION="us-east-1"

then I try to read those environment variables in my Spring Boot app:

String cloudStack = System.getEnv("CLOUD_STACK"); - returns null instead of staging It seems like environment variables are not accessible from init.d service. Similar issue - How can I set environment variables in my Linux service for Asterisk even though it doesn't have a real user?

Would really appreciate your help


Viewing all articles
Browse latest Browse all 29253

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>