Portable Init Script? - portability

How to write a portable init Script which works with
upstart (Ubuntu)
systemd
optional init.d
Other platforms (Windows, Android, OS-X) are not important in my context.

Both systemd and upstart support sysinit style scripts. RHEL 6 uses upstart but most scripts are normal init.d bash scripts. RHEL 7 and Fedora 19 (and earlier) use systemd, but they happily run old init scripts.
You can use normal old style daemon that forks with init script. If the application does not fork on its own you can use something like supervisord to do the forking for you and directly integrate with separate systemd script. I do not know details about upstart except it uses it's own format, but supporting it (if you do not have to support old/current linux systems) seems reasonable only for non-linux distributions. systemd is currently Linux specific, though I've seen work being done to port it to BSD.
You may be interested in how they integrated CUPS. Last time I checked the systemd "script" starts the daemon with -f option (foreground) - ExecStart=/usr/sbin/cupsd -f. The init.d script does not add that flag.
In short - for now use old style System V init.d script if you want one solution that works everywhere. Add systemd support if you have some spare resources and if you have enough, you can certainly support the three systems separately (greatest benefit for the users, but a lot of work).
I'd personally create init.d + systemd scripts and would not care about upstart. Chances are systemd will soon replace upstart (also look here) and init.d scripts will remain usable on the rest of the UNIX-es.

As far as I know systemd allows to run init.d scripts, so you can do a script that is portable with upstart and init.d.
The other thing is that all of them (systemd, init.d, upstart) uses its own syntax. The only solution I see is to create three different scripts that call some application of the most common service interface - a forking service application. That way all of the managers will know how to handle your service. And provide your application with all three kinds of scripts. Then, installer will have to choose what script is to be installed with your service application.

Related

Running wsl results in starting a Jupyter Notebook

I have installed Anaconda under Windows and Ubuntu under WSL. I have not used this Ubuntu installation for a long time. When I tried to run Ubuntu now, I saw the following:
That is, WSL starts a Jupyter Notebook server, which I have to kill by hitting Ctrl-C to get the Ubuntu prompt. What could be causing this behavior?
There are several ways for something to "autostart" when running WSL:
First, you (or an application) may have modified your startup scripts to start the Jupyter Notebook server. To see if this is the case, try starting WSL from PowerShell by running:
wsl -e bash --noprofile --norc
This will run bash without the startup scripts. If this brings you to the prompt without running the notebook sesrver, then the problem is in your ~/.bashrc or ~/.bash_profile (assuming bash is your default shell).
Given the symptoms you are seeing, this is the most likely cause. If that's the case, look in those files to see if you can find the line that is starting the server, and comment it out.
Second, and related to the first, do you recall trying to enable Systemd at any point using something like Genie or WSL2Hacks? If so, then I believe they modify your start scripts to run Systemd, which can be used to start other services. However, I would expect those Systemd-executed services to start daemonized, in the background, and not interrupt your shell's startup.
Under Windows 11, services can also be autostarted via /etc/wsl.conf, but again, they would be started by the root user in this case, and in the background. I can't think of a non-pathological way that this could be used to interrupt the user's startup shell experience.

What is the easiest way to run bash dependent dockerfiles on windows?

I need to setup docker on my windows 10 OS. I've previously been a linux guy where everything just works so this is a pain for me. It works as expected but within the dockerfile there are calls that uses /bin/bash which makes the build fail.
I've tried to setup a VM with hyper-v but then i stopped because i figured there must be an easier way. I found the bash.exe in windows. i can't run as sudo but i guess that doesn't matter here as long as i run bash as administrator. wget works here but the docker program cant be found when i run docker --version.
Is the easiest way to run bash scripts on win10 with the bash.exe? And why can't docker run in the bash terminal (there is no .bashrc)?
I would use Linux on the Windows box. The two systems can access each other's file systems (\\wsl$, /mnt/c). I use Ubuntu, and it's as if I was using a "normal" Ubuntu box in all aspects, so far. I'd be surprised if your process didn't work here.
Alternatively, there's Cygwin. When running Cygwin, you're kinda in a VM, kinda not. It's a bit blurry. As such, it's not as robust as WSL. But it might do the trick, and it's a lot less "heavy" than installing a full Linux distro.

Specifying JupyterHub Path Variable

I am in the process of installing jupyterhub. I successfully install jupyterhub using:
python3 -m pip install jupyterhub
npm install -g configurable-http-proxy
However, when I run jupyterhub -h in the Windows command prompt it gives:
"jupyterhub" is not recognized as an internal or external command, operable
program or batch file.
I added C:\Users\User\AppData\Local\Continuum\Anaconda3\Lib\site-packages\jupyterhub\ to my user environment variable, however still receive the message. What path should I be using?
Please note that according to this, Jupyterhub is not officially supported for Windows yet.
That aside, you could dockerize it to make your life easier. For this error, please check if you can see the executable in C:\Program Files\Continuum Analytics\Anaconda3\scripts. The lib directory you're specifying contains python source files and not the executables.
I had this same issue, and I saw this occurred because jupyterhub is a python script rather than an executable. So to run this on Windows I needed to execute it like python C:\Program Files\Continuum Analytics\Anaconda3\scripts\jupyterhub.
However, I still was unable to run jupyterhub on Windows because it depends on the pwd module, which is a Unix/Linux only module.
As others have said, Windows is not a supported platform. JupyterHub is best used on Linux-like platforms where you have Docker or something similar to conatainerize each user's session.
A good alternative is to install Oracle VirtualBox and run a local VM. I run a 64-bit Ubuntu and it's quite good performance. It makes things much easier to run JupyterHub on. Asides depending on pwd, there are also assumptions around user-creation and other activities that Windows isn't going to handle well.
In short, if you want to run on native Windows, you're going to become the first JupyterHub Windows contributor. I looked at doing it but it looked like too much effort.
The upside of running a VM is that behaviour in the VM is going to more closely resemble what you have running on the server anyway. If you don't plan running on a server, then just "jupyter notebook", as this is all JupyterHub ends up running...

How to install and run midnight commander on Busybox?

I'm just downloaded busybox image for docker. And it's a bit confusing how to install packages with busybox.
For example, how to install and run midnight commander on busybox?
You seem to confuse busybox as "an OS (or at least a whole userland)".
This is not the case. What Busybox is:
BusyBox combines tiny versions of many common UNIX utilities into a
single small executable. It provides replacements for most of the
utilities you usually find in GNU fileutils, shellutils, etc.
Source:
https://www.busybox.net/about.html
The whole utilities/command that Busybox can provide are documented in its "Command help" section, here:
https://www.busybox.net/downloads/BusyBox.html
And nothing more.
(It can then be configured and build to provide less than that, since its targeted to FLASH/memory constrained embedded environment and you may want to make busybox smaller).
Notice, in its command help, how it provides close to nothing[0] to manage the installation of other, non-busybox things such as midnight commander. Which does not imply that you cannot install and run midnight commander in a busybox-based user environment, only that its none of busybox business.
I don't know what's your purpose running a busybox docker image, but you may want to read busybox documentation first.
[0]:
As it is busybox can provide a dpkg command, to "Install, remove and manage Debian packages". I never used that though.

Is there a good EC2 image for a microinstance that includes just ruby but not rails,mysql, etc

I just want to spool up some micro-instances and install a few gems.
I recommend you just start an instance of a clean base AMI running the Linux distro of your preference from a trusted source. Then run the standard commands (e.g., apt-get, yum) to install the standard Ruby provided by the distro and go from there.
You don't need to find an AMI that has exactly the set of packages you want to run. Modern Linux makes it easy to install these cleanly.
With AMIs like the official Ubuntu or Amazon Linux you can even pass in a script as user-data and it will run it on first boot. You can use this to make sure that your desired packages and gems are installed when the instance runs.

Resources