App Service Linux の WebJobs はどこで実行されているのかのメモ

# はじめに

https://learn.microsoft.com/ja-jp/azure/app-service/webjobs-create?tabs=windowscode

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4914/47bb94b4-1cb1-d67b-6729-13080d4c8db1.png)

サイドカーについて色々調べていて、そういえば同時期？に利用できるようになった WebJobs はどうなん？と思ってやってみた。

参考

https://techcommunity.microsoft.com/blog/appsonazureblog/create-and-deploy-linux-webjobs-on-azure-app-service/4218587

---

そしたらこのエラー

```
[11/29/2024 08:35:05 > 56ce77: ERR ] An error occurred trying to start process 'node.exe' with working directory '/home/site/wwwroot/App_Data/jobs/continuous/myjob'. No such file or directory
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4914/2f12f94a-3cf7-dc3b-cf5a-cd12e74cec9b.png)

エラーそのものはなんかすごくしょうもない。。。

https://stackoverflow.com/questions/79020100/linux-azure-webjob-in-nodejs-referring-to-node-exe

が注目すべきはそのスタックトレース
```
[11/29/2024 08:35:05 > 56ce77: SYS INFO] Status changed to Running
[11/29/2024 08:35:05 > 56ce77: ERR ] An error occurred trying to start process 'node.exe' with working directory '/home/site/wwwroot/App_Data/jobs/continuous/myjob'. No such file or directory
[11/29/2024 08:35:05 > 56ce77: SYS ERR ] System.AggregateException: One or more errors occurred. (An error occurred trying to start process 'node.exe' with working directory '/home/site/wwwroot/App_Data/jobs/continuous/myjob'. No such file or directory)
 ---> System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'node.exe' with working directory '/home/site/wwwroot/App_Data/jobs/continuous/myjob'. No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Kudu.Core.Infrastructure.ProcessWrapper.Start() in C:\wagit\AAPT-Antares-Kudu\Kudu.Core\Infrastructure\ProcessWrapper.cs:line 27
   at Kudu.Core.Infrastructure.ProcessExtensions.Start(IProcess process, ITracer tracer, Stream output, Stream error, Stream input, IdleManager idleManager) in C:\wagit\AAPT-Antares-Kudu\Kudu.Core\Infrastructure\ProcessExtensions.cs:line 242
   at Kudu.Core.Infrastructure.Executable.ExecuteAsync(ITracer tracer, String arguments, Stream output, Stream error, Stream input, IdleManager idleManager) in C:\wagit\AAPT-Antares-Kudu\Kudu.Core\Infrastructure\Executable.cs:line 255
   --- End of inner exception stack trace ---
   at Kudu.Core.Infrastructure.Executable.ExecuteInternal(ITracer tracer, Func`2 onWriteOutput, Func`2 onWriteError, Encoding encoding, String arguments, Object[] args)
   at Kudu.Core.Infrastructure.Executable.ExecuteReturnExitCode(ITracer tracer, Action`1 onWriteOutput, Action`1 onWriteError, String arguments, Object[] args) in C:\wagit\AAPT-Antares-Kudu\Kudu.Core\Infrastructure\Executable.cs:line 165
   at Kudu.Core.Jobs.BaseJobRunner.RunJobInstance(JobBase job, IJobLogger logger, String runId, String trigger, ITracer tracer, Int32 port) in C:\wagit\AAPT-Antares-Kudu\Kudu.Core\Jobs\BaseJobRunner.cs:line 274
[11/29/2024 08:35:05 > 56ce77: SYS INFO] Process went down, waiting for 60 seconds
```

WebJobsは Kudu でやってるっぽい。サイドカーではないのかな。
[Antares](https://www.zdnet.com/article/codename-antares-a-new-microsoft-hosting-platform-for-web-apps/) って、でてますけど。。。

でいろいろ気になってみてみたメモ。
とりあえず、StackOverflowのとおりshellを挟んでnodeを実行するようにしてみた。

```sh
echo "Hello webjob"
echo "run which node"
echo `which node`
echo "run node -v"
echo `node -v`
```

でその結果が

```
[11/29/2024 12:27:21 > 56ce77: SYS INFO] Status changed to Starting
[11/29/2024 12:27:22 > 56ce77: SYS INFO] WebJob singleton setting is True
[11/29/2024 12:27:22 > 56ce77: SYS INFO] WebJob singleton lock is acquired
[11/29/2024 12:27:22 > 56ce77: SYS INFO] Run script 'hello.sh' with script host - 'BashScriptHost'
[11/29/2024 12:27:22 > 56ce77: SYS INFO] Status changed to Running
[11/29/2024 12:27:22 > 56ce77: INFO] Hello webjob
[11/29/2024 12:27:22 > 56ce77: INFO] run which node
[11/29/2024 12:27:22 > 56ce77: INFO] /usr/local/bin/node
[11/29/2024 12:27:22 > 56ce77: INFO] run node -v
[11/29/2024 12:27:22 > 56ce77: INFO] v20.15.1
[11/29/2024 12:27:22 > 56ce77: SYS INFO] Status changed to Success
[11/29/2024 12:27:22 > 56ce77: SYS INFO] Process went down, waiting for 60 seconds
```

一方 Kudu Bash では
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4914/e6aeacc9-aa0c-3d12-034e-a8f73ee3ed47.png)

`/usr/local/bin/node` のバージョンが違う。

もう少し詳しく見てみる。

```info.sh
#!/bin/sh
# this script log system info
cat /proc/self/cgroup
echo "whoami: $(whoami)"
echo "IP: $(ifconfig | grep inet | head -n 1 | awk '{print $2}')"
```

結果
```
[11/29/2024 12:48:24 > 56ce77: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[11/29/2024 12:48:24 > 56ce77: SYS INFO] Status changed to Starting
[11/29/2024 12:48:24 > 56ce77: SYS INFO] WebJob singleton setting is True
[11/29/2024 12:48:24 > 56ce77: SYS INFO] WebJob singleton lock is acquired
[11/29/2024 12:48:24 > 56ce77: SYS INFO] Run script 'info.sh' with script host - 'BashScriptHost'
[11/29/2024 12:48:24 > 56ce77: SYS INFO] Status changed to Running
[11/29/2024 12:48:25 > 56ce77: INFO] 12:cpuset:/
[11/29/2024 12:48:25 > 56ce77: INFO] 11:blkio:/system.slice/lwasv2.service
[11/29/2024 12:48:25 > 56ce77: INFO] 10:devices:/system.slice/lwasv2.service
[11/29/2024 12:48:25 > 56ce77: INFO] 9:cpu,cpuacct:/system.slice/lwasv2.service
[11/29/2024 12:48:25 > 56ce77: INFO] 8:memory:/system.slice/lwasv2.service
[11/29/2024 12:48:25 > 56ce77: INFO] 7:freezer:/
[11/29/2024 12:48:25 > 56ce77: INFO] 6:perf_event:/
[11/29/2024 12:48:25 > 56ce77: INFO] 5:net_cls,net_prio:/
[11/29/2024 12:48:25 > 56ce77: INFO] 4:hugetlb:/
[11/29/2024 12:48:25 > 56ce77: INFO] 3:pids:/system.slice/lwasv2.service
[11/29/2024 12:48:25 > 56ce77: INFO] 2:rdma:/
[11/29/2024 12:48:25 > 56ce77: INFO] 1:name=systemd:/system.slice/lwasv2.service
[11/29/2024 12:48:25 > 56ce77: INFO] whoami: root
[11/29/2024 12:48:25 > 56ce77: INFO] IP: 169.254.133.2
[11/29/2024 12:48:25 > 56ce77: SYS INFO] Status changed to Success
[11/29/2024 12:48:25 > 56ce77: SYS INFO] Process went down, waiting for 60 seconds
[11/29/2024 12:48:25 > 56ce77: SYS INFO] Status changed to PendingRestart
```

一方 Kudu Bash

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4914/88ef9ac3-96b5-4740-5c56-b254a3dbafa1.png)


うーんやっぱり Kudu とは別のコンテナで実行されているのかな？？？

もう少し情報追加
```
#!/bin/sh
# this script log system info
cat /proc/self/cgroup
echo "whoami: $(whoami)"
echo "IP: $(ifconfig | grep inet | head -n 1 | awk '{print $2}')"
ps aux
echo "sleeping for 1000000 seconds"
sleep 1000000
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4914/01a164aa-6a8d-dd7c-962d-36aa3893be64.png)

なんか見覚えあるプロセスがいる。これはもしやアプリコンテナではなかろうか。。。
ということで、アプリコンテナ側で見てみると発見。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4914/cba0e713-a285-a2a7-26ff-b032106fa987.png)

# 結論

何らかの仕組みを使ってアプリコンテナ内で実行されている。