Correct way to edit /etc/init.d entries

Groucho

New Member
Joined
Mar 7, 2019
Messages
7
Reaction score
4
Credits
49
Hello:

I'll try to make this as short as possible.

At some point in the lifetime of my installation, I edited an entry in /etc/init.d, in this specific case, /etc/init.d/halt.
As a result, I ended up with two entries:

Code:
/etc/init.d/halt
Code:
/etc/init.d/halt~

At that time, I left it at that, thinking that the newly generated entry (obviously a backup) would just stay there.
ie: oblivious as to what was going on within the system and not taken into account.

Code:
~$ ls -1 /etc/init.d
--- snip ---
halt
--- snip ---
halt~
--- snip ---
~$

While I have a look at my log files every fortnight or so to see if I catch anything strange, I don't do the same with running services unless it is warranted.
eg: something seems to be amiss or the CUPS / cups-browsed CVE thing.

So I had a look at and , to my surprise, found this:

Code:
~$ sudo service --status-all
--- snip ---
 [ - ]  halt~     <- this is the *backup* file being loaded.
--- snip ---
~$

Both files have the same attributes.
They have the same size because, for testing purposes, I have edited the original file to reflect the contents of the backup file.

Code:
~$ ls -l /etc/init.d/halt
-rwxr-xr-x 1 root root 1417 Sep 29 08:01 /etc/init.d/halt
~$
Code:
~$ ls -l /etc/init.d/halt~
-rwxr-xr-x 1 root root 1417 Sep 28 07:56 /etc/init.d/halt~
~$

Can anyone tell me why the backup file is being loaded instead of the edited file?
ie: /etc/init.d/halt~ instead of /etc/init.d/halt.

Where should I be looking?

Thanks in advance.

Best,

G.
 


Hello:

I'll try to make this as short as possible.

At some point in the lifetime of my installation, I edited an entry in /etc/init.d, in this specific case, /etc/init.d/halt.
As a result, I ended up with two entries:

Code:
/etc/init.d/halt
Code:
/etc/init.d/halt~

At that time, I left it at that, thinking that the newly generated entry (obviously a backup) would just stay there.
ie: oblivious as to what was going on within the system and not taken into account.

Code:
~$ ls -1 /etc/init.d
--- snip ---
halt
--- snip ---
halt~
--- snip ---
~$

While I have a look at my log files every fortnight or so to see if I catch anything strange, I don't do the same with running services unless it is warranted.
eg: something seems to be amiss or the CUPS / cups-browsed CVE thing.

So I had a look at and , to my surprise, found this:

Code:
~$ sudo service --status-all
--- snip ---
 [ - ]  halt~     <- this is the *backup* file being loaded.
--- snip ---
~$

Both files have the same attributes.
They have the same size because, for testing purposes, I have edited the original file to reflect the contents of the backup file.

Code:
~$ ls -l /etc/init.d/halt
-rwxr-xr-x 1 root root 1417 Sep 29 08:01 /etc/init.d/halt
~$
Code:
~$ ls -l /etc/init.d/halt~
-rwxr-xr-x 1 root root 1417 Sep 28 07:56 /etc/init.d/halt~
~$

Can anyone tell me why the backup file is being loaded instead of the edited file?
ie: /etc/init.d/halt~ instead of /etc/init.d/halt.

Where should I be looking?

Thanks in advance.

Best,

G.
The output indicates that file /etc/init.d/halt~ is older than the /etc/init.d/halt file.

What were the "testing purposes" when the files were changed? When the more recent file: halt, was overwritten by the back up file: halt~, the formerly more recent file was effectively lost. Once the change was effected, the file: halt~ became the more recent file, which is likely the reason the system has used it.
 
Last edited:
Hello:

... output indicates that file /etc/init.d/halt~ is older than the /etc/init.d/halt file.
I see ...
So the ~ is related to how the system behaves when a file in /etc/init.d is edited.
Not something (ie: a backup copy) added by the editor used (eg: jed, nano, mc)

What were the "testing purposes" ...
That was the last thing I did, when I realised there were two halt files.

Originally, I had changed something related to the shutdown process.
Cannot recall exactly what it did, it was a few years ago, before I was tidier when doing such things.
Basically it allowed me to shutdown my box without the intervention of an utterly annoying feature by the name of shutdown helper. 8^°

It works with a custom shutdown.sh script I put in /usr/bin/.

Code:
    log_action_msg "Will now halt"
#        read -p "Press enter to halt ($netdown $poweroff $hddown)" reply       # this is the edited line
        halt -d -f $netdown $poweroff $hddown
The testing would have been to delete `halt~`and see if the other halt file was loaded. ie: halt
As they were the same in every way, the expected outcome would have been that the system shut down as usual.

When the more recent file: halt, was overwritten by the back up file: halt~, the more recent file was effectively lost. Once the change was effected, the file: halt~ became the more recent file, which is likely the reason the system has used it.
Right.
Seems that it is all normal system behaviour then.

Thank you very much for your input.

Best,

G.
 
I think the ~ being added to the file name may be done by your editor. I have edited files in /etc/init.d and that didn't happen. I normally just use a text editor. If you update a package and doing so changes a file in that directory your changes may be lost. I don't normally need to edit any files in that directory unless I created them. I use tilde, an editor, and don't have that problem.

Signed,

Matthew Campbell
 
I think the ~ being added to the file name may be done by your editor. I have edited files in /etc/init.d and that didn't happen. I normally just use a text editor. If you update a package and doing so changes a file in that directory your changes may be lost. I don't normally need to edit any files in that directory unless I created them. I use tilde, an editor, and don't have that problem.

Signed,

Matthew Campbell
In debian, on this machine running trixie, the "~" which was used in past releases has been replaced by "-", and for system files, it's the system that creates them, e.g.

Code:
$ ls /etc | grep '.-$'
group-
gshadow-
passwd-
shadow-
subgid-
subuid-

There aren't any such files with a similar "-" here in /etc/init.d, so I can't say about that and I'm not recalling any such.
 
In debian, on this machine running trixie, the "~" which was used in past releases has been replaced by "-", and for system files, it's the system that creates them, e.g.

Code:
$ ls /etc | grep '.-$'
group-
gshadow-
passwd-
shadow-
subgid-
subuid-

There aren't any such files with a similar "-" here in /etc/init.d, so I can't say about that and I'm not recalling any such.
I was aware of the password files and such in /etc/ doing that, but not in /etc/init.d/.

Signed,

Matthew Campbell
 
Hello:

In debian, on this machine running trixie, the "~" ...

So it's not the editor, it is a system thing.
In Devuan Daedalus, the `~ `is still used.

That said, through trial and error I have found this:

Using jed*
1.
If I edit /etc/init.d/halt by just adding # somewhere and save the file, no other file is created nor is the contents of /etc/init.d/halt~ affected.

2.
The same action on /etc/init.d/halt~ will modify it and also create a new file (ie: halt~~).
/etc/init.d/halt~~ is a copy of the original file. ie: /etc/init.d/halt~, which I can then delete.

* a cross-platform cmd line editor, unsuspected of adding anything unnecessary. 8^°

Now, here's the thing® ...
If I reboot without deleting /etc/init.d/halt~~ ...
Yes, both /etc/init.d/halt~ and /etc/init.d/halt~~ get loaded:

Code:
~$ sudo service --status-all | grep halt
--- snip ---
 [ - ]  halt~
 [ - ]  halt~~
--- snip ---
~$

That being so, at this point the question to ask would be:

Why are both halt* files loaded by the system?
If I delete halt~~ and reboot, why does the system load only halt~?

Code:
~$ sudo service --status-all | grep halt
--- snip ---
 [ - ]  halt~
--- snip ---
~$
I have the feeling that there is something missing here, no idea what.
ie: whatever it is that tells the system to only load halt~ and skip halt.

Something that has not been done in the experiment above (prior to rebooting the box).
The lack of which is making the system load both /etc/init.d/halt~ and /etc/init.d/halt~~

Comments welcome.

Thanks in advance.

Best,

G.
 
Comments welcome.

Thanks in advance.

Best,

G.
I can't really say anything more usefully than already said. Unfortunately, I don't have a purely sysVinit system here to experiment with. The debian and debian based systems here, though including many sysVinit scripts in /etc/init.d, has them run by systemd. When altering one to try and reproduce the behaviour described in post #1 and #7, that behaviour didn't happen here. It was tried with scripts other that "halt" because that one doesn't exist in these systems. That may suggest that the behaviour is associated more specifically with the particular sysVinit system in devuan, but that's a guess. When altering files here, the vim editor was used, but no backups with altered filenames were created on saving the files nor on starting the scripts. Sorry that I can't get to the bottom of it.
 

Members online


Top