blob: 3a204f66a4f13b25e4fff47c9bb0dd476357fb12 [file] [log] [blame]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
hello_loop = Process(
name = 'hello',
cmdline = """
while true; do
echo hello world
sleep 10
done
""")
# Write out a python program that self daemonizes via double forking.
# Asserts that thermos doesn't lose track of double forking proceses. On task
# tear down it should be given a SIGTERM so it can shut down cleanly.
write_program = Process(
name = "write_program",
cmdline = """
cat >./daemon.py <<EOL
import os
import signal
import sys
import time
def handler(signum, frame):
os.remove("{{term_file}}")
sys.exit(0)
def main():
pid = os.fork()
if pid > 0:
sys.exit(0)
os.setsid()
os.umask(0)
pid = os.fork()
if pid > 0:
sys.exit(0)
signal.signal(signal.SIGTERM, handler)
while True:
time.sleep(1)
if __name__ == '__main__':
main()
EOL
"""
)
run_daemon = Process(
name = 'run_daemon',
cmdline = 'python ./daemon.py'
)
task = Task(
processes = [hello_loop, write_program, run_daemon],
constraints = order(write_program, run_daemon),
resources = Resources(cpu=1, ram=1*MB, disk=100*MB)
)
jobs = [
Service(
cluster = 'devcluster',
environment = 'test',
role = 'vagrant',
name = 'daemonize',
task = task
)
]